refactor: share scraper and launcher helpers

BaseScraper reads JSON once (_fetch_json, json_object), every scraper files its requirements through systems_from_requirements, and the batocera-systems readers (Batocera, KNULLI, AmberELEC, EmuELEC) inherit CheckBiosScraper. Launcher modules share one Launcher record, one LauncherPatternMissing and one link_record. DAT importers build provenance entries from LogiqxDat.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 18:28:33 +01:00
1 parent ac16875c5b
commit 7cd499531d
27 files changed
+256 -360

No files matched your search

+26 -8
View File
@@ -18,7 +18,7 @@ from dataclasses import dataclass, field
from model.sourceref import span
from .base_scraper import fetch_bytes, github_headers
from .configgen_launchers import LauncherShapeError
from .configgen_launchers import Launcher, LauncherPatternMissing
NAME = r"[A-Za-z_][A-Za-z0-9_]*"
# A single-quoted "$" is literal: it is carried as this mark through expansion.
@@ -28,13 +28,6 @@ LITERAL_DOLLAR = "\x00"
LOOP_MARK = "\x01"
class LauncherPatternMissing(LauncherShapeError):
"""A construct an extractor reads is absent from the launcher source."""
def __init__(self, path: str, what: str) -> None:
super().__init__(f"{path}: {what} not found")
def merge_lines(lines: Iterable[int]) -> list[tuple[int, int]]:
"""Line numbers as sorted spans, a gap of one line joined."""
spans: list[tuple[int, int]] = []
@@ -377,6 +370,31 @@ class Script:
return _merge_links(found)
def link_record(
emulator: str,
script: Script,
link: Link,
*,
guard_lines: Iterable[int] = (),
case_insensitive: bool | None = None,
fails_when_missing: bool | str | None = False,
) -> Launcher:
"""The record of an ln -s a script makes under the BIOS root,
citing the guard lines the link waits for beside its own."""
return Launcher(
emulator=emulator,
build="standalone",
kind="links",
names=list(link.names),
source_ref=source_ref([(script.path, link.lines | set(guard_lines))]),
expands=link.expands or None,
search_dir=link.bios_side,
passes_to=f"symlink {link.link} -> {link.target}",
case_insensitive=case_insensitive,
fails_when_missing=fails_when_missing,
)
def _under(path: str, root: str) -> bool:
return path.rstrip("/") == root.rstrip("/") or path.startswith(root.rstrip("/") + "/")