# -*- coding: utf-8 -*- """模块详设去掉非功能设计、SaaS部署与运维;总纲补 SaaS 章;刷新目录。""" from __future__ import annotations import sys from pathlib import Path HERE = Path(__file__).resolve().parent if str(HERE) not in sys.path: sys.path.insert(0, str(HERE)) from docx import Document from _delivery_docx_polish import ( SAAS_NFR_H1_RE, drop_h1_sections, force_all_text_black, insert_toc_field, latest_formal_files, open_via_temp, renumber_heading_gaps, save_via_temp, ) from _fix_toc_and_numbering import refresh_one from _gen_delivery_sys_docs import write_sys_dds from _unify_ab_delivery_vnext import BASE def is_module_dds(path: Path) -> bool: name = path.name if "详细设计" not in name: return False if "总纲" in name: return False return path.parent.name in {f"S{i}" for i in range(9)} def process_module(path: Path) -> str: doc = open_via_temp(path) dropped = drop_h1_sections(doc, SAAS_NFR_H1_RE) renum = renumber_heading_gaps(doc) insert_toc_field(doc) force_all_text_black(doc) save_via_temp(doc, path) return f"{path.parent.name}/{path.name} drop={dropped} renum={renum}" def main() -> None: import _gen_delivery_sys_docs as sysgen orig = sysgen.save_doc def save_ver(doc, dest): dest = Path(dest) orig(doc, dest.with_name(f"{dest.stem}-V0.4{dest.suffix}")) sysgen.save_doc = save_ver try: write_sys_dds() finally: sysgen.save_doc = orig files = [p for p in latest_formal_files(BASE) if is_module_dds(p)] sys_dds = BASE / "00-系统总纲" / "SYS-详细设计说明书-总纲-V0.4.docx" print("modules", len(files), flush=True) for p in files: print("prep", process_module(p), flush=True) targets = files + [sys_dds] print("toc", len(targets), flush=True) for p in targets: try: print(f"OK {p.parent.name}/{p.name} {refresh_one(p)}", flush=True) except Exception as exc: print(f"FAIL {p.parent.name}/{p.name}: {exc}", flush=True) if __name__ == "__main__": main()