mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-27 11:58:53 -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"],
|
||||
|
||||
Reference in new issue
Block a user