Spaces:
Runtime error
Runtime error
File size: 717 Bytes
99fdb5f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import subprocess
import os
import uuid
import shutil
from core.config import settings
def extract_archive(input_path: str):
extract_dir = os.path.join(settings.TEMP_DIR, f"extract_{uuid.uuid4()}")
os.makedirs(extract_dir, exist_ok=True)
cmd = ["7z", "x", input_path, f"-o{extract_dir}", "-y"]
subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return extract_dir
def rezip_folder(folder_path: str, target_ext: str):
output_name = f"{uuid.uuid4()}.{target_ext}"
output_path = os.path.join(settings.OUTPUT_DIR, output_name)
cmd = ["7z", "a", output_path, folder_path]
subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return output_path
|