refactor: move ten command helpers into packages

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 15:47:20 +01:00
1 parent 6d21a98342
commit 19681a3735
22 files changed
+218 -191

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
"""The pages a deploy changes, as the request body IndexNow takes."""
from __future__ import annotations
import json
from core import upstream
from sitegen.agents import INDEXNOW_FILE, INDEXNOW_KEY, SITE
HOST = "abdess.github.io"
# What one IndexNow request accepts.
MAX_URLS = 10_000
USER_AGENT = "retrobios-indexnow"
def live_digests(url: str = f"{SITE}digests.json") -> dict[str, str]:
"""The digests the live site serves. None yet (the first deploy that
writes them) is an empty map: every page is new."""
body = upstream.fetch_body(url, timeout=60, user_agent=USER_AGENT)
return {} if body is None else json.loads(body.decode("utf-8"))
def changed_urls(new: dict[str, str], old: dict[str, str]) -> list[str]:
"""Pages added, changed or removed between two digest maps."""
return sorted(url for url in new.keys() | old.keys() if new.get(url) != old.get(url))
def payload(urls: list[str]) -> dict:
if len(urls) > MAX_URLS:
raise SystemExit(f"error: {len(urls)} changed pages, one request takes {MAX_URLS}")
return {"host": HOST, "key": INDEXNOW_KEY, "keyLocation": f"{SITE}{INDEXNOW_FILE}",
"urlList": urls}
+44
View File
@@ -0,0 +1,44 @@
"""The lines of a verify run that wiki/reading-reports.md quotes."""
from __future__ import annotations
import re
import subprocess
import sys
from core.paths import REPO_ROOT
PAGE = REPO_ROOT / "wiki" / "reading-reports.md"
BLOCK = re.compile(
r"(<!-- generated: verify-retrodeck -->\n```\n)(.*?)(```\n<!-- /generated: verify-retrodeck -->)",
re.S)
# The count lines, in the order verify prints them.
COUNTS = (" Core files:", " Bundled with their emulator", " Core files held",
" Game data:", " Game data held", " Launcher reads", " Launcher records",
" No external files:", " Ground truth:", " ")
def excerpt(lines: list[str]) -> list[str]:
"""The lines of a verify run the page shows."""
kept = [lines[0]]
untested = next((line for line in lines if line.startswith(" UNTESTED")), None)
if untested:
kept.append(untested)
for index, line in enumerate(lines):
if line.startswith(" DISCREPANCY") and index + 1 < len(lines) \
and lines[index + 1].startswith(" "):
kept += [line, lines[index + 1]]
break
counts_from = next(i for i, line in enumerate(lines) if line.startswith(" Core files:"))
kept += [line for line in lines[counts_from:] if line.startswith(COUNTS)]
return kept
def run() -> list[str]:
proc = subprocess.run([sys.executable, str(REPO_ROOT / "scripts" / "verify.py"),
"--platform", "retrodeck"], capture_output=True, text=True,
cwd=REPO_ROOT, check=False)
lines = proc.stdout.splitlines()
if not lines or not lines[0].startswith("RetroDECK:"):
raise SystemExit(f"verify did not run: {proc.stderr[-300:]}")
return lines