Files
auto-solution/scripts/build_spec_documents.py
2026-05-07 15:40:57 +08:00

55 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
以《规则库设计与管理子系统系统软件需求规格说明书》《规则库设计与管理子系统软件设计说明书》
为版式与行文风格底稿(不修改这两份参考文件),仅更新输出:
方案自动化生成-软件需求规格说明书.docx
方案自动化生成-软件设计说明书.docx
实现zip + lxml仅改 w:t 与顶层段落文字;保留块级结构与域。
生成后在 Word 中「更新域」刷新目录与页码。
"""
from pathlib import Path
from template_inplace_engine import collect_hf_paths, fill_docx_inplace, verify_body_structure_same
from template_inplace_mappings import (
SDD_PARAGRAPH_PREDICATES,
SDD_SUBSTRINGS,
SRS_PARAGRAPH_PREDICATES,
SRS_SUBSTRINGS,
)
ROOT = Path(__file__).resolve().parents[1]
# 参考底稿(只读,脚本不写入)
SRS_TEMPLATE = ROOT / "规则库设计与管理子系统系统软件需求规格说明书.docx"
SDD_TEMPLATE = ROOT / "规则库设计与管理子系统软件设计说明书.docx"
SRS_OUT = ROOT / "方案自动化生成-软件需求规格说明书.docx"
SDD_OUT = ROOT / "方案自动化生成-软件设计说明书.docx"
def main():
if not SRS_TEMPLATE.is_file():
raise FileNotFoundError(SRS_TEMPLATE)
if not SDD_TEMPLATE.is_file():
raise FileNotFoundError(SDD_TEMPLATE)
hf_srs = collect_hf_paths(SRS_TEMPLATE)
hf_sdd = collect_hf_paths(SDD_TEMPLATE)
fill_docx_inplace(SRS_TEMPLATE, SRS_OUT, SRS_SUBSTRINGS, SRS_PARAGRAPH_PREDICATES, hf_srs)
ok, msg = verify_body_structure_same(SRS_TEMPLATE, SRS_OUT)
if not ok:
raise RuntimeError("SRS body 结构不一致: " + msg)
print("SRS OK", SRS_OUT, msg)
fill_docx_inplace(SDD_TEMPLATE, SDD_OUT, SDD_SUBSTRINGS, SDD_PARAGRAPH_PREDICATES, hf_sdd)
ok2, msg2 = verify_body_structure_same(SDD_TEMPLATE, SDD_OUT)
if not ok2:
raise RuntimeError("SDD body 结构不一致: " + msg2)
print("SDD OK", SDD_OUT, msg2)
if __name__ == "__main__":
main()