87 lines
3.1 KiB
Python
87 lines
3.1 KiB
Python
#!/usr/bin/env python
|
|
"""COBOL 迁移验证平台全流程入口:先白盒 cobol_testgen 再黑盒 LLM 数据生成。
|
|
|
|
用法:
|
|
python run.py --design <詳細設計書.md> --source <程序.cbl> \
|
|
--file-db-md <COPY句定義書.md> --cpy <COPYBOOK目录> \
|
|
--db-md <DB定義書.md> --output <输出目录>
|
|
|
|
步骤:
|
|
1) cobol_testgen (白盒静态分析 + 测试数据生成) → python -m cobol_testgen --gcov <source> <output>
|
|
2) black-box-data-create (DeepSeek LLM 数据生成) → 透传全部参数给 black-box-data-create/main.py
|
|
|
|
任一步失败即停止,返回该步退出码。
|
|
"""
|
|
import argparse
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
BLACKBOX_MAIN = os.path.join(ROOT, "black-box-data-create", "main.py")
|
|
|
|
|
|
def build_parser():
|
|
p = argparse.ArgumentParser(
|
|
description="COBOL 迁移验证平台:先跑白盒 cobol_testgen,再跑黑盒 LLM 数据生成")
|
|
p.add_argument("--design", required=True, help="詳細設計書 .md のパス")
|
|
p.add_argument("--source", required=True, help="COBOL ソース .cbl のパス")
|
|
p.add_argument("--file-db-md", required=True, help="ファイル/DB 構造 .md のパス")
|
|
p.add_argument("--cpy", required=True, help="COPYBOOK 格納ディレクトリ")
|
|
p.add_argument("--db-md", required=True, help="DB 定義書 .md のパス")
|
|
p.add_argument("--output", default="output", help="出力ディレクトリ")
|
|
p.add_argument("--api-key", help="DeepSeek API Key(透传给黑盒)")
|
|
p.add_argument("--model", help="API モデル名(透传给黑盒)")
|
|
p.add_argument("--rules", help="ルール格納ディレクトリ(透传给黑盒)")
|
|
p.add_argument("--max-tokens", type=int, help="API 生成トークン上限(透传给黑盒)")
|
|
p.add_argument("--dry-run", action="store_true", help="只打印要执行的命令,不真正执行")
|
|
return p
|
|
|
|
|
|
def _run(cmd, cwd, label, dry_run=False):
|
|
print(f"\n== {label} ==")
|
|
print(f" $ {' '.join(cmd)}")
|
|
if dry_run:
|
|
print(" [dry-run] 跳过执行")
|
|
return 0
|
|
r = subprocess.run(cmd, cwd=cwd)
|
|
return r.returncode
|
|
|
|
|
|
def main():
|
|
args = build_parser().parse_args()
|
|
|
|
rc = _run(
|
|
[sys.executable, "-m", "cobol_testgen", "--gcov", args.source, args.output],
|
|
cwd=ROOT,
|
|
label="步骤1: cobol_testgen 白盒数据生成",
|
|
dry_run=args.dry_run,
|
|
)
|
|
if rc != 0:
|
|
return rc
|
|
|
|
bb_cmd = [
|
|
sys.executable, BLACKBOX_MAIN,
|
|
"--design", args.design,
|
|
"--source", args.source,
|
|
"--file-db-md", args.file_db_md,
|
|
"--cpy", args.cpy,
|
|
"--db-md", args.db_md,
|
|
"--output", args.output,
|
|
]
|
|
for opt in ("--api-key", "--model", "--rules", "--max-tokens"):
|
|
v = getattr(args, opt.lstrip("-").replace("-", "_"))
|
|
if v is not None:
|
|
bb_cmd.extend([opt, str(v)])
|
|
|
|
return _run(
|
|
bb_cmd,
|
|
cwd=ROOT,
|
|
label="步骤2: black-box-data-create LLM 数据生成",
|
|
dry_run=args.dry_run,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|