Skip to content

Commit

Permalink
feat: uploader: 20x 7z packaging speed
Browse files Browse the repository at this point in the history
  • Loading branch information
yzqzss committed Sep 12, 2023
1 parent ce17a94 commit 32d6acc
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions wikiteam3/uploader/compresser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, bin7z: str = "7z"):
raise FileNotFoundError(f"7z binary not found at {bin7z}")

@staticmethod
def compress_dir(dir_path: Union[str, Path], bin7z: str = "7z", level: int = 1):
def compress_dir(dir_path: Union[str, Path], bin7z: str = "7z", level: int = 0):
''' Compress dir_path into dump_dir.7z and return the resolved path to the compressed file.
level:
Expand All @@ -108,11 +108,16 @@ def compress_dir(dir_path: Union[str, Path], bin7z: str = "7z", level: int = 1):
print(f"File {archive_path} already exists. Skip compressing.")
return archive_path

r = subprocess.run(
[bin7z, "a", "-t7z", "-m0=lzma2", f"-mx={level}", "-scsUTF-8",
"-md=64m", "-ms=off", str(archive_temp_path), dir_path],
check=True
)
if level:
cmds = [bin7z, "a", "-t7z", "-m0=lzma2", f"-mx={level}", "-scsUTF-8",
"-md=64m", "-ms=off"]
else: # level == 0
assert level == 0
cmds = [bin7z, "a", "-t7z", f"-mx={level}", "-scsUTF-8", "-ms=off"]
cmds.extend([str(archive_temp_path), str(dir_path)])

r = subprocess.run(cmds, check=True)

assert archive_temp_path.exists()
# move tmp file to final file
os.rename(archive_temp_path, archive_path)
Expand Down

0 comments on commit 32d6acc

Please sign in to comment.