Skip to content

Commit 5d1851b

Browse files
committed
[O] convert check to non-AI script
1 parent ddce7a2 commit 5d1851b

File tree

2 files changed

+97
-12
lines changed

2 files changed

+97
-12
lines changed

.claude/commands/checkSort.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

checkSort.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
"""
4+
检查 configSort.yaml 和 AquaMai.zh.toml 的一致性
5+
6+
检查内容:
7+
1. AquaMai.zh.toml 中的所有 Sections 是否都在 configSort.yaml 中存在
8+
2. configSort.yaml 中"社区功能"分类的内容是否同时存在于其他分类中
9+
"""
10+
11+
import sys
12+
from pathlib import Path
13+
import yaml
14+
15+
16+
def load_toml_sections(toml_path: Path) -> set[str]:
17+
"""从 TOML 文件中提取所有 Section 名称(通过解析 [Section] 标记)"""
18+
sections = set()
19+
20+
with open(toml_path, "r", encoding="utf-8") as f:
21+
for line in f:
22+
line = line.strip()
23+
# 匹配 [Section] 或 #[Section] 格式
24+
if line.startswith("[") or line.startswith("#["):
25+
# 去掉注释符号
26+
if line.startswith("#"):
27+
line = line[1:]
28+
# 提取 Section 名称
29+
if line.startswith("[") and line.endswith("]"):
30+
section = line[1:-1]
31+
sections.add(section)
32+
33+
return sections
34+
35+
36+
def load_yaml_sections(yaml_path: Path) -> dict[str, list[str]]:
37+
"""从 YAML 文件中提取所有分类及其包含的 Sections"""
38+
with open(yaml_path, "r", encoding="utf-8") as f:
39+
data = yaml.safe_load(f)
40+
41+
return data
42+
43+
44+
def main():
45+
# 文件路径
46+
toml_path = Path("Output/AquaMai.zh.toml")
47+
yaml_path = Path("AquaMai/configSort.yaml")
48+
49+
if not toml_path.exists():
50+
print(f"[错误] 找不到文件 {toml_path}")
51+
return 1
52+
53+
if not yaml_path.exists():
54+
print(f"[错误] 找不到文件 {yaml_path}")
55+
return 1
56+
57+
# 加载数据
58+
toml_sections = load_toml_sections(toml_path)
59+
yaml_categories = load_yaml_sections(yaml_path)
60+
61+
# 收集 YAML 中所有的 sections
62+
yaml_all_sections = set()
63+
for sections in yaml_categories.values():
64+
yaml_all_sections.update(sections)
65+
66+
# 检查 1: TOML 中的所有 Sections 是否都在 YAML 中存在
67+
missing_in_yaml = toml_sections - yaml_all_sections
68+
69+
if missing_in_yaml:
70+
print("[失败] 以下 Sections 在 AquaMai.zh.toml 中存在,但不在 configSort.yaml 中:")
71+
for section in sorted(missing_in_yaml):
72+
print(f" - {section}")
73+
return 1
74+
75+
# 检查 2: "社区功能" 中的内容是否都存在于其他分类中
76+
community_sections = set(yaml_categories.get("社区功能", []))
77+
other_sections = set()
78+
79+
for category, sections in yaml_categories.items():
80+
if category != "社区功能":
81+
other_sections.update(sections)
82+
83+
missing_in_other = community_sections - other_sections
84+
85+
if missing_in_other:
86+
print("[失败] 以下 Sections 在\"社区功能\"中存在,但不在其他分类中:")
87+
for section in sorted(missing_in_other):
88+
print(f" - {section}")
89+
return 1
90+
91+
# 所有检查通过
92+
print("[通过] 检查通过")
93+
return 0
94+
95+
96+
if __name__ == "__main__":
97+
sys.exit(main())

0 commit comments

Comments
 (0)