mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 18:47:53 -06:00
refactor: one retropie package script selector
This commit is contained in:
1 parent
5a931ad4b1
commit
ff3b2699bd
3 files changed
+49
-19
No files matched your search
@@ -30,7 +30,7 @@ from collections.abc import Iterator
|
||||
|
||||
from .base_scraper import BaseScraper, BiosRequirement, fetch_branch_head, fetch_bytes
|
||||
from .retropie_launchers import SCRIPTMODULES
|
||||
from .retropie_launchers import SECTIONS as _SCRIPT_SECTIONS
|
||||
from .retropie_launchers import SECTIONS as PACKAGE_SECTIONS
|
||||
from .retropie_launchers import extract_launchers
|
||||
from .retropie_modules import module_fields
|
||||
|
||||
@@ -44,9 +44,20 @@ MAX_ARCHIVE = 64 * 1024 * 1024
|
||||
# SD image. The version a user runs is the one this script declares.
|
||||
_VERSION_FILE = "retropie_packages.sh"
|
||||
_VERSION = re.compile(r'^__version="([^"]+)"', re.MULTILINE)
|
||||
# Sections RetroPie does not build as emulators: setup helpers, themes,
|
||||
# drivers and the like carry no core.
|
||||
_PACKAGE_DIRS = _SCRIPT_SECTIONS
|
||||
|
||||
|
||||
def package_script(relative: str) -> str | None:
|
||||
"""section/filename of a package script, None for any other member.
|
||||
|
||||
Only the PACKAGE_SECTIONS hold packages: setup helpers, themes, drivers
|
||||
and the like carry no core. The platform and target scrapers both select
|
||||
scripts here, so a targeted pack never filters a package the platform
|
||||
list names.
|
||||
"""
|
||||
parts = relative.split("/")
|
||||
if len(parts) == 3 and parts[0] == SCRIPTMODULES and parts[1] in PACKAGE_SECTIONS:
|
||||
return f"{parts[1]}/{parts[2]}"
|
||||
return None
|
||||
|
||||
|
||||
def core_name(module_id: str) -> str:
|
||||
@@ -107,13 +118,9 @@ class Scraper(BaseScraper):
|
||||
for relative, text in script_members(raw):
|
||||
parts = relative.split("/")
|
||||
is_version_file = relative == _VERSION_FILE
|
||||
is_package = (
|
||||
len(parts) == 3
|
||||
and parts[0] == "scriptmodules"
|
||||
and parts[1] in _PACKAGE_DIRS
|
||||
)
|
||||
is_package = package_script(relative) is not None
|
||||
is_launch_script = (
|
||||
len(parts) == 4 and parts[0] == SCRIPTMODULES and parts[1] in _SCRIPT_SECTIONS
|
||||
len(parts) == 4 and parts[0] == SCRIPTMODULES and parts[1] in PACKAGE_SECTIONS
|
||||
)
|
||||
if is_package or is_launch_script:
|
||||
self._scripts[relative] = text
|
||||
|
||||
@@ -14,7 +14,14 @@ import tarfile
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from ..retropie_modules import PLATFORM_FLAGS, module_enabled, module_fields
|
||||
from ..retropie_scraper import SOURCE_URL, core_name, fetch_archive, script_members
|
||||
from ..retropie_scraper import (
|
||||
PACKAGE_SECTIONS,
|
||||
SOURCE_URL,
|
||||
core_name,
|
||||
fetch_archive,
|
||||
package_script,
|
||||
script_members,
|
||||
)
|
||||
from . import BaseTargetScraper, target_cli
|
||||
|
||||
PLATFORM_NAME = "retropie"
|
||||
@@ -23,9 +30,6 @@ PLATFORM_NAME = "retropie"
|
||||
GITHUB_API_URL = (
|
||||
"https://api.github.com/repos/RetroPie/RetroPie-Setup/contents/scriptmodules"
|
||||
)
|
||||
# The sections the platform scraper reads: a standalone package missing here
|
||||
# is filtered out of every targeted pack.
|
||||
PACKAGE_DIRS = ("emulators", "libretrocores", "ports")
|
||||
|
||||
ARCH_MAP: dict[str, str] = {
|
||||
"rpi1": "armv6",
|
||||
@@ -66,12 +70,11 @@ class Scraper(BaseTargetScraper):
|
||||
modules: dict[str, str] = {}
|
||||
try:
|
||||
for relative, text in script_members(_fetch_archive(url)):
|
||||
parts = relative.split("/")
|
||||
if len(parts) == 3 and parts[0] == "scriptmodules" and parts[1] in PACKAGE_DIRS:
|
||||
modules[f"{parts[1]}/{parts[2]}"] = text
|
||||
if name := package_script(relative):
|
||||
modules[name] = text
|
||||
except tarfile.TarError as exc:
|
||||
raise RuntimeError(f"{url}: {exc}") from exc
|
||||
for section in PACKAGE_DIRS:
|
||||
for section in PACKAGE_SECTIONS:
|
||||
if not any(name.startswith(f"{section}/") for name in modules):
|
||||
raise RuntimeError(f"no scriptmodules under {section}/ in {url}")
|
||||
return dict(sorted(modules.items()))
|
||||
|
||||
Reference in new issue
Block a user