Changeset View
Changeset View
Standalone View
Standalone View
swh/core/tarball.py
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | Args: | ||||
it will be created if it does not exist | it will be created if it does not exist | ||||
Raises: | Raises: | ||||
ValueError when a problem occurs during unpacking | ValueError when a problem occurs during unpacking | ||||
""" | """ | ||||
try: | try: | ||||
os.makedirs(dest, exist_ok=True) | os.makedirs(dest, exist_ok=True) | ||||
shutil.unpack_archive(tarpath, extract_dir=dest) | format = None | ||||
for format_, exts, _ in shutil.get_unpack_formats(): | |||||
if any([tarpath.lower().endswith(ext.lower()) for ext in exts]): | |||||
format = format_ | |||||
break | |||||
shutil.unpack_archive(tarpath, extract_dir=dest, format=format) | |||||
except shutil.ReadError as e: | except shutil.ReadError as e: | ||||
raise ValueError(f"Problem during unpacking {tarpath}. Reason: {e}") | raise ValueError(f"Problem during unpacking {tarpath}. Reason: {e}") | ||||
except NotImplementedError: | except NotImplementedError: | ||||
if tarpath.endswith(".zip"): | if tarpath.lower().endswith(".zip"): | ||||
_unpack_zip(tarpath, dest) | _unpack_zip(tarpath, dest) | ||||
else: | else: | ||||
raise | raise | ||||
normalize_permissions(dest) | normalize_permissions(dest) | ||||
def normalize_permissions(path: str): | def normalize_permissions(path: str): | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |