refactor: read retropie module fields in one place

rp_registerModule sources the script: the id, section, flags and repo
are top-level assignments, the last one wins. The platform, target,
launcher, rom folder and export readers each kept their own pattern;
they now share module_fields. Same ids and flags over the 287
scriptmodules at 427e7621.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 16:43:46 +01:00
1 parent 24463647f6
commit 12b00e024b
6 files changed
+40 -39

No files matched your search

+21 -1
View File
@@ -1,9 +1,15 @@
"""Which RetroPie scriptmodules a platform enables, as RetroPie-Setup decides."""
"""How RetroPie-Setup reads a scriptmodule: the fields it declares, the platforms that enable it."""
from __future__ import annotations
import re
from collections.abc import Iterable
# scriptmodules/packages.sh rp_registerModule sources the script, so a
# top-level assignment sets the field and the last one wins. RetroPie writes
# each at the start of a line, in double quotes.
_MODULE_FIELD = re.compile(r'^rp_module_(id|section|flags|repo)="([^"]*)"', re.MULTILINE)
# scriptmodules/system.sh: set_platform_defaults starts each platform's flags
# with its own name and getconf LONG_BIT (`x86_64`, `64bit`), then the cpu_*
# and platform_* functions add theirs. A PC takes platform_native, which adds
@@ -25,6 +31,20 @@ PLATFORM_FLAGS: dict[str, set[str]] = {
}
def module_field_lines(text: str) -> dict[str, tuple[str, int]]:
"""(value, line) of the id, section, flags and repo a scriptmodule
declares, by field name."""
return {
found.group(1): (found.group(2), text.count("\n", 0, found.start()) + 1)
for found in _MODULE_FIELD.finditer(text)
}
def module_fields(text: str) -> dict[str, str]:
"""The id, section, flags and repo a scriptmodule declares, by field name."""
return dict(_MODULE_FIELD.findall(text))
def module_enabled(flags: Iterable[str], platform_flags: set[str]) -> bool:
"""Whether RetroPie enables a module whose rp_module_flags are `flags`.