parameters: (self,source,attemptCount=0)
docstring: Given an instance of SampleDataSource, downloads the associated data and
      load them into Slicer if it applies.
  
      The function always returns a list.
  
      Based on the fileType(s), nodeName(s) and loadFile(s) associated with
      the source, different values may be appended to the returned list:
  
        - if nodeName is specified, appends loaded nodes but if ``loadFile`` is False appends downloaded filepath
        - if fileType is ``SceneFile``, appends downloaded filepath
        - if fileType is ``ZipFile``, appends directory of extracted archive but if ``loadFile`` is False appends downloaded filepath
  
      If no ``nodeNames`` and no ``fileTypes`` are specified or if ``loadFiles`` are all False,
      returns the list of all downloaded filepaths.
docstring_summary: Given an instance of SampleDataSource, downloads the associated data and
      load them into Slicer if it applies.
docstring_tokens: Given an instance of SampleDataSource downloads the associated data and load them into Slicer if it applies .
function: def downloadFromSource(self,source,attemptCount=0):
      """Given an instance of SampleDataSource, downloads the associated data and
      load them into Slicer if it applies.
  
      The function always returns a list.
  
      Based on the fileType(s), nodeName(s) and loadFile(s) associated with
      the source, different values may be appended to the returned list:
  
        - if nodeName is specified, appends loaded nodes but if ``loadFile`` is False appends downloaded filepath
        - if fileType is ``SceneFile``, appends downloaded filepath
        - if fileType is ``ZipFile``, appends directory of extracted archive but if ``loadFile`` is False appends downloaded filepath
  
      If no ``nodeNames`` and no ``fileTypes`` are specified or if ``loadFiles`` are all False,
      returns the list of all downloaded filepaths.
      """
      nodes = []
      filePaths = []
  
      for uri,fileName,nodeName,checksum,loadFile,loadFileType in zip(source.uris,source.fileNames,source.nodeNames,source.checksums,source.loadFiles,source.loadFileType):
  
        current_source = SampleDataSource(uris=uri, fileNames=fileName, nodeNames=nodeName, checksums=checksum, loadFiles=loadFile, loadFileType=loadFileType, loadFileProperties=source.loadFileProperties)
        try:
          filePath = self.downloadFileIntoCache(uri, fileName, checksum)
        except ValueError:
          if attemptCount < 5:
            attemptCount += 1
            self.logMessage('<b>Load failed! Trying to download again (%d of 5 attempts)...</b>' % (attemptCount), logging.ERROR)
            filePath = self.downloadFileIntoCache(uri, fileName, checksum)
  
        filePaths.append(filePath)
  
        if loadFileType == 'ZipFile':
          if loadFile == False:
            nodes.append(filePath)
            continue
          outputDir = slicer.mrmlScene.GetCacheManager().GetRemoteCacheDirectory() + "/" + os.path.splitext(os.path.basename(filePath))[0]
          qt.QDir().mkpath(outputDir)
          success = slicer.util.extractArchive(filePath, outputDir)
          if not success and attemptCount < 5:
            file = qt.QFile(filePath)
            if not file.remove():
              self.logMessage('<b>Load failed! Unable to delete and try again loading %s!</b>' % filePath, logging.ERROR)
              nodes.append(None)
              break
            attemptCount += 1
            self.logMessage('<b>Load failed! Trying to download again (%d of 5 attempts)...</b>' % (attemptCount), logging.ERROR)
            outputDir = self.downloadFromSource(current_source,attemptCount)[0]
          nodes.append(outputDir)
  
        elif loadFileType == 'SceneFile':
          if not loadFile:
            nodes.append(filePath)
            continue
          success = self.loadScene(filePath, source.loadFileProperties.copy())
          if not success and attemptCount < 5:
            file = qt.QFile(filePath)
            if not file.remove():
              self.logMessage('<b>Load failed! Unable to delete and try again loading %s!</b>' % filePath, logging.ERROR)
              nodes.append(None)
              break
            attemptCount += 1
            self.logMessage('<b>Load failed! Trying to download again (%d of 5 attempts)...</b>' % (attemptCount), logging.ERROR)
            filePath = self.downloadFromSource(current_source,attemptCount)[0]
          nodes.append(filePath)
  
        elif nodeName:
          if loadFile == False:
            nodes.append(filePath)
            continue
          loadedNode = self.loadNode(filePath, nodeName, loadFileType, source.loadFileProperties.copy())
          if loadedNode is None and attemptCount < 5:
            file = qt.QFile(filePath)
            if not file.remove():
              self.logMessage('<b>Load failed! Unable to delete and try again loading %s!</b>' % filePath, logging.ERROR)
              nodes.append(None)
              break
            attemptCount += 1
            self.logMessage('<b>Load failed! Trying to download again (%d of 5 attempts)...</b>' % (attemptCount), logging.ERROR)
            loadedNode = self.downloadFromSource(current_source,attemptCount)[0]
          nodes.append(loadedNode)
  
      if nodes:
        return nodes
      else:
        return filePaths
function_tokens: def downloadFromSource ( self , source , attemptCount = 0 ) : nodes = [ ] filePaths = [ ] for uri , fileName , nodeName , checksum , loadFile , loadFileType in zip ( source . uris , source . fileNames , source . nodeNames , source . checksums , source . loadFiles , source . loadFileType ) : current_source = SampleDataSource ( uris = uri , fileNames = fileName , nodeNames = nodeName , checksums = checksum , loadFiles = loadFile , loadFileType = loadFileType , loadFileProperties = source . loadFileProperties ) try : filePath = self . downloadFileIntoCache ( uri , fileName , checksum ) except ValueError : if attemptCount < 5 : attemptCount += 1 self . logMessage ( '<b>Load failed! Trying to download again (%d of 5 attempts)...</b>' % ( attemptCount ) , logging . ERROR ) filePath = self . downloadFileIntoCache ( uri , fileName , checksum ) filePaths . append ( filePath ) if loadFileType == 'ZipFile' : if loadFile == False : nodes . append ( filePath ) continue outputDir = slicer . mrmlScene . GetCacheManager ( ) . GetRemoteCacheDirectory ( ) + "/" + os . path . splitext ( os . path . basename ( filePath ) ) [ 0 ] qt . QDir ( ) . mkpath ( outputDir ) success = slicer . util . extractArchive ( filePath , outputDir ) if not success and attemptCount < 5 : file = qt . QFile ( filePath ) if not file . remove ( ) : self . logMessage ( '<b>Load failed! Unable to delete and try again loading %s!</b>' % filePath , logging . ERROR ) nodes . append ( None ) break attemptCount += 1 self . logMessage ( '<b>Load failed! Trying to download again (%d of 5 attempts)...</b>' % ( attemptCount ) , logging . ERROR ) outputDir = self . downloadFromSource ( current_source , attemptCount ) [ 0 ] nodes . append ( outputDir ) elif loadFileType == 'SceneFile' : if not loadFile : nodes . append ( filePath ) continue success = self . loadScene ( filePath , source . loadFileProperties . copy ( ) ) if not success and attemptCount < 5 : file = qt . QFile ( filePath ) if not file . remove ( ) : self . logMessage ( '<b>Load failed! Unable to delete and try again loading %s!</b>' % filePath , logging . ERROR ) nodes . append ( None ) break attemptCount += 1 self . logMessage ( '<b>Load failed! Trying to download again (%d of 5 attempts)...</b>' % ( attemptCount ) , logging . ERROR ) filePath = self . downloadFromSource ( current_source , attemptCount ) [ 0 ] nodes . append ( filePath ) elif nodeName : if loadFile == False : nodes . append ( filePath ) continue loadedNode = self . loadNode ( filePath , nodeName , loadFileType , source . loadFileProperties . copy ( ) ) if loadedNode is None and attemptCount < 5 : file = qt . QFile ( filePath ) if not file . remove ( ) : self . logMessage ( '<b>Load failed! Unable to delete and try again loading %s!</b>' % filePath , logging . ERROR ) nodes . append ( None ) break attemptCount += 1 self . logMessage ( '<b>Load failed! Trying to download again (%d of 5 attempts)...</b>' % ( attemptCount ) , logging . ERROR ) loadedNode = self . downloadFromSource ( current_source , attemptCount ) [ 0 ] nodes . append ( loadedNode ) if nodes : return nodes else : return filePaths