def unpack(src_path, tempdir): if src_path.endswith(('.tar.gz', '.tar.bz2', '.tgz', '.tar.xz', '.tar')): tar_xf(src_path, tempdir) elif src_path.endswith('.zip'): unzip(src_path, tempdir) else: raise Exception("not a valid source")
def unpack(source_dict, src_dir, cache_folder, recipe_path, croot, verbose=False, timeout=90, locking=True): ''' Uncompress a downloaded source. ''' src_path, unhashed_fn = download_to_cache(cache_folder, recipe_path, source_dict) if not isdir(src_dir): os.makedirs(src_dir) if verbose: print("Extracting download") with TemporaryDirectory(dir=croot) as tmpdir: unhashed_dest = os.path.join(tmpdir, unhashed_fn) if src_path.lower().endswith(('.tar.gz', '.tar.bz2', '.tgz', '.tar.xz', '.tar', 'tar.z')): tar_xf(src_path, tmpdir) elif src_path.lower().endswith('.zip'): unzip(src_path, tmpdir) elif src_path.lower().endswith('.whl'): # copy wheel itself *and* unpack it # This allows test_files or about.license_file to locate files in the wheel, # as well as `pip install name-version.whl` as install command unzip(src_path, tmpdir) copy_into(src_path, unhashed_dest, timeout, locking=locking) else: # In this case, the build script will need to deal with unpacking the source print("Warning: Unrecognized source format. Source file will be copied to the SRC_DIR") copy_into(src_path, unhashed_dest, timeout, locking=locking) flist = os.listdir(tmpdir) folder = os.path.join(tmpdir, flist[0]) if len(flist) == 1 and os.path.isdir(folder): hoist_single_extracted_folder(folder) flist = os.listdir(tmpdir) for f in flist: shutil.move(os.path.join(tmpdir, f), os.path.join(src_dir, f))
def unpack(meta, config): ''' Uncompress a downloaded source. ''' src_path = download_to_cache(meta, config) if not isdir(config.work_dir): os.makedirs(config.work_dir) if config.verbose: print("Extracting download") if src_path.lower().endswith( ('.tar.gz', '.tar.bz2', '.tgz', '.tar.xz', '.tar', 'tar.z')): tar_xf(src_path, config.work_dir) elif src_path.lower().endswith('.zip'): unzip(src_path, config.work_dir) elif src_path.lower().endswith('.whl'): # copy wheel itself *and* unpack it # This allows test_files or about.license_file to locate files in the wheel, # as well as `pip install name-version.whl` as install command unzip(src_path, config.work_dir) copy_into(src_path, config.work_dir, config.timeout, locking=config.locking) else: # In this case, the build script will need to deal with unpacking the source print( "Warning: Unrecognized source format. Source file will be copied to the SRC_DIR" ) copy_into(src_path, config.work_dir, config.timeout, locking=config.locking)
def unpack(src_path, tempdir): if src_path.endswith(('.tar.gz', '.tar.bz2', '.tgz', '.tar.xz', '.tar')): tar_xf(src_path, tempdir) elif src_path.endswith('.zip'): unzip(src_path, tempdir) else: raise Exception("not a valid source: %s" % src_path)
def unpack(src_path, tempdir): if src_path.endswith((".tar.gz", ".tar.bz2", ".tgz", ".tar.xz", ".tar")): tar_xf(src_path, tempdir) elif src_path.endswith(".zip"): unzip(src_path, tempdir) else: raise Exception("not a valid source")
def unpack(meta): src_path = download_to_cache(meta) os.makedirs(WORK_DIR) if src_path.endswith(('.tar.gz', '.tar.bz2', '.tgz', '.tar.xz', '.tar')): tar_xf(src_path, WORK_DIR) elif src_path.endswith('.zip'): unzip(src_path, WORK_DIR) else: # In this case, the build script will need to deal with unpacking the source print("Warning: Unrecognized source format. Source file will be copied to the SRC_DIR") copy2(src_path, WORK_DIR)
def test_unzip(testing_workdir): with open('file_with_execute_permission', 'w') as f: f.write("test") file_path = os.path.join(testing_workdir, 'file_with_execute_permission') current_permissions = os.stat(file_path).st_mode os.chmod(file_path, current_permissions | stat.S_IXUSR) with zipfile.ZipFile('test.zip', 'w') as z: z.write('file_with_execute_permission') utils.unzip('test.zip', 'unpack') unpacked_path = os.path.join('unpack', 'file_with_execute_permission') assert os.path.isfile(unpacked_path) st_mode = os.stat(unpacked_path).st_mode assert st_mode & stat.S_IXUSR
def unpack(meta): """ Uncompress a downloaded source. """ src_path = download_to_cache(meta) os.makedirs(WORK_DIR) if src_path.lower().endswith((".tar.gz", ".tar.bz2", ".tgz", ".tar.xz", ".tar")): tar_xf(src_path, WORK_DIR) elif src_path.lower().endswith(".zip"): unzip(src_path, WORK_DIR) else: # In this case, the build script will need to deal with unpacking the source print("Warning: Unrecognized source format. Source file will be copied to the SRC_DIR") copy2(src_path, WORK_DIR)
def unpack(meta): ''' Uncompress a downloaded source. ''' src_path = download_to_cache(meta) os.makedirs(WORK_DIR) if src_path.lower().endswith(('.tar.gz', '.tar.bz2', '.tgz', '.tar.xz', '.tar')): tar_xf(src_path, WORK_DIR) elif src_path.lower().endswith('.zip'): unzip(src_path, WORK_DIR) else: # In this case, the build script will need to deal with unpacking the source print("Warning: Unrecognized source format. Source file will be copied to the SRC_DIR") copy2(src_path, WORK_DIR)
def unpack(meta, verbose=False): ''' Uncompress a downloaded source. ''' src_path = download_to_cache(meta) os.makedirs(WORK_DIR) if verbose: print("Extracting download") if src_path.lower().endswith(('.tar.gz', '.tar.bz2', '.tgz', '.tar.xz', '.tar', 'tar.z')): tar_xf(src_path, WORK_DIR) elif src_path.lower().endswith('.zip'): unzip(src_path, WORK_DIR) else: # In this case, the build script will need to deal with unpacking the source print("Warning: Unrecognized source format. Source file will be copied to the SRC_DIR") copy2(src_path, WORK_DIR)
def unpack(meta, config): """ Uncompress a downloaded source. """ src_path = download_to_cache(meta, config) if not isdir(config.work_dir): os.makedirs(config.work_dir) if config.verbose: print("Extracting download") if src_path.lower().endswith((".tar.gz", ".tar.bz2", ".tgz", ".tar.xz", ".tar", "tar.z")): tar_xf(src_path, get_dir(config)) elif src_path.lower().endswith(".zip"): unzip(src_path, get_dir(config)) else: # In this case, the build script will need to deal with unpacking the source print("Warning: Unrecognized source format. Source file will be copied to the SRC_DIR") copy_into(src_path, get_dir(config), config.timeout)
def unpack(meta, config): ''' Uncompress a downloaded source. ''' src_path = download_to_cache(meta, config) if not isdir(config.work_dir): os.makedirs(config.work_dir) if config.verbose: print("Extracting download") if src_path.lower().endswith(('.tar.gz', '.tar.bz2', '.tgz', '.tar.xz', '.tar', 'tar.z')): tar_xf(src_path, config.work_dir) elif src_path.lower().endswith('.zip'): unzip(src_path, config.work_dir) else: # In this case, the build script will need to deal with unpacking the source print("Warning: Unrecognized source format. Source file will be copied to the SRC_DIR") copy_into(src_path, config.work_dir, config.timeout)
def unpack(meta, config): ''' Uncompress a downloaded source. ''' src_path = download_to_cache(meta, config) if not isdir(config.work_dir): os.makedirs(config.work_dir) if config.verbose: print("Extracting download") if src_path.lower().endswith(('.tar.gz', '.tar.bz2', '.tgz', '.tar.xz', '.tar', 'tar.z')): tar_xf(src_path, config.work_dir) elif src_path.lower().endswith('.zip'): unzip(src_path, config.work_dir) else: # In this case, the build script will need to deal with unpacking the source print("Warning: Unrecognized source format. Source file will be copied to the SRC_DIR") copy_into(src_path, config.work_dir, config.timeout, locking=config.locking)