Files
pokemon/scripts/update_swarm/librarian.py
T

43 lines
1.7 KiB
Python

from __future__ import annotations
import os, sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import enrich_vault as E
import enrich_web as W
ROMM_PLATFORM_IDS = {"GBA": 72, "PC": 200, "windows": 200}
def require_platform_id(platform: str) -> int:
if platform not in ROMM_PLATFORM_IDS:
raise KeyError(f"no RomM platform_id for {platform!r}; add it to ROMM_PLATFORM_IDS")
return ROMM_PLATFORM_IDS[platform]
def superseded_name(live_basename: str, old_version: str) -> str:
root, ext = os.path.splitext(live_basename)
return f"{root} ({old_version}){ext}"
def romm_scan_argv(platform_ids: list[int]) -> list[str]:
if not platform_ids:
raise ValueError("platform_ids is required; refusing a full-library walk")
ids = "[" + ", ".join(str(i) for i in platform_ids) + "]"
py = (
"import asyncio; from endpoints.sockets.scan import scan_platforms; "
"from handler.scan_handler import ScanType; "
f"asyncio.run(scan_platforms(platform_ids={ids}, metadata_sources=[], scan_type=ScanType.QUICK))"
)
return ["docker", "exec", "-w", "/backend", "romm", "python3", "-c", py]
def patch_note(path: str, version: str, release_date: str | None,
source_url: str | None, history_md: str | None, status: str | None) -> str:
fm_text, body, _ = E.read_note(path)
fm = E.parse_fm(fm_text)
fm["version"] = version
if release_date:
fm["release_date"] = release_date
if source_url:
fm["source"] = source_url
if status:
fm["status"] = status
if history_md:
body = W.set_section(body, "Version history", history_md.strip())
return f"---\n{E.emit_fm(fm)}\n---\n{body}"