1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| from __future__ import annotations
|
| import argparse
| import json
| import sys
| from pathlib import Path
|
| from .core import InputError, run_pipeline
|
|
| def build_parser() -> argparse.ArgumentParser:
| parser = argparse.ArgumentParser(
| description="读取标准估值快照,一次生成计算结果、质检清单、报告和运行清单。"
| )
| parser.add_argument("--input", required=True, type=Path, help="标准估值快照 JSON")
| parser.add_argument("--output-dir", required=True, type=Path, help="本次运行输出目录")
| parser.add_argument(
| "--source-registry",
| type=Path,
| default=Path(__file__).with_name("source_registry.json"),
| help="可信信源注册表;默认使用包内固定版本",
| )
| parser.add_argument("--force", action="store_true", help="忽略有效缓存,强制重算")
| return parser
|
|
| def main(argv: list[str] | None = None) -> int:
| args = build_parser().parse_args(argv)
| try:
| status = run_pipeline(
| snapshot_path=args.input,
| output_dir=args.output_dir,
| source_registry_path=args.source_registry,
| force=args.force,
| )
| except InputError as exc:
| print(
| json.dumps(
| {"status": "INPUT_ERROR", "errors": exc.errors},
| ensure_ascii=False,
| indent=2,
| ),
| file=sys.stderr,
| )
| return 2
| except (OSError, json.JSONDecodeError) as exc:
| print(
| json.dumps(
| {"status": "RUNTIME_ERROR", "error": str(exc)},
| ensure_ascii=False,
| indent=2,
| ),
| file=sys.stderr,
| )
| return 3
|
| print(json.dumps(status, ensure_ascii=False, indent=2))
| return 0
|
|