Changeset View
Changeset View
Standalone View
Standalone View
swh/core/tarball.py
Show All 31 Lines | Returns | ||||
full path to the uncompressed directory. | full path to the uncompressed directory. | ||||
""" | """ | ||||
try: | try: | ||||
run(['tar', 'xf', tarpath, '-C', extract_dir], check=True) | run(['tar', 'xf', tarpath, '-C', extract_dir], check=True) | ||||
return extract_dir | return extract_dir | ||||
except Exception as e: | except Exception as e: | ||||
raise shutil.ReadError( | raise shutil.ReadError( | ||||
f'Unable to uncompress {tarpath} to {extract_dir}. Reason: {e}') | f'Unable to uncompress {tarpath} to {extract_dir}. Reason: {e}' | ||||
) | |||||
def register_new_archive_formats(): | def register_new_archive_formats(): | ||||
"""Register new archive formats to uncompress | """Register new archive formats to uncompress | ||||
""" | """ | ||||
registered_formats = [f[0] for f in shutil.get_unpack_formats()] | registered_formats = [f[0] for f in shutil.get_unpack_formats()] | ||||
for name, extensions, function in ADDITIONAL_ARCHIVE_FORMATS: | for name, extensions, function in ADDITIONAL_ARCHIVE_FORMATS: | ||||
Show All 35 Lines | for dirpath, _, fnames in os.walk(dest): | ||||
os.chmod(fpath, 0o644) | os.chmod(fpath, 0o644) | ||||
def _ls(rootdir): | def _ls(rootdir): | ||||
"""Generator of filepath, filename from rootdir. | """Generator of filepath, filename from rootdir. | ||||
""" | """ | ||||
for dirpath, dirnames, fnames in os.walk(rootdir): | for dirpath, dirnames, fnames in os.walk(rootdir): | ||||
for fname in (dirnames+fnames): | for fname in dirnames + fnames: | ||||
fpath = os.path.join(dirpath, fname) | fpath = os.path.join(dirpath, fname) | ||||
fname = utils.commonname(rootdir, fpath) | fname = utils.commonname(rootdir, fpath) | ||||
yield fpath, fname | yield fpath, fname | ||||
def _compress_zip(tarpath, files): | def _compress_zip(tarpath, files): | ||||
"""Compress dirpath's content as tarpath. | """Compress dirpath's content as tarpath. | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |