refactor: read es-de commands through romfolders

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:01:53 +01:00
1 parent 0548d3d823
commit b80fc1919d
3 files changed
+15 -17

No files matched your search

+8 -11
View File
@@ -54,6 +54,7 @@ from .base_scraper import (
systems_from_requirements,
)
from .retrodeck_launchers import extract_launchers
from .romfolders.es import command_core, esde_systems
PLATFORM_NAME = "retrodeck"
COMPONENTS_REPO = "RetroDECK/components"
@@ -67,7 +68,6 @@ ES_DE_SYSTEMS_URL = (
"https://raw.githubusercontent.com/" + ES_DE_REPO
+ "/{rev}/resources/systems/linux/es_systems.xml"
)
_RETROARCH_CORE = re.compile(r"%CORE_RETROARCH%/([\w.+-]+?)_libretro\.so")
def es_systems_libretro_systems(text: str) -> dict[str, list[str]]:
@@ -77,20 +77,17 @@ def es_systems_libretro_systems(text: str) -> dict[str, list[str]]:
(retroarch/rd_assets/rd_config/retroarch.cfg, sort_savefiles_by_content_enable
and sort_savefiles_enable): a core is handed saves/<folder holding the
ROM>, the system's <path> folder below %ROMPATH%. A commented-out
command is no element and counts for nothing.
command counts for nothing.
"""
from model.safeparse import parse_untrusted_xml
found: dict[str, set[str]] = {}
for system in parse_untrusted_xml(text, "es_systems.xml").iter("system"):
path = (system.findtext("path") or "").strip().replace("\\", "/")
folder = path.rstrip("/").rsplit("/", 1)[-1]
for _name, path, _extensions, commands in esde_systems(text, "es_systems.xml"):
folder = path.replace("\\", "/").rstrip("/").rsplit("/", 1)[-1]
if not folder or folder.startswith("%"):
continue
for command in system.iter("command"):
match = _RETROARCH_CORE.search(command.text or "")
if match:
found.setdefault(match.group(1), set()).add(folder)
for _label, command in commands:
emulator, core = command_core(command)
if emulator == "retroarch" and core:
found.setdefault(core, set()).add(folder)
return {core: sorted(folders) for core, folders in sorted(found.items())}
+5 -5
View File
@@ -546,7 +546,7 @@ _RA_CORE = re.compile(r"%CORE_RETROARCH%[/\\]([\w.+-]+?)_libretro")
_EMULATOR = re.compile(r"%EMULATOR_([A-Za-z0-9_-]+)%")
def _command_core(command: str) -> tuple[str | None, str | None]:
def command_core(command: str) -> tuple[str | None, str | None]:
match = _RA_CORE.search(command)
if match:
return "retroarch", match.group(1)
@@ -557,7 +557,7 @@ def _command_core(command: str) -> tuple[str | None, str | None]:
return None, None
def _esde_systems(text: str, path: str) -> Iterator[tuple[str, str, list[str], list[tuple[str, str]]]]:
def esde_systems(text: str, path: str) -> Iterator[tuple[str, str, list[str], list[tuple[str, str]]]]:
root = parse_untrusted_xml(_lenient_xml(text), path)
for system in root.iter("system"):
name = (system.findtext("name") or "").strip()
@@ -695,7 +695,7 @@ def esde(spec: dict, fetcher: Fetcher) -> list[dict]:
text = _lenient_xml(fetcher.text(key, path))
lines = _first_lines(text, r"<name>([^<]+)</name>")
command_lines = _command_lines(text)
for name, rom_path, extensions, commands in _esde_systems(text, path):
for name, rom_path, extensions, commands in esde_systems(text, path):
folder = _strip_prefix(rom_path, ["%ROMPATH%/", "%ROMPATH%\\"])
if not name or not folder:
continue
@@ -731,11 +731,11 @@ def esde(spec: dict, fetcher: Fetcher) -> list[dict]:
chosen = match
else:
note = f"alternative emulator '{label}' names no command of this system"
emulator, core = _command_core(chosen[1])
emulator, core = command_core(chosen[1])
offers = _offers([
{"emulator": e, "core": c, "source_ref": _ref(key_, path_, line)}
for _label, command, line, key_, path_ in system["placed"]
for e, c in [_command_core(command)] if e
for e, c in [command_core(command)] if e
], core, emulator)
extensions = system["extensions"]
if "." in extensions:
+2 -1
View File
@@ -839,7 +839,8 @@ class TheScrapersReadTheSystemLists(unittest.TestCase):
"<command label=\"Azahar (Standalone)\">%EMULATOR_AZAHAR% %ROM%</command>"
"<command label=\"Citra\">%EMULATOR_RETROARCH% -L "
"%CORE_RETROARCH%/citra_libretro.so %ROM%</command>"
"<!-- <command>%EMULATOR_RETROARCH% -L %CORE_RETROARCH%/x_libretro.so</command> -->"
"<!-- <command>%EMULATOR_RETROARCH% --verbose -L "
"%CORE_RETROARCH%/x_libretro.so</command> -->"
"</system></systemList>"
)
self.assertEqual(es_systems_libretro_systems(text), {"citra": ["n3ds"]})