55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import argparse
|
|
from pathlib import Path
|
|
|
|
|
|
def validate_task_output(task_dir: Path) -> list[str]:
|
|
errors: list[str] = []
|
|
if not task_dir.exists():
|
|
return [f"Missing task directory: {task_dir}"]
|
|
if not task_dir.is_dir():
|
|
return [f"Not a directory: {task_dir}"]
|
|
|
|
xlsx_files = sorted(task_dir.glob("*.xlsx"))
|
|
md_files = sorted(task_dir.glob("*.md"))
|
|
if len(xlsx_files) != 1:
|
|
errors.append(f"Expected exactly one .xlsx file, found {len(xlsx_files)}")
|
|
if len(md_files) != 1:
|
|
errors.append(f"Expected exactly one .md file, found {len(md_files)}")
|
|
|
|
if len(xlsx_files) == 1 and len(md_files) == 1:
|
|
if xlsx_files[0].stem != md_files[0].stem:
|
|
errors.append(f"Basenames differ: {xlsx_files[0].name} vs {md_files[0].name}")
|
|
|
|
if len(md_files) == 1:
|
|
text = md_files[0].read_text(encoding="utf-8")
|
|
required = [
|
|
"# 重点风险领域规则模型与脚本",
|
|
"## 目录",
|
|
]
|
|
for marker in required:
|
|
if marker not in text:
|
|
errors.append(f"Markdown missing marker: {marker}")
|
|
if "规则模型" not in text and "暂无生成成功的规则" not in text:
|
|
errors.append("Markdown has neither rule models nor an empty-rules marker")
|
|
|
|
return errors
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description="Validate a YG-Rules task output directory.")
|
|
parser.add_argument("task_dir", type=Path)
|
|
args = parser.parse_args()
|
|
|
|
errors = validate_task_output(args.task_dir)
|
|
if errors:
|
|
for error in errors:
|
|
print(f"ERROR: {error}")
|
|
return 1
|
|
|
|
print(f"OK: {args.task_dir}")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|