parameters: (url, archiveFilePath, outputDir, \
                                expectedNumberOfExtractedFiles=None, numberOfTrials=3, checksum=None)
return_statement: return False
docstring: Downloads an archive from ``url`` as ``archiveFilePath``, and extracts it to ``outputDir``.
  
    This combined function tests the success of the download by the extraction step,
    and re-downloads if extraction failed.
  
    If specified, the ``checksum`` is used to verify that the downloaded file is the expected one.
    It must be specified as ``<algo>:<digest>``. For example, ``SHA256:cc211f0dfd9a05ca3841ce1141b292898b2dd2d3f08286affadf823a7e58df93``.
docstring_summary: Downloads an archive from ``url`` as ``archiveFilePath``, and extracts it to ``outputDir``.
docstring_tokens: Downloads an archive from url as archiveFilePath and extracts it to outputDir .
function: def downloadAndExtractArchive(url, archiveFilePath, outputDir, \
                                expectedNumberOfExtractedFiles=None, numberOfTrials=3, checksum=None):
    """ Downloads an archive from ``url`` as ``archiveFilePath``, and extracts it to ``outputDir``.
  
    This combined function tests the success of the download by the extraction step,
    and re-downloads if extraction failed.
  
    If specified, the ``checksum`` is used to verify that the downloaded file is the expected one.
    It must be specified as ``<algo>:<digest>``. For example, ``SHA256:cc211f0dfd9a05ca3841ce1141b292898b2dd2d3f08286affadf823a7e58df93``.
    """
    import os
    import shutil
    import logging
  
    maxNumberOfTrials = numberOfTrials
  
    def _cleanup():
      # If there was a failure, delete downloaded file and empty output folder
      logging.warning('Download and extract failed, removing archive and destination folder and retrying. Attempt #%d...' % (maxNumberOfTrials - numberOfTrials))
      os.remove(archiveFilePath)
      shutil.rmtree(outputDir)
      os.mkdir(outputDir)
  
    while numberOfTrials:
      if not downloadFile(url, archiveFilePath, checksum):
        numberOfTrials -= 1
        _cleanup()
        continue
      if not extractArchive(archiveFilePath, outputDir, expectedNumberOfExtractedFiles):
        numberOfTrials -= 1
        _cleanup()
        continue
      return True
  
    _cleanup()
    return False
function_tokens: def downloadAndExtractArchive ( url , archiveFilePath , outputDir , expectedNumberOfExtractedFiles = None , numberOfTrials = 3 , checksum = None ) : import os import shutil import logging maxNumberOfTrials = numberOfTrials def _cleanup ( ) : # If there was a failure, delete downloaded file and empty output folder logging . warning ( 'Download and extract failed, removing archive and destination folder and retrying. Attempt #%d...' % ( maxNumberOfTrials - numberOfTrials ) ) os . remove ( archiveFilePath ) shutil . rmtree ( outputDir ) os . mkdir ( outputDir ) while numberOfTrials : if not downloadFile ( url , archiveFilePath , checksum ) : numberOfTrials -= 1 _cleanup ( ) continue if not extractArchive ( archiveFilePath , outputDir , expectedNumberOfExtractedFiles ) : numberOfTrials -= 1 _cleanup ( ) continue return True _cleanup ( ) return False