"""ES-DE: es_systems.xml with the alternative emulators and the commands an installer writes over it.""" from __future__ import annotations import re import shlex from collections.abc import Iterator from model.romfolders import format_ref from model.safeparse import parse_untrusted_xml from . import Fetcher, SourceError, register from .es import extension_list, first_lines, lenient_xml, folder_offers, strip_prefix # --------------------------------------------------------------------------- # ES-DE (EmuDeck, RetroDECK) _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]: match = _RA_CORE.search(command) if match: return "retroarch", match.group(1) match = _EMULATOR.search(command) if match: name = match.group(1).lower() return name, name return None, None 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() rom_path = (system.findtext("path") or "").strip() commands = [((c.get("label") or "").strip(), (c.text or "").strip()) for c in system.findall("command")] yield name, rom_path, extension_list(system.findtext("extension")), commands def _alternative_emulators(text: str, function: str) -> dict[str, tuple[str, int]]: """`ESDE_setEmu '