| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #!/usr/bin/env python
- """把 hdkg 批次产物发布到平台共享结果根目录(只读接口读取的位置)。
- 批次目录形如 <batch-root>/<field>/<period>/{detail,report,registration.json},
- 发布后变为 <out-root>/<field>/<period>/...,与 HDKG_OUT_ROOT 对齐。
- 说明:本脚本不做 MinIO 上传、不写平台 MySQL;平台若要登记 analysis_general_file,
- 由现有导入任务或后续 MinIO 导入脚本完成。这里先保证“结果可被页面读取”。
- """
- from __future__ import annotations
- import argparse
- import json
- import shutil
- from pathlib import Path
- def main() -> int:
- ap = argparse.ArgumentParser()
- ap.add_argument("--batch-root", required=True)
- ap.add_argument("--out-root", required=True)
- args = ap.parse_args()
- batch = Path(args.batch_root)
- reg_path = batch / "registration.json"
- if not reg_path.is_file():
- raise SystemExit(f"没有 registration.json: {reg_path}")
- reg = json.loads(reg_path.read_text(encoding="utf-8"))
- if reg.get("status") != "ok":
- raise SystemExit(f"批次状态不是 ok: {reg.get('status')} {reg.get('error')}")
- field = reg.get("fieldCode")
- period = reg.get("period")
- if not field or not period:
- raise SystemExit("registration.json 缺 fieldCode/period")
- if not (batch / "detail" / "health.json").is_file():
- raise SystemExit("缺 detail/health.json")
- target = Path(args.out_root) / field / period
- target.mkdir(parents=True, exist_ok=True)
- for name in ("detail", "report", "logs"):
- src = batch / name
- if src.is_dir():
- shutil.copytree(src, target / name, dirs_exist_ok=True)
- for name in ("check_result.csv", "healthscores_check.csv", "registration.json"):
- src = batch / name
- if src.is_file():
- shutil.copy2(src, target / name)
- print(f"published {field}/{period} -> {target}")
- return 0
- if __name__ == "__main__":
- raise SystemExit(main())
|