Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/api/private/deposit_read.py
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def aggregate_tarballs(extraction_dir, archive_paths): | ||||
aggregated_tarball_rootdir = os.path.join(dir_path, 'aggregate') | aggregated_tarball_rootdir = os.path.join(dir_path, 'aggregate') | ||||
os.makedirs(aggregated_tarball_rootdir, 0o755, exist_ok=True) | os.makedirs(aggregated_tarball_rootdir, 0o755, exist_ok=True) | ||||
# uncompress in a temporary location all archives | # uncompress in a temporary location all archives | ||||
for archive_path in archive_paths: | for archive_path in archive_paths: | ||||
tarball.uncompress(archive_path, aggregated_tarball_rootdir) | tarball.uncompress(archive_path, aggregated_tarball_rootdir) | ||||
# Aggregate into one big tarball the multiple smaller ones | # Aggregate into one big tarball the multiple smaller ones | ||||
temp_tarpath = tarball.compress( | temp_tarpath = shutil.make_archive( | ||||
aggregated_tarball_rootdir + '.zip', | aggregated_tarball_rootdir, 'zip', | ||||
nature='zip', | aggregated_tarball_rootdir) | ||||
dirpath_or_files=aggregated_tarball_rootdir) | |||||
# can already clean up temporary directory | # can already clean up temporary directory | ||||
shutil.rmtree(aggregated_tarball_rootdir) | shutil.rmtree(aggregated_tarball_rootdir) | ||||
try: | try: | ||||
yield temp_tarpath | yield temp_tarpath | ||||
finally: | finally: | ||||
shutil.rmtree(dir_path) | shutil.rmtree(dir_path) | ||||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |