-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate_screenplay.py
More file actions
43 lines (34 loc) · 1.13 KB
/
Copy pathvalidate_screenplay.py
File metadata and controls
43 lines (34 loc) · 1.13 KB
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
"""
validate_screenplay.py - 命令行校验工具 (薄封装,核心逻辑在 validator.py)
用法: python validate_screenplay.py examples/last-ferry.screenplay.yaml
"""
import sys
import yaml
import validator
def main():
if len(sys.argv) < 2:
print("用法: python validate_screenplay.py <screenplay.yaml>")
sys.exit(1)
yaml_path = sys.argv[1]
try:
with open(yaml_path, encoding="utf-8") as f:
data = yaml.safe_load(f)
except FileNotFoundError:
print(f"❌ 文件不存在: {yaml_path}")
sys.exit(1)
except yaml.YAMLError as e:
print(f"❌ YAML 格式错误: {e}")
sys.exit(1)
ok, errors = validator.validate(data)
if not ok:
print(f"❌ 校验失败({len(errors)} 项):")
for e in errors:
print(f" - {e}")
sys.exit(1)
meta = data.get("metadata", {})
print("✅ 校验全部通过!")
print(f" 剧本: {meta.get('title', '(无标题)')}")
print(f" 人物: {len(data.get('characters', []))} 位")
print(f" 场次: {len(data.get('scenes', []))} 场")
if __name__ == "__main__":
main()