Files
mandy/scripts/sync_victory.py
NotRexed 5aec2353db Add VIctory sync and run-control tools; let the pad file press buttons
scripts/sync_victory.py fetches DexNom/VIctory and merges new commits into
victory/ with git subtree pull. scripts/port_ctl.py starts a run with its
logs, captures and saves outside the repository, presses stand-in pad keys
through VICTORY_MOVEMENT_FILE, saves frames through VICTORY_CAPTURE_REQUEST
and reads the frame-rate lines.

The movement file now takes every key of the stand-in pad's table (Enter,
Back, Esc, Tab, the D-pad, shoulders, triggers, stick clicks), so menus can
be driven by a script. Tested with cargo test -p victory-hle --features
diagnostics movement (4 passed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 15:48:32 -05:00

94 lines
3.2 KiB
Python

#!/usr/bin/env python3
"""Check DexNom/VIctory for new commits and optionally merge them into victory/.
VIctory lives in this repository as a git subtree under ``victory/`` (added with
``git subtree add --prefix=victory victory main``). This tool fetches the
``victory`` remote, reports the commits that are not merged yet and, with
``--merge``, pulls them in with ``git subtree pull`` so upstream history is kept
and local changes under ``victory/`` are merged, not overwritten.
Run from anywhere inside the repository:
python -I scripts/sync_victory.py # report only
python -I scripts/sync_victory.py --merge # report, then merge if clean
Exit codes: 0 up to date or merged, 10 updates waiting (report only),
2 git failure, 3 working tree not clean (merge refused), 4 merge conflict.
"""
import argparse
import datetime
import os
import subprocess
import sys
REMOTE = "victory"
BRANCH = "main"
PREFIX = "victory"
def git(*args, check=True):
proc = subprocess.run(
["git", *args],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
encoding="utf-8",
errors="replace",
)
if check and proc.returncode != 0:
print(f"git {' '.join(args)} failed ({proc.returncode}):\n{proc.stdout}")
sys.exit(2)
return proc
def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--merge", action="store_true", help="merge new commits with git subtree pull")
args = ap.parse_args()
top = git("rev-parse", "--show-toplevel").stdout.strip()
os.chdir(top)
stamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
git("fetch", "--quiet", REMOTE, BRANCH)
upstream = git("rev-parse", f"{REMOTE}/{BRANCH}").stdout.strip()
merged = git("merge-base", "--is-ancestor", upstream, "HEAD", check=False).returncode == 0
if merged:
print(f"[{stamp}] {REMOTE}/{BRANCH} {upstream[:9]} is already merged; nothing to do.")
return 0
new = git("log", "--oneline", "--no-decorate", f"HEAD..{upstream}").stdout.strip().splitlines()
print(f"[{stamp}] {len(new)} new {REMOTE}/{BRANCH} commit(s) up to {upstream[:9]}:")
for line in new:
print(f" {line}")
if not args.merge:
return 10
dirty = git("status", "--porcelain", "--untracked-files=no").stdout.strip()
if dirty:
print("Working tree has uncommitted changes; commit or stash them, then run --merge again.")
print(dirty)
return 3
msg = (
f"Merge {REMOTE}/{BRANCH} {upstream[:9]} into {PREFIX}/ ({len(new)} commit(s))\n\n"
"Pulled with scripts/sync_victory.py --merge (git subtree pull).\n"
)
pull = git("subtree", "pull", f"--prefix={PREFIX}", REMOTE, BRANCH, "-m", msg, check=False)
print(pull.stdout.strip())
if pull.returncode != 0:
conflicts = git("diff", "--name-only", "--diff-filter=U", check=False).stdout.strip()
if conflicts:
print("Merge stopped on conflicts in:")
print(conflicts)
return 4
print("git subtree pull failed.")
return 2
print(f"Merged {REMOTE}/{BRANCH} {upstream[:9]} into {PREFIX}/.")
return 0
if __name__ == "__main__":
sys.exit(main())