mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-29 12:58:51 -06:00
refactor: one owner per installer source decision
--emulator says its Narrowed line through detail, as every other narrowing. Detection records that it read the RetroArch configs, and a lookup detects again only before that, held by detection_held. The list and pack open apart from the --from folders, whose refusal one function builds for line mode and the full screen.
This commit is contained in:
1 parent
18472f9d0f
commit
2b5031ecd6
15 files changed
+121
-89
No files matched your search
@@ -340,8 +340,9 @@ def _narrowing_advice(plat: str, axis: str, flag: str, recorded: frozenset,
|
||||
def _narrow_to_emulators(
|
||||
names: list[str], manifest: dict, plat: str,
|
||||
files: list[dict], omitted: list[dict],
|
||||
) -> tuple[list[dict], list[dict]]:
|
||||
"""Keep what the named emulators read, as the pack built for them.
|
||||
) -> tuple[list[str], list[dict], list[dict]]:
|
||||
"""(names chosen, files, omitted): what the named emulators read, as the
|
||||
pack built for them.
|
||||
|
||||
An emulator page offers this as one command, so a name the platform
|
||||
does not run is refused rather than read as nothing to install.
|
||||
@@ -355,7 +356,6 @@ def _narrow_to_emulators(
|
||||
chosen = resolve_choices(names, known, "emulator")
|
||||
except ValueError as exc:
|
||||
refuse_name(plat, f"Error: {plat}: {exc}")
|
||||
before = len(files)
|
||||
files, omitted = narrow_to_cores(manifest, chosen, files, omitted)
|
||||
# A whole-platform install keeps the platform's files of a system no
|
||||
# core is mapped to. Here only the named emulators' systems are wanted.
|
||||
@@ -370,8 +370,7 @@ def _narrow_to_emulators(
|
||||
|
||||
files = [entry for entry in files if theirs(entry)]
|
||||
omitted = [entry for entry in omitted if theirs(entry)]
|
||||
print(f" Narrowed {before} to {len(files)} files to {', '.join(chosen)}")
|
||||
return files, omitted
|
||||
return chosen, files, omitted
|
||||
|
||||
|
||||
def _standalone_builds(
|
||||
|
||||
@@ -59,6 +59,9 @@ def _retroarch_cfg_dir(
|
||||
# System directory -> the retroarch.cfg it was read from and the directory
|
||||
# ':' expands to there, for finding the cores of the same installation.
|
||||
_RETROARCH_CONFIGS: dict[Path, tuple[Path, Path]] = {}
|
||||
# Set by detection once it has read the configs: a lookup after it finds
|
||||
# nothing more by detecting again.
|
||||
_CONFIGS_READ: list[bool] = []
|
||||
|
||||
|
||||
def _parse_retroarch_system_dir(
|
||||
|
||||
@@ -10,6 +10,7 @@ from collections.abc import Callable, Iterator
|
||||
from pathlib import Path
|
||||
|
||||
from installer.config_values import (
|
||||
_CONFIGS_READ,
|
||||
_parse_bash_var,
|
||||
_parse_json_path,
|
||||
_parse_ps1_var,
|
||||
@@ -826,6 +827,8 @@ def _without_unnameable(found: list[tuple[str, Path]]) -> list[tuple[str, Path]]
|
||||
@_detection_guarded
|
||||
def detect_platforms(os_type: str) -> list[tuple[str, Path]]:
|
||||
"""Detect installed emulator platforms and their BIOS directories."""
|
||||
if not _CONFIGS_READ:
|
||||
_CONFIGS_READ.append(True)
|
||||
found: list[tuple[str, Path]] = []
|
||||
if os_type == "wsl":
|
||||
_note_windows_unasked()
|
||||
|
||||
+28
-10
@@ -803,12 +803,23 @@ def sources_line(
|
||||
|
||||
|
||||
def _open_local_sources(args: argparse.Namespace) -> None:
|
||||
"""Take the file list and the pack this run was given, and the platform
|
||||
they are for when none is named."""
|
||||
"""Line mode's sources: the --from folders read, then the file list and
|
||||
the pack this run was given."""
|
||||
reset_local_sources(args)
|
||||
open_from_folders(getattr(args, "from", None) or [])
|
||||
open_list_and_pack(args)
|
||||
|
||||
|
||||
def reset_local_sources(args: argparse.Namespace) -> None:
|
||||
"""Forget the sources and failures a previous run in this process kept."""
|
||||
LOCAL.reset()
|
||||
LOCAL.jobs = getattr(args, "jobs", 8) or 8
|
||||
SAID_FAILED.clear()
|
||||
_open_from_folders(getattr(args, "from", None) or [])
|
||||
|
||||
|
||||
def open_list_and_pack(args: argparse.Namespace) -> None:
|
||||
"""Take the file list and the pack this run was given, and the platform
|
||||
they are for when none is named."""
|
||||
if args.manifest is not None:
|
||||
LOCAL.manifest = args.manifest
|
||||
named = local_manifest_platform(args.manifest)
|
||||
@@ -889,16 +900,23 @@ def from_folder_problem(label: str) -> tuple[str, str] | None:
|
||||
return ("system", system) if system else None
|
||||
|
||||
|
||||
def _open_from_folders(folders: list[Path]) -> None:
|
||||
def from_folder_refusal(label: str) -> Refusal | None:
|
||||
"""The refusal of a folder named with --from that cannot be read, or None."""
|
||||
problem = from_folder_problem(label)
|
||||
if problem is None:
|
||||
return None
|
||||
reason, what = problem
|
||||
message = f"{label} {what}: --from names the folder to copy BIOS files from"
|
||||
return Refusal("from", reason, "", f"Error: {screen_text(message)}.", message=message)
|
||||
|
||||
|
||||
def open_from_folders(folders: list[Path]) -> None:
|
||||
"""Read each folder named with --from, or stop on one that cannot be."""
|
||||
for folder in folders:
|
||||
label = str(folder)
|
||||
problem = from_folder_problem(label)
|
||||
if problem is not None:
|
||||
reason, what = problem
|
||||
message = f"{label} {what}: --from names the folder to copy BIOS files from"
|
||||
raise Refusal("from", reason, "", f"Error: {screen_text(message)}.",
|
||||
message=message)
|
||||
refusal = from_folder_refusal(label)
|
||||
if refusal is not None:
|
||||
raise refusal
|
||||
_read_from_folder(label)
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
"""The folders a frontend names besides its BIOS folder: saves, roms, configs and emulators."""
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path, PurePosixPath
|
||||
|
||||
from installer.config_values import (
|
||||
_CONFIGS_READ,
|
||||
_RETROARCH_CONFIGS,
|
||||
_cfg_true,
|
||||
_config_keys,
|
||||
@@ -18,6 +17,7 @@ from installer.config_values import (
|
||||
from installer.console import detail
|
||||
from installer.detect_frontends import detect_platforms
|
||||
from installer.detect_os import detect_os
|
||||
from installer.detection_notes import detection_held
|
||||
from installer.events import EVENTS
|
||||
from installer.host_fs import _SETUP_SEARCH, _is_dir
|
||||
from installer.invocation import _INVOCATION
|
||||
@@ -36,8 +36,6 @@ from installer.paths import (
|
||||
)
|
||||
from installer.text import _plural
|
||||
|
||||
_CONFIGS_READ: list[bool] = []
|
||||
|
||||
|
||||
def _retroarch_config_for(bios_path: Path) -> tuple[Path, Path] | None:
|
||||
"""The retroarch.cfg whose system_directory is bios_path, and the
|
||||
@@ -52,13 +50,11 @@ def _retroarch_config_for(bios_path: Path) -> tuple[Path, Path] | None:
|
||||
found = _retroarch_config_at(bios_path)
|
||||
if found is not None or _CONFIGS_READ:
|
||||
return found
|
||||
_CONFIGS_READ.append(True)
|
||||
# Silent, the unsearched event too: this run searched for no setup, and
|
||||
# the event came after detect, the line it stands for never shown.
|
||||
_SETUP_SEARCH.quiet = True
|
||||
try:
|
||||
with contextlib.redirect_stdout(io.StringIO()), \
|
||||
contextlib.redirect_stderr(io.StringIO()):
|
||||
with detection_held():
|
||||
detect_platforms(_INVOCATION.os_type or detect_os())
|
||||
finally:
|
||||
_SETUP_SEARCH.quiet = False
|
||||
|
||||
@@ -470,9 +470,11 @@ def _pass_emulators(run: _InstallRun, p: _PlatformPass) -> bool:
|
||||
_recorded_emulators(args, p.plat_name, p.manifest, p.files, p.omitted_files)
|
||||
if args.emulator:
|
||||
names = emulator_names(p.manifest, p.files, p.omitted_files)
|
||||
p.files, p.omitted_files = _narrow_to_emulators(
|
||||
before = len(p.files)
|
||||
chosen, p.files, p.omitted_files = _narrow_to_emulators(
|
||||
args.emulator, p.manifest, p.plat_name, p.files, p.omitted_files
|
||||
)
|
||||
detail(f" Narrowed {before} to {len(p.files)} files to {', '.join(chosen)}")
|
||||
if args.standalone:
|
||||
p.files, p.omitted_files = _standalone_builds(
|
||||
args.emulator, names, p.manifest, p.plat_name, p.files, p.omitted_files)
|
||||
|
||||
@@ -32,7 +32,7 @@ from installer.destination import card_choice, dest_default
|
||||
from installer.detect_frontends import detect_frontends
|
||||
from installer.detection_notes import DETECTION_NOTES, detection_held
|
||||
from installer.detect_os import _enter_wsl, _wsl_dest, detect_os, detected_os
|
||||
from installer.from_folders import _open_local_sources, from_folder_problem
|
||||
from installer.from_folders import from_folder_refusal, open_list_and_pack, reset_local_sources
|
||||
from installer.host_fs import _DETECTION_REFUSED, refused_words
|
||||
from installer.install_record import choice_given
|
||||
from installer.invocation import _INVOCATION
|
||||
@@ -874,19 +874,15 @@ def _tui_startup(args: argparse.Namespace) -> tuple[TuiState, list[tuple]] | Non
|
||||
if os_type == "wsl":
|
||||
_enter_wsl()
|
||||
_wsl_dest(args)
|
||||
reset_local_sources(args)
|
||||
open_list_and_pack(args)
|
||||
# The --from folders are read by each check, not here: indexing a large
|
||||
# card held the first frame back. Only whether each can be read is asked.
|
||||
folders = getattr(args, "from") or []
|
||||
setattr(args, "from", None)
|
||||
try:
|
||||
_open_local_sources(args)
|
||||
finally:
|
||||
setattr(args, "from", folders)
|
||||
for folder in folders:
|
||||
problem = from_folder_problem(str(folder))
|
||||
if problem is not None:
|
||||
print(f"Error: {screen_text(str(folder))} {problem[1]}: --from names the folder "
|
||||
"to copy BIOS files from.", file=sys.stderr)
|
||||
for folder in getattr(args, "from") or []:
|
||||
refusal = from_folder_refusal(str(folder))
|
||||
if refusal is not None:
|
||||
for line in refusal.lines:
|
||||
print(line, file=sys.stderr)
|
||||
return None
|
||||
return tui_start(args, os_type)
|
||||
|
||||
|
||||
Reference in new issue
Block a user