Files
mtgodot-poc/scripts/audit_zh_server_names.py
T
shenleiandClaude Opus 5.5 a46093104c layout: restructure into src/ tests/ android/ scripts/ tools/
- extension/src/{port,platform,codepage} -> src/; native_render -> src/host
  (+ dxt, shaders/); libgr2 -> src/gr2; extension/third_party -> third_party
- extension/tests -> tests/port, libgr2/tests -> tests/gr2
- android-native -> android (build.sh, push-client.sh moved in)
- script -> scripts; tools/40250 -> tools/server; oracle -> tools/granny-oracle;
  perf tools -> tools/perf
- all build trees under build/ (native, release, android, port-gate)
- xrender:: CMake aliases -> mt::; port-map ledger impl paths rewritten

No code changes. ctest 15/15, port_gate macos+android PASS, port_map check 0 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 19:08:19 +09:00

76 lines
2.7 KiB
Python

#!/usr/bin/env python3
"""Compare a read-only 40250 database name export with the older Chinese tables."""
import argparse
import json
from pathlib import Path
REPO = Path(__file__).resolve().parents[1]
DEFAULT_EXPORT = REPO / "build/zh-locale/server-audit"
DEFAULT_TABLES = REPO.parent / "server_extracted/40250_deploy"
def live_names(path: Path):
names = {}
for number, line in enumerate(path.read_text(encoding="ascii").splitlines(), 1):
try:
vnum, encoded = line.split("\t", 1)
name = bytes.fromhex(encoded).decode("gbk")
if int(vnum) in names:
raise ValueError("duplicate VNUM")
names[int(vnum)] = name
except (ValueError, UnicodeDecodeError) as error:
raise ValueError(f"{path}:{number}: {error}") from error
return names
def older_names(path: Path):
names = {}
for line in path.read_text(encoding="utf-8").splitlines()[1:]:
vnum, name = line.split("\t", 1)
names[int(vnum)] = name
return names
def audit(export_dir: Path, tables_dir: Path):
result = {}
for kind in ("item", "mob"):
live = live_names(export_dir / f"{kind}_names_hex.tsv")
older = older_names(tables_dir / f"{kind}_names_zh.txt")
shared = live.keys() & older.keys()
conflicts = [
{"vnum": vnum, "server": live[vnum], "older_table": older[vnum]}
for vnum in sorted(shared) if live[vnum] != older[vnum]
]
result[kind] = {
"server_rows": len(live),
"older_table_rows": len(older),
"shared_vnums": len(shared),
"server_only_vnums": len(live.keys() - older.keys()),
"older_only_vnums": len(older.keys() - live.keys()),
"server_names_without_hanzi": sum(
not any("\u4e00" <= char <= "\u9fff" for char in name)
for name in live.values()
),
"conflicts": conflicts,
}
return result
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--export-dir", type=Path, default=DEFAULT_EXPORT)
parser.add_argument("--tables-dir", type=Path, default=DEFAULT_TABLES)
parser.add_argument("--output", type=Path, default=DEFAULT_EXPORT / "name-audit.json")
args = parser.parse_args()
report = audit(args.export_dir, args.tables_dir)
args.output.write_text(json.dumps(report, ensure_ascii=False, indent=2) + "\n", encoding="utf-8")
for kind, data in report.items():
print(f"{kind}: rows={data['server_rows']} no_hanzi={data['server_names_without_hanzi']} "
f"conflicts={len(data['conflicts'])}")
if __name__ == "__main__":
main()