mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-30 13:28:51 -06:00
refactor: break the scraper import cycles
This commit is contained in:
1 parent
2b3551dd22
commit
a81c497e8d
19 files changed
+921
-860
No files matched your search
@@ -27,12 +27,9 @@ Verification (batocera-systems at the release tag):
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import shlex
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
from model.safeparse import yaml_load_upstream
|
||||
|
||||
from .base_scraper import BaseScraper, BiosRequirement, fetch_github_latest_version
|
||||
from .batocera_scraper import (
|
||||
SYSTEM_SLUG_MAP as BATOCERA_SLUGS,
|
||||
@@ -45,21 +42,27 @@ from .batocera_scraper import (
|
||||
)
|
||||
from .emuelec_launchers import extract_launchers
|
||||
from .es_emulators import (
|
||||
SystemEmulators,
|
||||
attach_system_cores,
|
||||
es_cores,
|
||||
json_systems,
|
||||
system_cores,
|
||||
)
|
||||
from scraper.shell_launchers import RepoTree
|
||||
from .emuelec_systems import (
|
||||
BUILDS_OF,
|
||||
ES_SYSTEMS_TEMPLATE,
|
||||
PORTS_TEMPLATE,
|
||||
RUNNERS,
|
||||
_RAW,
|
||||
port_engines,
|
||||
with_ports,
|
||||
)
|
||||
from .targets.emuelec_targets_scraper import Scraper as DeviceTargets
|
||||
|
||||
PLATFORM_NAME = "emuelec"
|
||||
|
||||
REPO = "EmuELEC/EmuELEC"
|
||||
_RAW = "https://raw.githubusercontent.com/EmuELEC/EmuELEC/{ref}/"
|
||||
SOURCE_TEMPLATE = _RAW + "packages/sx05re/emuelec/bin/batocera/batocera-systems"
|
||||
ES_SYSTEMS_TEMPLATE = _RAW + "packages/sx05re/emuelec-emulationstation/config/es_systems.json"
|
||||
PORTS_TEMPLATE = _RAW + "packages/sx05re/emuelec-ports/sources/ports.yaml"
|
||||
|
||||
# Batocera's names, plus the keys EmuELEC writes that Batocera does not:
|
||||
# console keys under the slug the other scrapers give them, and each port
|
||||
@@ -92,35 +95,6 @@ SYSTEM_SLUG_MAP = {
|
||||
"RigelEngine": "duke-nukem-2",
|
||||
}
|
||||
|
||||
# es_systems.json names libretro cores under `libretro`, and `retrorun`
|
||||
# loads the libretro core it lists. emuelecRunEmu.sh:101-116 turns either
|
||||
# into ${CORE}_libretro. Any other emulator runs the core it names
|
||||
# (EMU="${CORE}", line 107) through the case at lines 164-353.
|
||||
RUNNERS: dict[str, str | None] = {"libretro": None, "retrorun": None}
|
||||
|
||||
# A standalone emulator and the libretro core of the same emulator, from the
|
||||
# packages each one builds (packages/sx05re/emulators/<pkg>/package.mk
|
||||
# PKG_SITE): hatarisa hatari/hatari, stellasa stella-emu/stella, fbneoSA
|
||||
# finalburnneo/FBNeo, flycastsa flyinghead/flycast, scummvmsa
|
||||
# scummvm/scummvm, PPSSPPSDL hrydgard/ppsspp.
|
||||
BUILDS_OF = {
|
||||
"HATARISA": "hatari",
|
||||
"STELLASA": "stella",
|
||||
"FBNEOSA": "fbneo",
|
||||
"flycastsa": "flycast",
|
||||
"SCUMMVMSA": "scummvm",
|
||||
"PPSSPPSDL": "ppsspp",
|
||||
}
|
||||
|
||||
# The ES system `ports` (es_systems.json:2570-2590) runs one generated
|
||||
# script per entry of ports.yaml through emuelecRunApp.sh:22, and its single
|
||||
# emulator `ports` is that dispatch, not a program. The scripts are rendered
|
||||
# from port.sh.j2 by port_builder.py (emuelec-ports/package.mk:62-64): each
|
||||
# runs its `commands`, so the engine is the libretro core a command hands
|
||||
# emuelecRunEmu.sh with -C (lines 367-369 load <core>_libretro.so), or the
|
||||
# program `port_exe` names.
|
||||
PORTS_SYSTEM = "ports"
|
||||
|
||||
|
||||
def launcher_revision(url: str) -> str:
|
||||
"""The tag or commit a batocera-systems URL is read at."""
|
||||
@@ -130,45 +104,6 @@ def launcher_revision(url: str) -> str:
|
||||
return found.group(1)
|
||||
|
||||
|
||||
def port_engines(text: str) -> list[tuple[str, str, str | None, bool]]:
|
||||
"""(port, engine, check_bios key, libretro?) for each entry of ports.yaml.
|
||||
|
||||
The engine is written as the OS writes it: the libretro core a command
|
||||
hands emuelecRunEmu.sh with -C, else `port_exe`. `check_bios` is the
|
||||
batocera-systems key the script hands ee_check_bios on a failed start
|
||||
(port.sh.j2:23-25), the key the port's files are listed under.
|
||||
"""
|
||||
data = yaml_load_upstream(text)
|
||||
if not isinstance(data, dict) or not data:
|
||||
raise ValueError("ports.yaml names no port")
|
||||
engines = []
|
||||
for port, spec in data.items():
|
||||
core = None
|
||||
for command in map(str, spec.get("commands") or []):
|
||||
if "emuelecRunEmu.sh" in command:
|
||||
core = next(
|
||||
(w[2:] for w in shlex.split(command) if w.startswith("-C")), core
|
||||
)
|
||||
engine = core or spec.get("port_exe")
|
||||
if not engine:
|
||||
raise ValueError(f"ports.yaml: {port} names neither a core nor port_exe")
|
||||
engines.append((str(port), str(engine), spec.get("check_bios"), core is not None))
|
||||
return engines
|
||||
|
||||
|
||||
def with_ports(
|
||||
systems: SystemEmulators, engines: list[tuple[str, str, str | None, bool]]
|
||||
) -> SystemEmulators:
|
||||
"""The ES systems, each port engine filed under `ports` and its own key."""
|
||||
def entry(engine: str, libretro: bool) -> tuple[str, list[str]]:
|
||||
return ("libretro", [engine]) if libretro else (engine, [engine])
|
||||
|
||||
result = {**systems, PORTS_SYSTEM: [entry(e, lr) for _, e, _, lr in engines]}
|
||||
for _, engine, key, libretro in engines:
|
||||
if key:
|
||||
result[key] = [*result.get(key, []), entry(engine, libretro)]
|
||||
return result
|
||||
|
||||
class Scraper(BaseScraper):
|
||||
"""Scraper for EmuELEC's batocera-systems."""
|
||||
|
||||
@@ -249,7 +184,6 @@ class Scraper(BaseScraper):
|
||||
engines depend on emuelec-ports, which no package of an image
|
||||
depends on, and flycast-dojo is in no device list (UNBUILT there).
|
||||
"""
|
||||
from .targets.emuelec_targets_scraper import Scraper as DeviceTargets
|
||||
targets = DeviceTargets().device_targets(self.tag)["targets"]
|
||||
return {name for entry in targets.values() for name in entry["cores"]}
|
||||
|
||||
|
||||
Reference in new issue
Block a user