tools/bisect_repackage/bisect_repackage_utils.py
def ExtractZip(filename, output_dir, extract_file_list=[], verbose=True):
  """Extract the zip archive in the output directory."""
  MaybeMakeDirectory(output_dir)

  # On Linux and Mac, we use the unzip command as it will
  # handle links and file bits (executable), which is much
  # easier then trying to do that with ZipInfo options.
  #
  # The Mac Version of unzip unfortunately does not support Zip64, whereas
  # the python module does, so we have to fallback to the python zip module
  # on Mac if the filesize is greater than 4GB.
  #
  # On Windows, try to use 7z if it is installed, otherwise fall back to python
  # zip module and pray we don't have files larger than 512MB to unzip.
  unzip_cmd = None
  if ((IsMac() and os.path.getsize(filename) < 4 * 1024 * 1024 * 1024)
      or IsLinux()):
    unzip_cmd = ['unzip', '-o']
  elif IsWindows() and os.path.exists('C:\\Program Files\\7-Zip\\7z.exe'):
    unzip_cmd = ['C:\\Program Files\\7-Zip\\7z.exe', 'x', '-y']

  if unzip_cmd:
    # Make sure path is absolute before changing directories.
    filepath = os.path.abspath(filename)
    saved_dir = os.getcwd()
    os.chdir(output_dir)
    command = unzip_cmd + [filepath]
    command.extend(extract_file_list)
    result = RunCommand(command)
    os.chdir(saved_dir)
    if result:
      raise ExternalError('unzip failed: %s => %s' % (str(command), result))
  else:
    assert IsWindows() or IsMac()
    zf = zipfile.ZipFile(filename)
    # TODO(hinoka): This can be multiprocessed.
    for name in zf.namelist():
      if verbose:
        print('Extracting %s' % name)
      zf.extract(name, output_dir)
      if IsMac():
        # Restore permission bits.
        os.chmod(os.path.join(output_dir, name),
                 zf.getinfo(name).external_attr >> 16L)
Extract the zip archive in the output directory.
Extract the zip archive in the output directory.
Extract the zip archive in the output directory .
def ExtractZip(filename, output_dir, extract_file_list=[], verbose=True):
  MaybeMakeDirectory(output_dir)
   The Mac Version of unzip unfortunately does not support Zip64, whereas
   the python module does, so we have to fallback to the python zip module
   on Mac if the filesize is greater than 4GB.
   On Windows, try to use 7z if it is installed, otherwise fall back to python
   zip module and pray we don't have files larger than 512MB to unzip.
  unzip_cmd = None
  if ((IsMac() and os.path.getsize(filename) < 4 * 1024 * 1024 * 1024)
      or IsLinux()):
    unzip_cmd = ['unzip', '-o']
  elif IsWindows() and os.path.exists('C:\\Program Files\\7-Zip\\7z.exe'):
    unzip_cmd = ['C:\\Program Files\\7-Zip\\7z.exe', 'x', '-y']
  if unzip_cmd:
     Make sure path is absolute before changing directories.
    filepath = os.path.abspath(filename)
    saved_dir = os.getcwd()
    os.chdir(output_dir)
    command = unzip_cmd + [filepath]
    command.extend(extract_file_list)
    result = RunCommand(command)
    os.chdir(saved_dir)
    if result:
      raise ExternalError('unzip failed: %s => %s' % (str(command), result))
  else:
    assert IsWindows() or IsMac()
    zf = zipfile.ZipFile(filename)
     TODO(hinoka): This can be multiprocessed.
    for name in zf.namelist():
      if verbose:
        print('Extracting %s' % name)
      zf.extract(name, output_dir)
      if IsMac():
         Restore permission bits.
        os.chmod(os.path.join(output_dir, name),
                 zf.getinfo(name).external_attr >> 16L)
def ExtractZip ( filename , output_dir , extract_file_list = [ ] , verbose = True ) : MaybeMakeDirectory ( output_dir ) unzip_cmd = None if ( ( IsMac ( ) and os . path . getsize ( filename ) < 4 * 1024 * 1024 * 1024 ) or IsLinux ( ) ) : unzip_cmd = [ 'unzip' , '-o' ] elif IsWindows ( ) and os . path . exists ( 'C:\\Program Files\\7-Zip\\7z.exe' ) : unzip_cmd = [ 'C:\\Program Files\\7-Zip\\7z.exe' , 'x' , '-y' ] if unzip_cmd : filepath = os . path . abspath ( filename ) saved_dir = os . getcwd ( ) os . chdir ( output_dir ) command = unzip_cmd + [ filepath ] command . extend ( extract_file_list ) result = RunCommand ( command ) os . chdir ( saved_dir ) if result : raise ExternalError ( 'unzip failed: %s => %s' % ( str ( command ) , result ) ) else : assert IsWindows ( ) or IsMac ( ) zf = zipfile . ZipFile ( filename ) for name in zf . namelist ( ) : if verbose : print ( 'Extracting %s' % name ) zf . extract ( name , output_dir ) if IsMac ( ) : os . chmod ( os . path . join ( output_dir , name ) , zf . getinfo ( name ) . external_attr >> 16L )
Extract the zip archive in the output directory.
Extract the zip archive in the output directory .
"""Extract the zip archive in the output directory.""" # On Linux and Mac, we use the unzip command as it will # handle links and file bits (executable), which is much # easier then trying to do that with ZipInfo options. # # The Mac Version of unzip unfortunately does not support Zip64, whereas # the python module does, so we have to fallback to the python zip module # on Mac if the filesize is greater than 4GB. # # On Windows, try to use 7z if it is installed, otherwise fall back to python # zip module and pray we don't have files larger than 512MB to unzip. # Make sure path is absolute before changing directories. # TODO(hinoka): This can be multiprocessed. # Restore permission bits.
filename
output_dir
extract_file_list
verbose