files-game/tools/sync_data.py
2026-10-01 17:22:18 -04:00

53 lines
1.6 KiB
Python
Executable file

#!/usr/bin/env python3
"""Copies the card data the GDScript engine reads from the files-tcg repo into data/
(godot-plan.md M0). Run it after editing cards.csv; the conformance runner refuses traces made from
a different CSV.
tools/sync_data.py copy
tools/sync_data.py --check exit 1 if data/ is stale
"""
import argparse
import filecmp
import shutil
import sys
from pathlib import Path
PROJECT = Path(__file__).resolve().parent.parent
DEFAULT_REPO = Path.home() / "Troglodyte-Chamber" / "files-tcg"
# Repo path -> project path.
FILES = {
"decks/files-deck-1/cards.csv": "data/cards.csv",
}
def main() -> int:
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("--repo", type=Path, default=DEFAULT_REPO, help="files-tcg checkout")
ap.add_argument("--check", action="store_true", help="only report stale files")
args = ap.parse_args()
stale = []
for src_rel, dst_rel in FILES.items():
src, dst = args.repo / src_rel, PROJECT / dst_rel
if not src.exists():
print(f"missing in repo: {src}", file=sys.stderr)
return 2
if dst.exists() and filecmp.cmp(src, dst, shallow=False):
continue
stale.append(dst_rel)
if not args.check:
dst.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(src, dst)
print(f"updated {dst_rel}")
if args.check:
for f in stale:
print(f"stale: {f}")
return 1 if stale else 0
if not stale:
print("data/ is up to date")
return 0
if __name__ == "__main__":
sys.exit(main())