mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-27 03:48:52 -06:00
refactor: take a recorded choice in one place
The journey to another device's folder no longer stops on Create the folder?: one missing level is created as line mode does, since the shared rule for a missing BIOS folder.
This commit is contained in:
1 parent
c113a79c70
commit
352e2bbb5e
7 files changed
+125
-44
No files matched your search
+33
-10
@@ -414,6 +414,33 @@ def drop_recorded(args: argparse.Namespace, plat: str, flag: str, why: str,
|
||||
print(f" Left out of the recorded choice: {flag} ({why}).")
|
||||
|
||||
|
||||
class RecordedChoice(NamedTuple):
|
||||
"""A recorded choice as a run takes it: parsed, its words once the
|
||||
parts that no longer apply are out, and those parts in words."""
|
||||
|
||||
parsed: argparse.Namespace
|
||||
choice: list[str]
|
||||
left_out: list[str]
|
||||
|
||||
|
||||
def take_recorded_choice(choice: list[str]) -> RecordedChoice | None:
|
||||
"""The recorded choice made the run's, None where this installer lacks
|
||||
one of its options. A games folder that is gone gives the card's own."""
|
||||
try:
|
||||
parsed = build_parser().parse_args(choice)
|
||||
except SystemExit:
|
||||
return None
|
||||
words, left_out = list(choice), []
|
||||
if isinstance(parsed.for_games, Path) and not _is_dir(parsed.for_games):
|
||||
parsed.for_games = True
|
||||
options = [(flag, None if flag == "--for-games" else value)
|
||||
for flag, value in record_options(choice)]
|
||||
words = [word for flag, value in options
|
||||
for word in ([flag] if value is None else [flag, value])]
|
||||
left_out.append("its games folder (no longer there)")
|
||||
return RecordedChoice(parsed, words, left_out)
|
||||
|
||||
|
||||
def apply_record(args: argparse.Namespace, plat: str, folder: Path) -> dict | None:
|
||||
"""Take the choice recorded for plat in folder as the run's, as if its
|
||||
options had been typed: the plan's first choice. Returns the record,
|
||||
@@ -422,30 +449,26 @@ def apply_record(args: argparse.Namespace, plat: str, folder: Path) -> dict | No
|
||||
say_record_problem(plat, folder, path, problem)
|
||||
if setup is None:
|
||||
return None
|
||||
try:
|
||||
parsed = build_parser().parse_args(setup["choice"])
|
||||
except SystemExit:
|
||||
taken = take_recorded_choice(setup["choice"])
|
||||
if taken is None:
|
||||
say_record_problem(plat, folder, path,
|
||||
f"The install record {path} names options this installer lacks")
|
||||
return None
|
||||
parsed = taken.parsed
|
||||
for flag in RECORD_CHOICE:
|
||||
name = flag[2:].replace("-", "_")
|
||||
setattr(args, name, getattr(parsed, name))
|
||||
if args.for_games is not None:
|
||||
args.all_files = False
|
||||
args.from_record = True
|
||||
options = record_options(setup["choice"])
|
||||
options = record_options(taken.choice)
|
||||
if any(flag in RECORD_NARROWING for flag, _value in options):
|
||||
# Said where it narrows the list: the whole list again is the run
|
||||
# a person expects, and said nothing new.
|
||||
_RECORD_TAKEN[plat] = setup
|
||||
_INVOCATION.chosen[plat] = [option for option in options if option[0] != "--all-files"]
|
||||
if isinstance(args.for_games, Path) and not _is_dir(args.for_games):
|
||||
# The games folder recorded is gone: the card's own games are read.
|
||||
_INVOCATION.chosen[plat] = [(flag, None if flag == "--for-games" else value)
|
||||
for flag, value in _INVOCATION.chosen[plat]]
|
||||
args.for_games = True
|
||||
print(" Left out of the recorded choice: its games folder (no longer there).")
|
||||
for part in taken.left_out:
|
||||
print(f" Left out of the recorded choice: {part}.")
|
||||
message = record_menu_words(setup)
|
||||
EVENTS.emit("record", platform=plat, folder=str(folder), path=str(path), status="applied",
|
||||
choice=list(setup["choice"]), date=setup["written"],
|
||||
|
||||
@@ -7,7 +7,6 @@ from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from installer.arguments import build_parser
|
||||
from installer.cards import (
|
||||
_card_boundary,
|
||||
_mount_name,
|
||||
@@ -36,7 +35,13 @@ from installer.embedded import CARD_PLATFORMS, _a
|
||||
from installer.frontend_folders import _retroarch_config_at
|
||||
from installer.games import games_probe
|
||||
from installer.host_fs import _exists, _folder_writable, _is_dir, _nearest_folder, closed_folder
|
||||
from installer.install_record import RECORD_NARROWING, _RECORD_SAID, record_options, setup_record
|
||||
from installer.install_record import (
|
||||
RECORD_NARROWING,
|
||||
_RECORD_SAID,
|
||||
record_options,
|
||||
setup_record,
|
||||
take_recorded_choice,
|
||||
)
|
||||
from installer.invocation import OFFLINE_VARIABLE
|
||||
from installer.lists import local_targets
|
||||
from installer.offline import LOCAL, OFFLINE_FLAG_VALUE
|
||||
@@ -227,12 +232,17 @@ def _start_run(state: TuiState, run: str) -> list[tuple]:
|
||||
def _tui_record_take(state: TuiState) -> None:
|
||||
"""The recorded choice made the screen's, as its options would make it."""
|
||||
setup = state.record or {}
|
||||
try:
|
||||
parsed = build_parser().parse_args(setup.get("choice") or [])
|
||||
except SystemExit:
|
||||
taken = take_recorded_choice(setup.get("choice") or [])
|
||||
if taken is None:
|
||||
state.status = "The install record names options this installer lacks, so it is ignored."
|
||||
state.record = None
|
||||
return
|
||||
parsed = taken.parsed
|
||||
if taken.left_out:
|
||||
# What the run takes, as line mode keeps it: the plan reads as the
|
||||
# record's own choice again.
|
||||
setup = state.record = {**setup, "choice": taken.choice}
|
||||
state.status = f"Left out of the recorded choice: {', '.join(taken.left_out)}."
|
||||
state.cli_systems = list(parsed.system or [])
|
||||
state.cores = [token.strip() for value in parsed.core or [] for token in value.split(",")
|
||||
if token.strip()]
|
||||
|
||||
Reference in new issue
Block a user