mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 02:57:52 -06:00
refactor: read data dirs and inherits in one place
This commit is contained in:
1 parent
7be8a7cd7b
commit
67cb99606d
12 files changed
+73
-61
No files matched your search
@@ -48,6 +48,23 @@ def _inherited_yaml(platform_name: str, platforms_dir: str) -> tuple[dict, list[
|
||||
return merged, [platform_name, *chain]
|
||||
|
||||
|
||||
def inheritance_chain(platform: str, platforms_dir: str | os.PathLike[str]) -> list[str]:
|
||||
"""The platform and every platform its file inherits from, nearest first.
|
||||
|
||||
Stops at a file that does not exist or at a name already walked.
|
||||
"""
|
||||
chain: list[str] = []
|
||||
name: str | None = platform
|
||||
while name and name not in chain:
|
||||
path = os.path.join(platforms_dir, f"{name}.yml")
|
||||
if not os.path.isfile(path):
|
||||
break
|
||||
chain.append(name)
|
||||
inherits = (source_yaml_file(path) or {}).get("inherits")
|
||||
name = str(inherits) if inherits else None
|
||||
return chain
|
||||
|
||||
|
||||
def _cached_platform_yaml(path: str) -> dict:
|
||||
"""A registry or shared-group file, parsed once per real path."""
|
||||
real = os.path.realpath(path)
|
||||
|
||||
@@ -11,13 +11,22 @@ from core.cli import InputMissing
|
||||
from model.sources import source_yaml_file
|
||||
|
||||
|
||||
def load_data_dir_registry(platforms_dir: str = PLATFORMS_DIR) -> dict:
|
||||
"""Load the data directory registry from _data_dirs.yml."""
|
||||
registry_path = os.path.join(platforms_dir, "_data_dirs.yml")
|
||||
def data_dir_registry_at(registry_path: str | os.PathLike[str], required: bool = False) -> dict:
|
||||
"""The `data_directories:` mapping of a data directory registry file.
|
||||
|
||||
An absent file is an empty registry, or with ``required`` an input the
|
||||
command cannot run without.
|
||||
"""
|
||||
if not os.path.exists(registry_path):
|
||||
if required:
|
||||
raise InputMissing(f"Registry not found: {registry_path}")
|
||||
return {}
|
||||
data = source_yaml_file(registry_path) or {}
|
||||
return data.get("data_directories", {})
|
||||
return (source_yaml_file(registry_path) or {}).get("data_directories") or {}
|
||||
|
||||
|
||||
def load_data_dir_registry(platforms_dir: str | Path = PLATFORMS_DIR, required: bool = False) -> dict:
|
||||
"""Load the data directory registry from _data_dirs.yml."""
|
||||
return data_dir_registry_at(os.path.join(platforms_dir, "_data_dirs.yml"), required)
|
||||
|
||||
|
||||
def load_platform_registry(platforms_dir: str | Path = PLATFORMS_DIR, required: bool = False) -> dict:
|
||||
|
||||
Reference in new issue
Block a user