#!/usr/bin/env python3 """Set the registry's enabled flags to exactly the given challenge names. `set_challenge_enabled` only reports a change when the flag actually differs, so flipping several challenges at once through the API is a long round trip. This writes the registry directly (the same file the API writes) and leaves runtime reconciliation to panel/sync_all_challenges.py. Usage: python3 panel/set_enabled.py gift-card art fjb python3 panel/set_enabled.py --clear """ import json import sys from pathlib import Path REG = Path("/opt/gemastik18-final/teams/challenge_registry.json") def main(argv): reg = json.loads(REG.read_text()) names = [c["name"] for c in reg["challenges"]] want = set(argv[1:]) if "--clear" not in argv else set() unknown = want - set(names) if unknown: print("unknown challenge(s):", ", ".join(sorted(unknown))) return 2 for c in reg["challenges"]: c["enabled"] = c["name"] in want REG.write_text(json.dumps(reg, indent=2) + "\n") enabled = [c["name"] for c in reg["challenges"] if c["enabled"]] print(f"registry now enables {len(enabled)}: {', '.join(enabled)}") return 0 if __name__ == "__main__": raise SystemExit(main(sys.argv))