Files
ginnoir cb294f72a0 fix: address whole-branch review findings for update-swarm
- versions: require entire normalized string to be numeric so dates
  and hotfix suffixes compare as incomparable instead of eq/gt
- hosts: exact host or dot-suffix match rejects lookalikes like
  notmediafire.com and evilmega.nz; GitHub stays exact-set
- census: lazy extractor loop so a later OSError no longer discards an
  earlier sidecar changelog hit
- jobs: watchlist parses only table rows whose vault-note cell is a
  bare wikilink (skips parenthetical related/complete notes); wanted
  also matches bold names in Wanted.md tables with Pokemon prefix
  stripped and casefolded
- cli: validate-scouts and judge raise SystemExit when jobs.json has
  jobs but scouts/ has zero valid files
- fetch: download forwards timeout=60 to urlopen and writes to a
  .part file then os.replace, removing the partial on any failure
2026-08-14 15:11:16 -05:00

88 lines
3.3 KiB
Python

from __future__ import annotations
import argparse, glob, os, sys
from update_swarm.jobs import build_jobs, init_run
from update_swarm.judge import judge_all
from update_swarm.reports import write_reports
from update_swarm.schema import read_json, write_json
SCOUT_KEYS = ["stem", "latest_english_version", "url", "host", "gate",
"language_matrix", "source_used", "hackdex", "upstream_status", "notes"]
def validate_scout(obj: dict) -> list[str]:
return [k for k in SCOUT_KEYS if k not in obj]
def deploy_argv(pokemon_repo: str, site_repo: str) -> list[list[str]]:
return [
["python", "scripts/build-vault-mocs.py"],
["python", "scripts/build-wiki-data.py"],
["powershell", "-File", "scripts/deploy-site.ps1"],
]
def _load_scouts(run_dir: str, jobs: list[dict] | None = None) -> dict:
out = {}
for path in glob.glob(os.path.join(run_dir, "scouts", "*.json")):
obj = read_json(path)
errs = validate_scout(obj)
if errs:
raise SystemExit(f"{path} missing keys: {errs}")
out[obj["stem"]] = obj
if jobs and len(jobs) > 0 and not out:
raise SystemExit("no valid scout files in scouts/ but jobs.json has jobs")
return out
def _load_census(run_dir: str) -> dict:
out = {}
for path in glob.glob(os.path.join(run_dir, "census", "*.json")):
obj = read_json(path)
out[obj["stem"]] = obj
return out
def main(argv=None) -> int:
p = argparse.ArgumentParser(prog="update-swarm")
p.add_argument("--run", required=False, help="path to .scrape/update-runs/YYYY-MM-DD")
sub = p.add_subparsers(dest="cmd", required=True)
sub.add_parser("init")
pj = sub.add_parser("jobs")
pj.add_argument("--vault", required=True)
sub.add_parser("validate-scouts")
sub.add_parser("judge")
sub.add_parser("reports")
args = p.parse_args(argv)
if args.cmd == "init":
if not args.run:
raise SystemExit("--run is required")
init_run(args.run)
return 0
if args.cmd == "jobs":
if not args.run:
raise SystemExit("--run is required")
jobs = build_jobs(args.vault)
write_json(os.path.join(args.run, "jobs.json"), {"run_date": os.path.basename(args.run), "jobs": jobs})
print(f"wrote {len(jobs)} jobs")
return 0
if args.cmd == "validate-scouts":
if not args.run:
raise SystemExit("--run is required")
jobs = read_json(os.path.join(args.run, "jobs.json")).get("jobs")
_load_scouts(args.run, jobs)
print("scouts ok")
return 0
if args.cmd == "judge":
if not args.run:
raise SystemExit("--run is required")
jobs = read_json(os.path.join(args.run, "jobs.json"))["jobs"]
verdicts = judge_all(jobs, _load_census(args.run), _load_scouts(args.run, jobs))
write_json(os.path.join(args.run, "verdict.json"), {"verdicts": verdicts})
print(f"wrote {len(verdicts)} verdicts")
return 0
if args.cmd == "reports":
if not args.run:
raise SystemExit("--run is required")
verdicts = read_json(os.path.join(args.run, "verdict.json"))["verdicts"]
write_reports(args.run, verdicts)
return 0
return 1
if __name__ == "__main__":
sys.exit(main())