mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
Each network job had several copies. One is kept per job and every caller uses it. - Source revision: model.sourcerevision (source_revision, required_revision, platform_revision) replaces BaseTargetScraper's pattern list, the exporter's _REVISION, the four launcher_revision copies and RetroBat's own YAML reader. It reads the union of the shapes: GitHub raw, blob and tree with or without a path after the revision, GitLab raw, blob, tree and archive, codeload tar.gz and zip. The target scrapers now answer for RetroDECK, NextUI, MinUI and MyMinUI, whose tree URLs end at the commit, and the exporter reads GitLab blob and tree and codeload zip. EmuDeck and RetroBat still require a 40-hex commit, and each launcher reader requires its own repository in the URL. - Latest release: fetch_github_latest_version, type-checked, is the only lookup. mame_hash_scraper, romset_dat_importer and the Lakka target scraper call it. romset_dat_importer's NoReleaseError is gone: a release without a tag raises RuntimeError. - Tree listing: github_tree and tree_entries refuse a truncated or unreadable listing. The libretro and core-info scrapers share core_info_files and fetch_info_file, with libretro's refusal of an empty listing. The core-info listing and the RetroDECK, ROCKNIX launcher and libretro listings were not checked for truncation before. - GET: fetch_bytes is the one request path. fetch_text, fetch_present (None on 404 only), github_json and download are built on it, so every read retries 429 and 5xx, caps the body and raises FetchError, a ConnectionError carrying the HTTP status. The target scrapers' own fetch_text raised RuntimeError: they now raise FetchError, and an optional Batocera board include is skipped on 404 only, not on any failure. The exporter's originals, MiSTer, RetroPie, redump and the buildbot index go through it too. - Headers: core.upstream.forge_headers is the one builder. The token goes to api.github.com and raw.githubusercontent.com, the host compared whole, as Bearer. A URL that only names api.github.com in its query got the scrapers' token before, and profile_sync sent its token to github.com, whose release downloads redirect to asset storage with the header. Scraper reads of raw files now carry the token. - Submodule commit: submodule_commit checks that the path is a submodule. Batocera's target scraper accepted any contents answer with a sha, a directory's tree sha included. - Download: download streams through a scratch file renamed into place, retries like fetch_bytes, can keep an existing file and returns the Content-Disposition. It replaces the _download of romset_dat_importer and game_dat_importer.
105 lines
3.8 KiB
Python
105 lines
3.8 KiB
Python
"""Scraper for Recalbox per-board emulator availability.
|
|
|
|
Sources (recalbox/recalbox on GitLab, at the tag platforms/recalbox.yml names):
|
|
- configs/recalbox-<board>_defconfig -- the Buildroot packages each image
|
|
enables, one `BR2_PACKAGE_<NAME>=y` line per emulator package
|
|
- package/recalbox-romfs2/systems/<system>/system.ini -- the cores of each
|
|
system, each `[core.N]` naming the package that builds it, with board
|
|
overrides (`package.<board>`, `[core.N.<board>]`)
|
|
|
|
Recalbox runs on Raspberry Pi 3 to 5, two handhelds and x86_64: without a
|
|
target list, a Pi 3 pack carried the firmware of emulators only x86_64 builds.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
import sys
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
from . import BaseTargetScraper, target_cli
|
|
from ..base_scraper import fetch_bytes, fetch_text
|
|
from ..recalbox_scraper import SYSTEMS_TREE_URL, Scraper as PlatformScraper, board_cores
|
|
|
|
PLATFORM_NAME = "recalbox"
|
|
|
|
CONFIGS_TREE_URL = (
|
|
"https://gitlab.com/api/v4/projects/recalbox%2Frecalbox/repository/tree"
|
|
"?path=configs&ref={tag}&per_page=100"
|
|
)
|
|
DEFCONFIG_URL = "https://gitlab.com/recalbox/recalbox/-/raw/{tag}/configs/{name}"
|
|
_DEFCONFIG_RE = re.compile(r"^recalbox-(\w+)_defconfig$")
|
|
_ENABLED_RE = re.compile(r"^(BR2_PACKAGE_\w+)=y\s*$", re.MULTILINE)
|
|
|
|
|
|
def enabled_packages(defconfig: str) -> set[str]:
|
|
"""The Buildroot packages a defconfig turns on."""
|
|
return set(_ENABLED_RE.findall(defconfig))
|
|
|
|
|
|
def defconfig_arch(defconfig: str) -> str:
|
|
"""The architecture a defconfig builds for, from its Buildroot arch symbol."""
|
|
for symbol, arch in (("BR2_x86_64", "x86_64"), ("BR2_aarch64", "aarch64"),
|
|
("BR2_arm", "armhf")):
|
|
if re.search(rf"^{symbol}=y\s*$", defconfig, re.MULTILINE):
|
|
return arch
|
|
raise RuntimeError("defconfig names no BR2_x86_64, BR2_aarch64 or BR2_arm")
|
|
|
|
|
|
class Scraper(BaseTargetScraper):
|
|
"""Per-board core lists from Recalbox's defconfigs and system.ini files."""
|
|
|
|
def __init__(self, url: str = "https://gitlab.com/recalbox/recalbox") -> None:
|
|
super().__init__(url=url)
|
|
|
|
def fetch_targets(self) -> dict:
|
|
tag = self.pinned_revision(PLATFORM_NAME)
|
|
platform = PlatformScraper(tag)
|
|
listing = json.loads(fetch_bytes(CONFIGS_TREE_URL.format(tag=tag)))
|
|
boards = {
|
|
match.group(1): item["name"]
|
|
for item in listing
|
|
if (match := _DEFCONFIG_RE.match(item.get("name", "")))
|
|
}
|
|
if not boards:
|
|
raise RuntimeError(f"no recalbox-*_defconfig in configs/ at {tag}")
|
|
|
|
systems: list[str] = []
|
|
page = 1
|
|
while True:
|
|
entries = json.loads(fetch_bytes(SYSTEMS_TREE_URL.format(tag=tag, page=page)))
|
|
systems += [e["name"] for e in entries
|
|
if e.get("type") == "tree" and not e["name"].startswith(".")]
|
|
if len(entries) < 100:
|
|
break
|
|
page += 1
|
|
inis = platform._system_inis(systems)
|
|
|
|
targets: dict[str, dict] = {}
|
|
for board, name in sorted(boards.items()):
|
|
defconfig = fetch_text(DEFCONFIG_URL.format(tag=tag, name=name))
|
|
enabled = enabled_packages(defconfig)
|
|
cores: set[str] = set()
|
|
for text in inis:
|
|
cores |= board_cores(text, board, enabled)
|
|
arch = defconfig_arch(defconfig)
|
|
targets[board] = {"architecture": arch, "cores": sorted(cores)}
|
|
print(f" {board} ({arch}): {len(cores)} cores", file=sys.stderr)
|
|
|
|
return {
|
|
"platform": PLATFORM_NAME,
|
|
"source": f"{self.url}/-/tree/{tag}/configs",
|
|
"scraped_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
"targets": targets,
|
|
}
|
|
|
|
|
|
def main() -> None:
|
|
target_cli(Scraper, "Scrape Recalbox per-board cores")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|