mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 14:28:54 -06:00
refactor: move fixed_paths to shell_launchers
This commit is contained in:
1 parent
7b0a5d5d4a
commit
13f92eaf4a
3 files changed
+30
-27
No files matched your search
@@ -19,11 +19,11 @@ from dataclasses import dataclass, field
|
||||
|
||||
from model.launcherrecords import join_emulators
|
||||
from .configgen_launchers import Launcher
|
||||
from .rocknix_launchers import fixed_paths
|
||||
from scraper.shell_launchers import (
|
||||
config_placement,
|
||||
describe_keys,
|
||||
apply_evidence,
|
||||
fixed_paths,
|
||||
first_boot_placement,
|
||||
LauncherPatternMissing,
|
||||
Link,
|
||||
|
||||
@@ -26,6 +26,8 @@ from scraper.shell_launchers import (
|
||||
link_record,
|
||||
RepoTree,
|
||||
Script,
|
||||
FixedPaths,
|
||||
fixed_paths,
|
||||
Setting,
|
||||
settings,
|
||||
source_ref,
|
||||
@@ -142,32 +144,6 @@ def _file_under(value: str, root: str) -> bool:
|
||||
return value.startswith(root.rstrip("/") + "/")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FixedPaths:
|
||||
"""Keys of a config that name a file under one directory."""
|
||||
|
||||
keys: tuple[tuple[str, str], ...]
|
||||
names: tuple[str, ...]
|
||||
search_dir: str
|
||||
|
||||
|
||||
def fixed_paths(
|
||||
found: list[Setting], keys: list[tuple[str, str]], path: str
|
||||
) -> tuple[FixedPaths, set[int]]:
|
||||
"""The values of keys, as names relative to the directory they share."""
|
||||
by_key = {(s.section, s.key): s for s in found}
|
||||
missing = [k for k in keys if k not in by_key]
|
||||
if missing:
|
||||
raise LauncherPatternMissing(path, f"key {missing[0][1]}")
|
||||
values = [by_key[k].value for k in keys if by_key[k].value]
|
||||
lines = {by_key[k].line for k in keys}
|
||||
if not values:
|
||||
return FixedPaths(tuple(keys), (), ""), lines
|
||||
folder = posixpath.commonpath([posixpath.dirname(v) for v in values])
|
||||
names = tuple(posixpath.relpath(v, folder) for v in values)
|
||||
return FixedPaths(tuple(keys), names, folder), lines
|
||||
|
||||
|
||||
def bios_keys(tree: RepoTree, paths: list[str], root: str = BIOS_ROOT) -> list[tuple[str, str]]:
|
||||
"""Keys whose value is a file under root in at least one of the configs."""
|
||||
keys: list[tuple[str, str]] = []
|
||||
|
||||
@@ -10,6 +10,7 @@ gone, so a rewrite upstream stops the scrape instead of publishing nothing.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import posixpath
|
||||
import re
|
||||
from collections.abc import Callable, Iterable
|
||||
from dataclasses import dataclass, field
|
||||
@@ -667,6 +668,32 @@ def settings(text: str, separator: str = "=") -> list[Setting]:
|
||||
return found
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FixedPaths:
|
||||
"""Keys of a config that name a file under one directory."""
|
||||
|
||||
keys: tuple[tuple[str, str], ...]
|
||||
names: tuple[str, ...]
|
||||
search_dir: str
|
||||
|
||||
|
||||
def fixed_paths(
|
||||
found: list[Setting], keys: list[tuple[str, str]], path: str
|
||||
) -> tuple[FixedPaths, set[int]]:
|
||||
"""The values of keys, as names relative to the directory they share."""
|
||||
by_key = {(s.section, s.key): s for s in found}
|
||||
missing = [k for k in keys if k not in by_key]
|
||||
if missing:
|
||||
raise LauncherPatternMissing(path, f"key {missing[0][1]}")
|
||||
values = [by_key[k].value for k in keys if by_key[k].value]
|
||||
lines = {by_key[k].line for k in keys}
|
||||
if not values:
|
||||
return FixedPaths(tuple(keys), (), ""), lines
|
||||
folder = posixpath.commonpath([posixpath.dirname(v) for v in values])
|
||||
names = tuple(posixpath.relpath(v, folder) for v in values)
|
||||
return FixedPaths(tuple(keys), names, folder), lines
|
||||
|
||||
|
||||
def describe_keys(file: str, keys: tuple[tuple[str, str], ...]) -> str:
|
||||
"""file [section] key, key [other] key, sections named where they change."""
|
||||
described, section = file, None
|
||||
|
||||
Reference in new issue
Block a user