mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-03 06:48:52 -06:00
refactor: one loader for the rom-folder sources
This commit is contained in:
1 parent
17c64914ef
commit
1631ad0f4d
7 files changed
+32
-35
No files matched your search
@@ -6,20 +6,11 @@ from pathlib import Path
|
||||
|
||||
from core import upstream
|
||||
from model.registry import load_platform_registry
|
||||
from model.romfolders import row_sources
|
||||
from model.sources import source_yaml_file
|
||||
from model.romfolders import load_sources, row_sources, sources_dir
|
||||
from model.sourcerevision import scraped_revision
|
||||
from freshness.findings import OK, SKIPPED, STALE, UNKNOWN, Finding
|
||||
|
||||
|
||||
def romfolder_sources(platforms_dir: Path) -> dict[str, dict]:
|
||||
"""setup -> its platforms/romfolders/_sources/<setup>.yml."""
|
||||
out = {}
|
||||
for path in sorted((platforms_dir / "romfolders" / "_sources").glob("*.yml")):
|
||||
out[path.stem] = source_yaml_file(path) or {}
|
||||
return out
|
||||
|
||||
|
||||
def watched_sources(doc: dict) -> list[str]:
|
||||
"""The declared sources whose pins are compared: the setup's own pin
|
||||
(`os`, else the first declared), then every source its rows are read
|
||||
@@ -73,7 +64,7 @@ def check_romfolders(platforms_dir: Path, cache_dir: str, offline: bool) -> list
|
||||
"""
|
||||
return [
|
||||
_romfolder_pin(_subject(setup, doc, key), setup, doc["sources"][key], platforms_dir, cache_dir, offline)
|
||||
for setup, doc in romfolder_sources(platforms_dir).items()
|
||||
for setup, doc in load_sources(sources_dir(platforms_dir)).items()
|
||||
for key in watched_sources(doc)
|
||||
]
|
||||
|
||||
|
||||
@@ -24,8 +24,19 @@ from model.profiles import load_emulator_profiles, preferred_profile, upstream_p
|
||||
from model.platforms import load_platform_config, native_layer
|
||||
from model.sources import source_yaml_file
|
||||
|
||||
ROMFOLDERS_DIR = Path("platforms") / "romfolders"
|
||||
SOURCES_DIR = ROMFOLDERS_DIR / "_sources"
|
||||
|
||||
def romfolders_dir(platforms_dir: str | Path = PLATFORMS_DIR) -> Path:
|
||||
"""The rom-folder setups of a platforms directory."""
|
||||
return Path(platforms_dir) / "romfolders"
|
||||
|
||||
|
||||
def sources_dir(platforms_dir: str | Path = PLATFORMS_DIR) -> Path:
|
||||
"""The setups' declared sources and pins, beside the setup files."""
|
||||
return romfolders_dir(platforms_dir) / "_sources"
|
||||
|
||||
|
||||
ROMFOLDERS_DIR = romfolders_dir()
|
||||
SOURCES_DIR = sources_dir()
|
||||
|
||||
# "<source key> <path>:<line>[-<line>]", several joined by "; ".
|
||||
_REF_PART = re.compile(r"^(?P<key>[a-z0-9][a-z0-9-]*) (?P<path>\S+?)(?::(?P<lines>\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*))?$")
|
||||
@@ -87,6 +98,11 @@ def setup_paths(directory: Path = ROMFOLDERS_DIR) -> list[Path]:
|
||||
return sorted(p for p in Path(directory).glob("*.yml") if not p.name.startswith("_"))
|
||||
|
||||
|
||||
def load_sources(directory: Path = SOURCES_DIR) -> dict[str, dict]:
|
||||
"""Each setup's declared sources and facts, keyed by its file name."""
|
||||
return {path.stem: source_yaml_file(path) or {} for path in sorted(Path(directory).glob("*.yml"))}
|
||||
|
||||
|
||||
def load_setup(path: Path) -> dict:
|
||||
return source_yaml_file(path)
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ if (_SCRIPTS_DIR := str(Path(__file__).resolve().parents[2])) not in sys.path:
|
||||
sys.path.insert(0, _SCRIPTS_DIR)
|
||||
|
||||
from core import upstream
|
||||
from model.sources import source_yaml_file
|
||||
|
||||
from ..base_scraper import PlatformDumper
|
||||
|
||||
@@ -160,14 +159,6 @@ def load_formats() -> dict[str, Parser]:
|
||||
return FORMATS
|
||||
|
||||
|
||||
def load_sources(directory: Path) -> dict[str, dict]:
|
||||
"""Each setup's declared sources and facts, keyed by its file name."""
|
||||
out: dict[str, dict] = {}
|
||||
for path in sorted(Path(directory).glob("*.yml")):
|
||||
out[path.stem] = source_yaml_file(path) or {}
|
||||
return out
|
||||
|
||||
|
||||
def _clean_row(row: dict) -> dict:
|
||||
unknown = set(row) - set(ROW_KEYS)
|
||||
if unknown:
|
||||
|
||||
@@ -11,11 +11,10 @@ import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from . import Fetcher, SourceError, dump_setup, load_sources, scrape_setup
|
||||
from . import Fetcher, SourceError, dump_setup, scrape_setup
|
||||
from core.upstream import UpstreamError
|
||||
from core.artifacts import write_if_changed
|
||||
|
||||
DEFAULT_DIR = Path("platforms") / "romfolders"
|
||||
from model.romfolders import ROMFOLDERS_DIR, SOURCES_DIR, load_sources
|
||||
|
||||
|
||||
def main() -> int:
|
||||
@@ -24,10 +23,10 @@ def main() -> int:
|
||||
which.add_argument("--setup", action="append", help="setup id (repeatable)")
|
||||
which.add_argument("--all", action="store_true", help="every setup of the sources file")
|
||||
which.add_argument("--list", action="store_true", help="list the setups and their format")
|
||||
parser.add_argument("--sources", type=Path, default=DEFAULT_DIR / "_sources",
|
||||
parser.add_argument("--sources", type=Path, default=SOURCES_DIR,
|
||||
help="the setups, their repositories and pinned revisions")
|
||||
parser.add_argument("--output-dir", type=Path, default=DEFAULT_DIR,
|
||||
help=f"where <setup>.yml is written (default {DEFAULT_DIR})")
|
||||
parser.add_argument("--output-dir", type=Path, default=ROMFOLDERS_DIR,
|
||||
help=f"where <setup>.yml is written (default {ROMFOLDERS_DIR})")
|
||||
parser.add_argument("--offline", action="store_true", help="read the revision cache only")
|
||||
parser.add_argument("--dry-run", action="store_true", help="print counts, write nothing")
|
||||
args = parser.parse_args()
|
||||
|
||||
Reference in new issue
Block a user