File size: 858 Bytes
bfbecd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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()