From 8ecd102c77b1808dc1e0558379330a8a05a7e66b Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 05:04:56 +0100 Subject: [PATCH] refactor: name the listing options once Eight places tested the five --list-* options by hand, and four lists named them. One table and one function now say which a run gave, so a sixth listing is one line. --- install.ps1 | 2 +- install.py | 48 +++++++++++++++++------------------- install.sh | 2 +- install/launchers/index.json | 16 ++++++------ installer/cli.py | 37 ++++++++++++--------------- installer/events.py | 4 +-- installer/invocation.py | 12 +++++++++ installer/tui_routes.py | 6 ++--- 8 files changed, 66 insertions(+), 61 deletions(-) diff --git a/install.ps1 b/install.ps1 index 9014d129b..34d0442f9 100644 --- a/install.ps1 +++ b/install.ps1 @@ -16,7 +16,7 @@ # and Invoke-WebRequest throws on a cut transfer before the hash is read: # the site's build rewrites this line there (scripts/sitebootstrap.py). $mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." - $defaultInstallSha256 = "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1" + $defaultInstallSha256 = "fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. $maximumInstallerBytes = 8MB diff --git a/install.py b/install.py index 61c0cec22..57ec13efb 100644 --- a/install.py +++ b/install.py @@ -545,6 +545,18 @@ _COMMAND_ORDER = ( ) +# The options that print a list and install nothing, in the order a run +# names them. +LISTING_FLAGS = (("--list-platforms", "list_platforms"), ("--list-targets", "list_targets"), + ("--list-systems", "list_systems"), ("--list-cores", "list_cores"), + ("--list-emulators", "list_emulators")) + + +def listings_given(args: argparse.Namespace) -> list[str]: + """The listing options of a run, as typed.""" + return [flag for flag, attr in LISTING_FLAGS if getattr(args, attr)] + + def _command_rank(option: tuple[str, str | None]) -> int: flag = option[0] return _COMMAND_ORDER.index(flag) if flag in _COMMAND_ORDER else len(_COMMAND_ORDER) @@ -1549,8 +1561,7 @@ def _event_mode(args: argparse.Namespace) -> str: return "check" if args.dry_run: return "dry-run" - if (args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators): + if listings_given(args): return "list" return "install" @@ -13124,9 +13135,8 @@ def _tui_flag_blocker(args: argparse.Namespace) -> str: """The option of a run without questions, said as the reason.""" for flag, given in ( ("--check", args.check), ("--dry-run", args.dry_run), - ("--list-platforms", args.list_platforms), ("--list-targets", args.list_targets), - ("--list-systems", args.list_systems), ("--list-cores", args.list_cores), - ("--list-emulators", args.list_emulators), ("--events", args.events), + *((flag, getattr(args, attr)) for flag, attr in LISTING_FLAGS), + ("--events", args.events), ("--quiet", args.quiet), ("--yes", args.yes), ("--no-input", args.no_input), ("--restore", args.restore is not None), ("--pack", getattr(args, "pack", None) is not None), @@ -31402,8 +31412,7 @@ def _check_expert(parser: argparse.ArgumentParser, args: argparse.Namespace) -> """--one-per-slot, --standalone, --source truth and --find, applied or refused, never ignored. Each is held equal to the pack builder's own option, so a choice the builder refuses beside it is refused here.""" - listing = (args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators) + listing = bool(listings_given(args)) truth = args.source == "truth" refusals = ( (args.json and not args.find, "--json applies to --find"), @@ -31498,8 +31507,7 @@ def _main_check_values(parser: argparse.ArgumentParser, args: argparse.Namespace ): parser.error(f"{option} needs at least one name") if args.quiet and ( - args.check or args.dry_run or args.list_platforms or args.list_targets - or args.list_systems or args.list_cores or args.list_emulators + args.check or args.dry_run or listings_given(args) ): parser.error("--quiet applies to an install, not to --check, --dry-run or a listing") if args.tui and args.plain: @@ -31509,9 +31517,7 @@ def _main_check_values(parser: argparse.ArgumentParser, args: argparse.Namespace if args.required_only and args.for_games is None: parser.error("--required-only applies to --for-games: the list alone does not " "say which files a game cannot start without") - if args.for_games is not None and ( - args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators): + if args.for_games is not None and listings_given(args): parser.error("--for-games narrows an install, not a listing") @@ -31520,10 +31526,7 @@ def _main_check_listings(parser: argparse.ArgumentParser, args: argparse.Namespa # Applied or refused, never ignored: a run prints one list, and the # narrowing options apply to --list-systems and --list-cores only, past # --target and --installed-cores, which --list-emulators also reads. - listings = [flag for flag, given in ( - ("--list-platforms", args.list_platforms), ("--list-targets", args.list_targets), - ("--list-systems", args.list_systems), ("--list-cores", args.list_cores), - ("--list-emulators", args.list_emulators)) if given] + listings = listings_given(args) if len(listings) > 1: parser.error(f"{listings[0]} and {listings[1]} each print a list: run them " "one at a time") @@ -31573,8 +31576,7 @@ def _main_check_add_app(parser: argparse.ArgumentParser, args: argparse.Namespac (args.check or args.dry_run, "--add-app writes the RetroBIOS app on the card, which --check and " "--dry-run do not"), - (args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators, + (listings_given(args), "--add-app writes the RetroBIOS app on the card, which a listing does not"), (args.from_pack, "--add-app downloads the RetroBIOS app, and --from-pack " "makes no network request"), @@ -31607,10 +31609,7 @@ def _main_check_offline(parser: argparse.ArgumentParser, args: argparse.Namespac def _main_check_sources(parser: argparse.ArgumentParser, args: argparse.Namespace) -> None: """Refuse a source of files given with a listing that reads none.""" - if getattr(args, "from") and ( - args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators - ): + if getattr(args, "from") and listings_given(args): parser.error("--from copies files into the BIOS folder, which a listing " "does not write") if (args.from_pack or args.manifest) and args.list_platforms: @@ -31769,9 +31768,8 @@ def _check_pack(parser: argparse.ArgumentParser, args: argparse.Namespace) -> No ("--installed-cores", args.installed_cores), ("--cores-dir", args.cores_dir), ("--save-dir", args.save_dir), ("--standalone-copies", args.standalone_copies), ("--add-app", args.add_app), ("--romm-firmware", args.romm_firmware is not None), - ("--tui", args.tui), ("--list-platforms", args.list_platforms), - ("--list-targets", args.list_targets), ("--list-systems", args.list_systems), - ("--list-cores", args.list_cores), ("--list-emulators", args.list_emulators), + ("--tui", args.tui), + *((flag, getattr(args, attr)) for flag, attr in LISTING_FLAGS), ): if given: parser.error(f"--pack writes a pack ZIP, and {flag} reads or writes the " diff --git a/install.sh b/install.sh index afe182d08..69eaad3fb 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins # curl or wget stop on a cut transfer before the hash is read: the site's # build rewrites this line there (scripts/sitebootstrap.py). MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." -DEFAULT_INSTALL_SHA256="51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1" +DEFAULT_INSTALL_SHA256="fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. MAX_INSTALLER_BYTES=8388608 diff --git a/install/launchers/index.json b/install/launchers/index.json index 72e7e2fa1..a92f3d145 100644 --- a/install/launchers/index.json +++ b/install/launchers/index.json @@ -27,8 +27,8 @@ { "dest": "roms/ports/retrobios/install.py", "repo_path": "install.py", - "size": 1449198, - "sha256": "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1", + "size": 1448585, + "sha256": "fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1502823, - "sha256": "a89d78536fbb9c9642f57a879b7895f1d01607c57f781cdeeccaa54851db205f" + "size": 1502210, + "sha256": "a67944ee5000e3b1fc22081e0062025789b5d7b5efd25446df11bedbd04b0920" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1449198, - "sha256": "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1", + "size": 1448585, + "sha256": "fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1449198, - "sha256": "51a8d68a168a7cda89969c568aa1342202af26140e906af0105f44fa413d0cd1", + "size": 1448585, + "sha256": "fe4bc003ca129ff7c5f3adf622b51fded3c223560e7bf3a0e0c3289b7f9d706d", "executable": false }, { diff --git a/installer/cli.py b/installer/cli.py index 0039f8963..cce15c7e1 100644 --- a/installer/cli.py +++ b/installer/cli.py @@ -18,7 +18,14 @@ from installer.from_folders import _open_local_sources from installer.handheld_app import app_not_added from installer.host_fs import _is_dir, _writing from installer.install_record import restore_kept -from installer.invocation import OFFLINE_VARIABLE, _INVOCATION, installer_id, offline_requested +from installer.invocation import ( + LISTING_FLAGS, + OFFLINE_VARIABLE, + _INVOCATION, + installer_id, + listings_given, + offline_requested, +) from installer.narrowing import FIND_KINDS from installer.network import _RAW_ERRORS, install_bounded_opener from installer.offline import LOCAL, OFFLINE_FLAG_VALUE, offline_named @@ -34,8 +41,7 @@ def _check_expert(parser: argparse.ArgumentParser, args: argparse.Namespace) -> """--one-per-slot, --standalone, --source truth and --find, applied or refused, never ignored. Each is held equal to the pack builder's own option, so a choice the builder refuses beside it is refused here.""" - listing = (args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators) + listing = bool(listings_given(args)) truth = args.source == "truth" refusals = ( (args.json and not args.find, "--json applies to --find"), @@ -130,8 +136,7 @@ def _main_check_values(parser: argparse.ArgumentParser, args: argparse.Namespace ): parser.error(f"{option} needs at least one name") if args.quiet and ( - args.check or args.dry_run or args.list_platforms or args.list_targets - or args.list_systems or args.list_cores or args.list_emulators + args.check or args.dry_run or listings_given(args) ): parser.error("--quiet applies to an install, not to --check, --dry-run or a listing") if args.tui and args.plain: @@ -141,9 +146,7 @@ def _main_check_values(parser: argparse.ArgumentParser, args: argparse.Namespace if args.required_only and args.for_games is None: parser.error("--required-only applies to --for-games: the list alone does not " "say which files a game cannot start without") - if args.for_games is not None and ( - args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators): + if args.for_games is not None and listings_given(args): parser.error("--for-games narrows an install, not a listing") @@ -152,10 +155,7 @@ def _main_check_listings(parser: argparse.ArgumentParser, args: argparse.Namespa # Applied or refused, never ignored: a run prints one list, and the # narrowing options apply to --list-systems and --list-cores only, past # --target and --installed-cores, which --list-emulators also reads. - listings = [flag for flag, given in ( - ("--list-platforms", args.list_platforms), ("--list-targets", args.list_targets), - ("--list-systems", args.list_systems), ("--list-cores", args.list_cores), - ("--list-emulators", args.list_emulators)) if given] + listings = listings_given(args) if len(listings) > 1: parser.error(f"{listings[0]} and {listings[1]} each print a list: run them " "one at a time") @@ -205,8 +205,7 @@ def _main_check_add_app(parser: argparse.ArgumentParser, args: argparse.Namespac (args.check or args.dry_run, "--add-app writes the RetroBIOS app on the card, which --check and " "--dry-run do not"), - (args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators, + (listings_given(args), "--add-app writes the RetroBIOS app on the card, which a listing does not"), (args.from_pack, "--add-app downloads the RetroBIOS app, and --from-pack " "makes no network request"), @@ -239,10 +238,7 @@ def _main_check_offline(parser: argparse.ArgumentParser, args: argparse.Namespac def _main_check_sources(parser: argparse.ArgumentParser, args: argparse.Namespace) -> None: """Refuse a source of files given with a listing that reads none.""" - if getattr(args, "from") and ( - args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators - ): + if getattr(args, "from") and listings_given(args): parser.error("--from copies files into the BIOS folder, which a listing " "does not write") if (args.from_pack or args.manifest) and args.list_platforms: @@ -401,9 +397,8 @@ def _check_pack(parser: argparse.ArgumentParser, args: argparse.Namespace) -> No ("--installed-cores", args.installed_cores), ("--cores-dir", args.cores_dir), ("--save-dir", args.save_dir), ("--standalone-copies", args.standalone_copies), ("--add-app", args.add_app), ("--romm-firmware", args.romm_firmware is not None), - ("--tui", args.tui), ("--list-platforms", args.list_platforms), - ("--list-targets", args.list_targets), ("--list-systems", args.list_systems), - ("--list-cores", args.list_cores), ("--list-emulators", args.list_emulators), + ("--tui", args.tui), + *((flag, getattr(args, attr)) for flag, attr in LISTING_FLAGS), ): if given: parser.error(f"--pack writes a pack ZIP, and {flag} reads or writes the " diff --git a/installer/events.py b/installer/events.py index 15e13e574..88f2c9f6f 100644 --- a/installer/events.py +++ b/installer/events.py @@ -6,6 +6,7 @@ import json import threading from typing import TextIO +from installer.invocation import listings_given from installer.text import _CONTROLS EVENT_KEYS: dict[str, tuple[str, ...]] = { @@ -220,8 +221,7 @@ def _event_mode(args: argparse.Namespace) -> str: return "check" if args.dry_run: return "dry-run" - if (args.list_platforms or args.list_targets or args.list_systems - or args.list_cores or args.list_emulators): + if listings_given(args): return "list" return "install" diff --git a/installer/invocation.py b/installer/invocation.py index 267693518..2974cea52 100644 --- a/installer/invocation.py +++ b/installer/invocation.py @@ -35,6 +35,18 @@ _COMMAND_ORDER = ( ) +# The options that print a list and install nothing, in the order a run +# names them. +LISTING_FLAGS = (("--list-platforms", "list_platforms"), ("--list-targets", "list_targets"), + ("--list-systems", "list_systems"), ("--list-cores", "list_cores"), + ("--list-emulators", "list_emulators")) + + +def listings_given(args: argparse.Namespace) -> list[str]: + """The listing options of a run, as typed.""" + return [flag for flag, attr in LISTING_FLAGS if getattr(args, attr)] + + def _command_rank(option: tuple[str, str | None]) -> int: flag = option[0] return _COMMAND_ORDER.index(flag) if flag in _COMMAND_ORDER else len(_COMMAND_ORDER) diff --git a/installer/tui_routes.py b/installer/tui_routes.py index 5dbeed367..837ec9dd7 100644 --- a/installer/tui_routes.py +++ b/installer/tui_routes.py @@ -9,6 +9,7 @@ import sys from collections.abc import Mapping from typing import TYPE_CHECKING, NamedTuple, TextIO +from installer.invocation import LISTING_FLAGS from installer.terminal import TUI_MIN_COLS, TUI_MIN_ROWS, _enable_ansi, terminal_few_colours, terminal_without_ansi from installer.text import screen_text @@ -194,9 +195,8 @@ def _tui_flag_blocker(args: argparse.Namespace) -> str: """The option of a run without questions, said as the reason.""" for flag, given in ( ("--check", args.check), ("--dry-run", args.dry_run), - ("--list-platforms", args.list_platforms), ("--list-targets", args.list_targets), - ("--list-systems", args.list_systems), ("--list-cores", args.list_cores), - ("--list-emulators", args.list_emulators), ("--events", args.events), + *((flag, getattr(args, attr)) for flag, attr in LISTING_FLAGS), + ("--events", args.events), ("--quiet", args.quiet), ("--yes", args.yes), ("--no-input", args.no_input), ("--restore", args.restore is not None), ("--pack", getattr(args, "pack", None) is not None),