From b80fc1919d11a6cc6b4e74c57bb6ad3668235ead Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 04:31:11 +0100 Subject: [PATCH] refactor: read es-de commands through romfolders --- scripts/scraper/retrodeck_scraper.py | 19 ++++++++----------- scripts/scraper/romfolders/es.py | 10 +++++----- tests/test_save_root.py | 3 ++- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/scripts/scraper/retrodeck_scraper.py b/scripts/scraper/retrodeck_scraper.py index f5f11bfe2..f2ffa101b 100644 --- a/scripts/scraper/retrodeck_scraper.py +++ b/scripts/scraper/retrodeck_scraper.py @@ -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/, the system's 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())} diff --git a/scripts/scraper/romfolders/es.py b/scripts/scraper/romfolders/es.py index b30c96418..893f7da23 100644 --- a/scripts/scraper/romfolders/es.py +++ b/scripts/scraper/romfolders/es.py @@ -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"([^<]+)") 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: diff --git a/tests/test_save_root.py b/tests/test_save_root.py index 9a3313c58..1552e8ab8 100644 --- a/tests/test_save_root.py +++ b/tests/test_save_root.py @@ -839,7 +839,8 @@ class TheScrapersReadTheSystemLists(unittest.TestCase): "%EMULATOR_AZAHAR% %ROM%" "%EMULATOR_RETROARCH% -L " "%CORE_RETROARCH%/citra_libretro.so %ROM%" - "" + "" "" ) self.assertEqual(es_systems_libretro_systems(text), {"citra": ["n3ds"]})