_refresh_toc_s1style.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. """批量刷新 S1 风格 20 份交付文档的目录域(逐文件独立 Word 进程)。"""
  3. import subprocess
  4. import sys
  5. from pathlib import Path
  6. HERE = Path(__file__).resolve().parent
  7. sys.path.insert(0, str(HERE))
  8. from _gen_s1style_delivery import DELIVER, PENDING # noqa: E402
  9. FILES = [fname for dl in DELIVER.values() for fname in dl["files"].values()]
  10. def main():
  11. ok = 0
  12. for f in FILES:
  13. p = PENDING / f
  14. if not p.exists():
  15. print("MISS", f, flush=True)
  16. continue
  17. try:
  18. r = subprocess.run(
  19. [sys.executable, str(HERE / "_word_toc_one.py"), str(p)],
  20. capture_output=True, text=True, timeout=300,
  21. )
  22. out = (r.stdout or "").strip().replace("\n", " ")
  23. err = (r.stderr or "").strip().splitlines()
  24. tag = "OK " if r.returncode == 0 else "ERR"
  25. print(f"{tag} {f} {out}", flush=True)
  26. if r.returncode != 0 and err:
  27. print(" ", err[-1][:160], flush=True)
  28. if r.returncode == 0:
  29. ok += 1
  30. except Exception as exc:
  31. print(f"ERR {f} {exc}", flush=True)
  32. print(f"DONE {ok}/{len(FILES)}", flush=True)
  33. if __name__ == "__main__":
  34. main()