diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index 0912677ea..7375418c5 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -23,6 +23,7 @@ on: - "scripts/core/paths.py" - "scripts/core/romdir.py" - "scripts/core/sect233r1.py" + - "scripts/core/torrentzip.py" - "scripts/core/ziptools.py" - "scripts/cross_reference.py" - "scripts/dedup.py" @@ -34,6 +35,7 @@ on: - "scripts/indexnow.py" - "scripts/manifestselect.py" - "scripts/measurement_records.py" + - "scripts/model/__init__.py" - "scripts/model/alternatives.py" - "scripts/model/cliargs.py" - "scripts/model/composition.py" @@ -43,7 +45,9 @@ on: - "scripts/model/largefiles.py" - "scripts/model/platforms.py" - "scripts/model/profiles.py" + - "scripts/model/region.py" - "scripts/model/registry.py" + - "scripts/model/retired.py" - "scripts/model/safeparse.py" - "scripts/model/sources.py" - "scripts/model/systems.py" @@ -56,7 +60,6 @@ on: - "scripts/pr_checks.py" - "scripts/provenance_report.py" - "scripts/refresh_data_dirs.py" - - "scripts/region.py" - "scripts/release_record.py" - "scripts/resolve/__init__.py" - "scripts/resolve/archives.py" @@ -68,22 +71,20 @@ on: - "scripts/resolve/directories.py" - "scripts/resolve/gamedata.py" - "scripts/resolve/grouping.py" + - "scripts/resolve/launcherrefs.py" - "scripts/resolve/launchers.py" - "scripts/resolve/layout.py" - "scripts/resolve/localfile.py" - "scripts/resolve/nativemode.py" - "scripts/resolve/ownership.py" - "scripts/resolve/reconcile.py" + - "scripts/resolve/regions.py" - "scripts/resolve/slot.py" - "scripts/resolve/standalone.py" - "scripts/resolve/truth.py" - "scripts/resolve/validation.py" - "scripts/restore_large_files.py" - - "scripts/retired_files.py" - "scripts/romset_recipes.py" - - "scripts/scraper/base_scraper.py" - - "scripts/scraper/configgen_launchers.py" - - "scripts/scraper/shell_launchers.py" - "scripts/site_markdown.py" - "scripts/siteagents.py" - "scripts/sitebootstrap.py" @@ -105,7 +106,6 @@ on: - "scripts/slots.py" - "scripts/sourceref.py" - "scripts/split_pack.py" - - "scripts/torrentzip.py" - "scripts/upstream.py" - "scripts/validate_pr.py" - "scripts/validate_schemas.py" diff --git a/scripts/cross_reference.py b/scripts/cross_reference.py index 87cfb7038..ea4702f46 100644 --- a/scripts/cross_reference.py +++ b/scripts/cross_reference.py @@ -27,7 +27,8 @@ from typing import TYPE_CHECKING, TypedDict sys.path.insert(0, os.path.dirname(__file__)) from model.alternatives import set_keys, set_requirements, settle_sets -from resolve.layout import OUTER_ROOTS, system_dir_path +from model.declarations import OUTER_ROOTS +from resolve.layout import system_dir_path from model.cliargs import platform_arg, list_emulator_profiles, require_platform from model.profiles import ProfileSelectionError, load_emulator_profiles, select_emulator_profiles from resolve.ownership import _foreign_tree, _owner_tokens diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index daab4f2df..d8aab72b4 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -40,7 +40,8 @@ from typing import TYPE_CHECKING, TypedDict sys.path.insert(0, os.path.dirname(__file__)) from model.alternatives import core_file_spares, settle_sets, slot_set_keys from resolve.cores import resolve_platform_cores as _platform_cores -from resolve.layout import ROMS_ROOT, OUTER_ROOTS, outer_layout, core_system_dirs +from model.declarations import ROMS_ROOT, OUTER_ROOTS, outer_layout +from resolve.layout import core_system_dirs from resolve.contentlayout import TARGET_KEY, _core_key, content_folder_boards from model.profiles import ( installed_data_refs, diff --git a/scripts/model/declarations.py b/scripts/model/declarations.py index 2da8f9ed1..b60d3f227 100644 --- a/scripts/model/declarations.py +++ b/scripts/model/declarations.py @@ -2,6 +2,7 @@ from __future__ import annotations +import os from collections import Counter from core.paths import sanitize_pack_path @@ -143,3 +144,54 @@ def merged_platform_declarations( def expand_platform_declared_names(config: dict, db: dict) -> set[str]: """The names a platform declares, enriched as `platform_declarations`.""" return set(platform_declarations(config, db)) + + +# The entry root of a file read below the platform's roms directory, and of +# one read in an emulator's folder outside the BIOS tree that the registry +# describes. Each is located by the registry entry _directory. +ROMS_ROOT = "roms" +EMULATORS_ROOT = "emulators" +CONFIGS_ROOT = "configs" +OUTER_ROOTS = (ROMS_ROOT, EMULATORS_ROOT, CONFIGS_ROOT) + + +def outer_layout(config: dict, root: str) -> dict | None: + """Where a platform keeps the folder an outer root names, or None. + + roms: the roms root its rom folders file records (``path``, the OS's + spelling, and ``from_bios``, relative to the BIOS folder), with the + BIOS folder's own name, base_destination, that a run's folder must + carry before ``from_bios`` is followed from it. emulators: the + registry's ``emulators_directory``, the folders a launcher searches + for an emulator by key, which no rom folders file describes. + """ + if root == ROMS_ROOT: + found = config.get("_roms_root") or {} + base = str(config.get("base_destination") or "") + path, relation = found.get("path"), found.get("from_bios") + if not (path and relation) or "<" in str(path): + return None + if base: + return {"path": str(path), "from_bios": str(relation), "bios_folder": base} + # A list whose dests start above the BIOS folder (AmberELEC's + # bios/...) installs into the folder holding it: a roms root there + # or below is part of the install tree, written as a plain dest. + declared = declared_root(config) + if not declared: + return None + inside = os.path.normpath(f"{declared}/{relation}") + if inside == ".." or inside.startswith("../"): + return None + return {"path": str(path), "install_prefix": "" if inside == "." else inside} + if root == EMULATORS_ROOT: + return config.get("emulators_directory") or None + if root == CONFIGS_ROOT: + # The frontend's configs folder, as its path code builds it + # (configs_root, Batocera's batoceraPaths CONFIGS). + found = config.get("configs_root") or {} + base = str(config.get("base_destination") or "") + if not (found.get("path") and found.get("from_bios") and base): + return None + return {"path": str(found["path"]), "from_bios": str(found["from_bios"]), + "bios_folder": base} + return None diff --git a/scripts/packextras.py b/scripts/packextras.py index 716c42cac..6731659c2 100644 --- a/scripts/packextras.py +++ b/scripts/packextras.py @@ -22,7 +22,7 @@ from resolve.cores import resolve_platform_cores from resolve.layout import core_system_dirs, system_dir_path from resolve.standalone import platform_layouts from resolve.standalone import standalone_set as platform_standalone_set -from resolve.layout import OUTER_ROOTS, outer_layout +from model.declarations import OUTER_ROOTS, outer_layout from core.paths import sanitize_pack_path from resolve.content import declares_shape, shape_fits, size_fits from resolve.validation import deliverable, read_from_save_dir, read_from_system_dir diff --git a/scripts/resolve/contentlayout.py b/scripts/resolve/contentlayout.py index b9178ab1a..6edae408c 100644 --- a/scripts/resolve/contentlayout.py +++ b/scripts/resolve/contentlayout.py @@ -13,12 +13,11 @@ from resolve.layout import ( CONTENT_SYSTEM_TAG, CONTENT_TAG_PREFIXES, OUTSIDE_BIOS_FOLDER, - ROMS_ROOT, ROM_SEARCH_PREFIX, _placed_entry, - outer_layout, standalone_layout_path, ) +from model.declarations import ROMS_ROOT, outer_layout from core.paths import REPO_ROOT diff --git a/scripts/resolve/launchers.py b/scripts/resolve/launchers.py index a4ba962c4..648d9068c 100644 --- a/scripts/resolve/launchers.py +++ b/scripts/resolve/launchers.py @@ -20,7 +20,7 @@ import re from collections.abc import Callable, Iterable, Mapping from dataclasses import dataclass -from model.declarations import declared_root +from model.declarations import CONFIGS_ROOT, ROMS_ROOT, declared_root, outer_layout from resolve.content import name_match_size_ok from resolve.localfile import resolve_local_file from core.paths import sanitize_pack_path @@ -898,8 +898,6 @@ def _roms_place(config: dict, path: str | None) -> Place | None: platform installs above its BIOS folder (AmberELEC), else the roms tree.""" if path is None: return None - from resolve.layout import ROMS_ROOT, outer_layout - layout = outer_layout(config, ROMS_ROOT) or {} if "install_prefix" in layout: prefix = layout["install_prefix"] @@ -914,8 +912,6 @@ def folder_in_configs(directory: str, config: dict) -> str | None: (``configs_root.path``): Batocera's /userdata/system/configs, where its generators start shadPS4 from configs/shadps4. """ - from resolve.layout import CONFIGS_ROOT - return folder_in_root(directory, config, CONFIGS_ROOT) @@ -926,8 +922,6 @@ def folder_in_roms(directory: str, config: dict) -> str | None: (``roms_root.path``): ROCKNIX's /storage/roms, which holds its BIOS folder and the folders its launchers run programs from. """ - from resolve.layout import ROMS_ROOT, outer_layout - spelled = directory.strip().rstrip("/") for variable in ROMS_ROOT_VARIABLES: if outer_layout(config, ROMS_ROOT) and ( @@ -940,8 +934,6 @@ def folder_in_roms(directory: str, config: dict) -> str | None: def folder_in_root(directory: str, config: dict, root: str) -> str | None: """A directory relative to an outer root's path, None outside it.""" - from resolve.layout import outer_layout - roms = str((outer_layout(config, root) or {}).get("path") or "").rstrip("/") directory = directory.strip().rstrip("/") if not roms or not directory.startswith(roms + "/"): diff --git a/scripts/resolve/layout.py b/scripts/resolve/layout.py index b7d53fcf6..d5db226f6 100644 --- a/scripts/resolve/layout.py +++ b/scripts/resolve/layout.py @@ -3,10 +3,8 @@ from __future__ import annotations import json -import os from collections.abc import Iterable, Mapping -from model.declarations import declared_root def runs_standalone( @@ -188,55 +186,6 @@ def _executed(standalone_cores: Iterable[str]) -> list: # Why a standalone entry has no destination on a platform that relocates its # layout: the manifest's omission reason, named as the installer words it. OUTSIDE_BIOS_FOLDER = "outside_bios_folder" -# The entry root of a file read below the platform's roms directory, and of -# one read in an emulator's folder outside the BIOS tree that the registry -# describes. Each is located by the registry entry _directory. -ROMS_ROOT = "roms" -EMULATORS_ROOT = "emulators" -CONFIGS_ROOT = "configs" -OUTER_ROOTS = (ROMS_ROOT, EMULATORS_ROOT, CONFIGS_ROOT) - - -def outer_layout(config: dict, root: str) -> dict | None: - """Where a platform keeps the folder an outer root names, or None. - - roms: the roms root its rom folders file records (``path``, the OS's - spelling, and ``from_bios``, relative to the BIOS folder), with the - BIOS folder's own name, base_destination, that a run's folder must - carry before ``from_bios`` is followed from it. emulators: the - registry's ``emulators_directory``, the folders a launcher searches - for an emulator by key, which no rom folders file describes. - """ - if root == ROMS_ROOT: - found = config.get("_roms_root") or {} - base = str(config.get("base_destination") or "") - path, relation = found.get("path"), found.get("from_bios") - if not (path and relation) or "<" in str(path): - return None - if base: - return {"path": str(path), "from_bios": str(relation), "bios_folder": base} - # A list whose dests start above the BIOS folder (AmberELEC's - # bios/...) installs into the folder holding it: a roms root there - # or below is part of the install tree, written as a plain dest. - declared = declared_root(config) - if not declared: - return None - inside = os.path.normpath(f"{declared}/{relation}") - if inside == ".." or inside.startswith("../"): - return None - return {"path": str(path), "install_prefix": "" if inside == "." else inside} - if root == EMULATORS_ROOT: - return config.get("emulators_directory") or None - if root == CONFIGS_ROOT: - # The frontend's configs folder, as its path code builds it - # (configs_root, Batocera's batoceraPaths CONFIGS). - found = config.get("configs_root") or {} - base = str(config.get("base_destination") or "") - if not (found.get("path") and found.get("from_bios") and base): - return None - return {"path": str(found["path"]), "from_bios": str(found["from_bios"]), - "bios_folder": base} - return None def standalone_layout_path(entry: dict, profile: dict) -> str | None: diff --git a/scripts/resolve/truth.py b/scripts/resolve/truth.py index eed1018fe..0465d7b10 100644 --- a/scripts/resolve/truth.py +++ b/scripts/resolve/truth.py @@ -11,7 +11,7 @@ import os import sys from dataclasses import dataclass -from resolve.layout import OUTER_ROOTS +from model.declarations import OUTER_ROOTS from model.systems import _norm_system_id from model.registry import load_data_dir_registry from resolve.standalone import platform_layouts, standalone_set as platform_standalone_set diff --git a/scripts/verify.py b/scripts/verify.py index db85cf144..7529844cd 100644 --- a/scripts/verify.py +++ b/scripts/verify.py @@ -54,7 +54,8 @@ from model.targets import ( list_available_targets, build_target_cores_cache, ) -from resolve.layout import OUTER_ROOTS, runs_standalone, system_dir_path +from model.declarations import OUTER_ROOTS +from resolve.layout import runs_standalone, system_dir_path from resolve.ownership import _foreign_tree, _owner_tokens from model.cliargs import ( platform_arg,