feat: run.py 改为全流程入口,先白盒 cobol_testgen 后黑盒 LLM 数据生成
This commit is contained in:
@@ -1,50 +1,85 @@
|
||||
#!/usr/bin/env python
|
||||
"""COBOL 迁移验证平台统一入口。
|
||||
"""COBOL 迁移验证平台全流程入口:先白盒 cobol_testgen 再黑盒 LLM 数据生成。
|
||||
|
||||
用法:
|
||||
python run.py verify <主工程参数...> # 透传给 main.py (COBOL->Java/Spark 迁移验证)
|
||||
python run.py blackbox <黑盒参数...> # 透传给 black-box-data-create/main.py (LLM 测试数据生成)
|
||||
python run.py --design <詳細設計書.md> --source <程序.cbl> \
|
||||
--file-db-md <COPY句定義書.md> --cpy <COPYBOOK目录> \
|
||||
--db-md <DB定義書.md> --output <输出目录>
|
||||
|
||||
子命令后的参数原样转发给目标 main.py,由目标自行解析,本脚本不做任何处理。
|
||||
步骤:
|
||||
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")
|
||||
|
||||
TARGETS = {
|
||||
"verify": os.path.join(ROOT, "main.py"),
|
||||
"blackbox": os.path.join(ROOT, "black-box-data-create", "main.py"),
|
||||
}
|
||||
|
||||
USAGE = """\
|
||||
用法: python run.py <verify|blackbox> [参数...]
|
||||
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
|
||||
|
||||
子命令:
|
||||
verify - 主工程: COBOL->Java/Spark 迁移验证(透传给 main.py)
|
||||
blackbox - 黑盒工程: LLM 测试数据生成(透传给 black-box-data-create/main.py)
|
||||
"""
|
||||
|
||||
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():
|
||||
if len(sys.argv) < 2:
|
||||
print(USAGE, file=sys.stderr)
|
||||
return 2
|
||||
args = build_parser().parse_args()
|
||||
|
||||
engine = sys.argv[1]
|
||||
target = TARGETS.get(engine)
|
||||
if target is None:
|
||||
print(f"错误: 未知子命令 '{engine}'\n", file=sys.stderr)
|
||||
print(USAGE, file=sys.stderr)
|
||||
return 2
|
||||
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
|
||||
|
||||
if not os.path.exists(target):
|
||||
print(f"错误: 找不到目标脚本: {target}", file=sys.stderr)
|
||||
return 2
|
||||
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)])
|
||||
|
||||
passthrough = sys.argv[2:]
|
||||
return subprocess.run([sys.executable, target] + passthrough).returncode
|
||||
return _run(
|
||||
bb_cmd,
|
||||
cwd=ROOT,
|
||||
label="步骤2: black-box-data-create LLM 数据生成",
|
||||
dry_run=args.dry_run,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user