import shutil | |
import tarfile | |
from pathlib import Path | |
from tqdm import tqdm | |
def main(): | |
base_path = Path(".") | |
part_files = list(base_path.glob("*.tar.gz.part001")) | |
for part_file in part_files: | |
prefix = str(part_file).rsplit(".part", 1)[0] | |
part_files = sorted(base_path.glob(f"{prefix}.part*")) | |
tar_file = f"{prefix}.tar.gz" | |
print(f"merging {part_files} into {tar_file} ...") | |
with open(tar_file, "wb") as tar: | |
for part in part_files: | |
with open(part, "rb") as part_file: shutil.copyfileobj(part_file, tar) | |
tar_files = list(base_path.glob("*.tar.gz")) | |
for tar_file in tqdm(tar_files): | |
print(f"extracting {tar_file} ...") | |
with tarfile.open(tar_file, "r") as tar: | |
tar.extractall() | |
print(f"DONE!") | |
if __name__ == "__main__": | |
main() | |