avoid duplicate DICOM zip compression
This commit is contained in:
@@ -407,6 +407,40 @@ def zip_folder(source_dir, zip_path):
|
||||
return zip_path
|
||||
|
||||
|
||||
def zip_result_bundle(zip_path, state_zips, preview_paths):
|
||||
zip_path = Path(zip_path).resolve()
|
||||
safe_mkdir(zip_path.parent)
|
||||
if zip_path.exists():
|
||||
zip_path.unlink()
|
||||
|
||||
comparison_path = Path(preview_paths["comparison"]).resolve()
|
||||
screenshots_dir = Path(preview_paths["screenshots"]).resolve()
|
||||
|
||||
with zipfile.ZipFile(zip_path, "w", compression=zipfile.ZIP_DEFLATED) as archive:
|
||||
for state_key, state_zip in state_zips.items():
|
||||
source_zip = Path(state_zip).resolve()
|
||||
archive.write(
|
||||
source_zip,
|
||||
f"dicom_zips/{source_zip.name}",
|
||||
compress_type=zipfile.ZIP_STORED,
|
||||
)
|
||||
|
||||
if comparison_path.exists():
|
||||
archive.write(
|
||||
comparison_path,
|
||||
f"previews/{comparison_path.name}",
|
||||
)
|
||||
|
||||
if screenshots_dir.exists():
|
||||
for file_path in screenshots_dir.rglob("*"):
|
||||
if file_path.is_file():
|
||||
archive.write(
|
||||
file_path,
|
||||
Path("previews/process_screenshots") / file_path.relative_to(screenshots_dir),
|
||||
)
|
||||
return zip_path
|
||||
|
||||
|
||||
def set_job(job_id, **updates):
|
||||
with JOBS_LOCK:
|
||||
job = JOBS[job_id]
|
||||
@@ -612,10 +646,11 @@ class Handler(BaseHTTPRequestHandler):
|
||||
output_paths[state_key],
|
||||
job_root / f"{state_key}_{job_id}.zip",
|
||||
)
|
||||
set_job(job_id, message="正在打包四状态输出 ZIP...")
|
||||
zip_path = zip_folder(
|
||||
output_dir,
|
||||
set_job(job_id, message="正在整理四状态总 ZIP...")
|
||||
zip_path = zip_result_bundle(
|
||||
job_root / f"head_ct_morph_{job_id}.zip",
|
||||
state_zips,
|
||||
preview_paths,
|
||||
)
|
||||
return serialize_outputs(output_paths, preview_paths, zip_path, state_zips)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user