diff --git a/install.ps1 b/install.ps1 index cbb7fda4e..c22fbcad6 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 = "1e45d5dd7b8904b85e9ce9cf30235e818e894b78099569476f0798b8ed4b90d0" + $defaultInstallSha256 = "1fb588c9bcfea3bcd391237d1974a9a47a1565c699d5fab346efee008034bafb" # 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 d6b068850..4b0afc6d2 100644 --- a/install.py +++ b/install.py @@ -20951,7 +20951,7 @@ def folder_warnings(plat: str, bios_path: Path, files: list[dict], hint: Invocat lines += cannot_write_words(bios_path, plat, hint, commands, card) short = _space_short(bios_path, files, trees) if short is not None: - lines.append(space_words(short[0], short[1], card)) + lines += space_words(short[0], short[1], card, False, plat, hint, commands) return lines @@ -20973,14 +20973,41 @@ def cannot_write_words(bios_path: Path, plat: str, hint: Invocation, commands: b return [f"{CANNOT_WRITE}: {another}."] + said -def space_words(needed: int, free: int, card: bool) -> str: - """Not enough room, and what to do: on a card setup's own card, room is - made on the card, another folder being one its system does not read.""" +def space_remedy(short: int, plat: str, hint: Invocation | None, commands: bool = True, + card: bool = False, screen: bool = False, refused: bool = False) -> list[str]: + """What makes room for a run its drive cannot hold, the one remedy of the + plan and of the run's refusal (refused): on a card setup's own card, room + made there, another folder being one its system does not read; on the + screen, its folder row. Line mode has no folder row, so it and the + refusal name --dest, as the command once the platform is named. A second + line is that command.""" if card: - return (f"Not enough free space: {format_size(needed)} needed, " - f"{format_size(free)} free. Free some space on the card first.") - return (f"Not enough free space: {format_size(needed)} needed. Free some, or " - "choose another folder.") + # Its system reads this card alone: another drive, with RetroArch's + # list, was offered for an Onion card. + if refused: + return [f"Free up {format_size(short)} on the card, then run it again: its system " + "reads its BIOS files there only."] + return ["Free some space on the card first."] + if screen: + return ["Free some, or choose another folder."] + if not commands: + return [f"Free up {format_size(short)}, or run it again and choose another folder."] + if not plat or hint is None: + return [f"Free up {format_size(short)}, or use --dest to install to another drive."] + # --dest alone used to mean RetroArch's list: the platform is named, so + # a Batocera install moved to a USB drive stays Batocera's. + return [f"Free up {format_size(short)}, or install to another drive:", + hint.command(plat, "")] + + +def space_words(needed: int, free: int, card: bool, screen: bool = True, plat: str = "", + hint: Invocation | None = None, commands: bool = True) -> list[str]: + """Not enough room before the question, and what to do (space_remedy).""" + said = f"Not enough free space: {format_size(needed)} needed" + if card: + said += f", {format_size(free)} free" + remedy = space_remedy(needed - free, plat, hint, commands, card, screen) + return [f"{said}. {remedy[0]}"] + remedy[1:] def unlisted_saves_words(display: str) -> str: @@ -21855,19 +21882,8 @@ def _check_free_space(bios_path: Path, needed: int, plat: str = "", code: int = bytes_free=free) lines = [f"\nNot enough space on the drive holding {bios_path}.", f" Needed: {format_size(needed)}. Free: {format_size(free)}."] - if card: - # Its system reads this card alone: another drive, with RetroArch's - # list, was offered for an Onion card. - lines.append(f" Free up {format_size(needed - free)} on the card, then run it " - "again: its system reads its BIOS files there only.") - elif not plat: - lines.append(f" Free up {format_size(needed - free)}, or use --dest to install " - "to another drive.") - else: - # --dest alone used to mean RetroArch's list: the platform is named, so - # a Batocera install moved to a USB drive stays Batocera's. - lines.append(f" Free up {format_size(needed - free)}, or install to another " - f"drive:\n {_INVOCATION.command(plat, '')}") + remedy = space_remedy(needed - free, plat, _INVOCATION, card=card, refused=True) + lines.append(" " + "\n ".join(remedy)) raise Refusal("space", "drive_full", plat, *lines, code=code, message=f"Not enough space on the drive holding {bios_path}: " f"{format_size(needed)} needed, {format_size(free)} free.") @@ -26839,7 +26855,7 @@ def _plan_lines(check: dict, dest: Path | None, state: TuiState) -> list: if free is not None: lines.append(_detail(f"Free space: {format_size(free)}")) if space_needed(check) > free: - lines.append(space_words(space_needed(check), free, _on_its_card(state))) + lines += space_words(space_needed(check), free, _on_its_card(state)) backup = _plan_backups(check, state, fig) misplaced = _tui_misplaced(state) if check is state.check else [] if misplaced: diff --git a/install.sh b/install.sh index 0d59df1a9..029613836 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="1e45d5dd7b8904b85e9ce9cf30235e818e894b78099569476f0798b8ed4b90d0" +DEFAULT_INSTALL_SHA256="1fb588c9bcfea3bcd391237d1974a9a47a1565c699d5fab346efee008034bafb" # 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 00b1d7efd..800b88387 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": 1472446, - "sha256": "1e45d5dd7b8904b85e9ce9cf30235e818e894b78099569476f0798b8ed4b90d0", + "size": 1473352, + "sha256": "1fb588c9bcfea3bcd391237d1974a9a47a1565c699d5fab346efee008034bafb", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1526071, - "sha256": "c1edcd8b80fc5c49064937cf0214ff336160fa082c4d0e6df961f0a1c84c16d6" + "size": 1526977, + "sha256": "5a5101c98833239883e318087d4c6e60e8de515794f962fe8e2ac71672cdd731" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1472446, - "sha256": "1e45d5dd7b8904b85e9ce9cf30235e818e894b78099569476f0798b8ed4b90d0", + "size": 1473352, + "sha256": "1fb588c9bcfea3bcd391237d1974a9a47a1565c699d5fab346efee008034bafb", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1472446, - "sha256": "1e45d5dd7b8904b85e9ce9cf30235e818e894b78099569476f0798b8ed4b90d0", + "size": 1473352, + "sha256": "1fb588c9bcfea3bcd391237d1974a9a47a1565c699d5fab346efee008034bafb", "executable": false }, { diff --git a/installer/plan.py b/installer/plan.py index 9e5ce9978..6527441f8 100644 --- a/installer/plan.py +++ b/installer/plan.py @@ -12,7 +12,7 @@ from installer.narrowing import _filter_by_target from installer.offline import LOCAL, _offline_only, offline_named, offline_undo from installer.outcome import EVERYTHING_IN_PLACE from installer.paths import shown_path -from installer.plan_words import _sized +from installer.plan_words import _sized, space_remedy from installer.platforms import OTHER_TITLE, entry_systems, system_title from installer.refusal import Refusal from installer.space import space_shortfall @@ -251,19 +251,8 @@ def _check_free_space(bios_path: Path, needed: int, plat: str = "", code: int = bytes_free=free) lines = [f"\nNot enough space on the drive holding {bios_path}.", f" Needed: {format_size(needed)}. Free: {format_size(free)}."] - if card: - # Its system reads this card alone: another drive, with RetroArch's - # list, was offered for an Onion card. - lines.append(f" Free up {format_size(needed - free)} on the card, then run it " - "again: its system reads its BIOS files there only.") - elif not plat: - lines.append(f" Free up {format_size(needed - free)}, or use --dest to install " - "to another drive.") - else: - # --dest alone used to mean RetroArch's list: the platform is named, so - # a Batocera install moved to a USB drive stays Batocera's. - lines.append(f" Free up {format_size(needed - free)}, or install to another " - f"drive:\n {_INVOCATION.command(plat, '')}") + remedy = space_remedy(needed - free, plat, _INVOCATION, card=card, refused=True) + lines.append(" " + "\n ".join(remedy)) raise Refusal("space", "drive_full", plat, *lines, code=code, message=f"Not enough space on the drive holding {bios_path}: " f"{format_size(needed)} needed, {format_size(free)} free.") diff --git a/installer/plan_words.py b/installer/plan_words.py index 8d3bf3a27..a69f916bb 100644 --- a/installer/plan_words.py +++ b/installer/plan_words.py @@ -183,7 +183,7 @@ def folder_warnings(plat: str, bios_path: Path, files: list[dict], hint: Invocat lines += cannot_write_words(bios_path, plat, hint, commands, card) short = _space_short(bios_path, files, trees) if short is not None: - lines.append(space_words(short[0], short[1], card)) + lines += space_words(short[0], short[1], card, False, plat, hint, commands) return lines @@ -205,14 +205,41 @@ def cannot_write_words(bios_path: Path, plat: str, hint: Invocation, commands: b return [f"{CANNOT_WRITE}: {another}."] + said -def space_words(needed: int, free: int, card: bool) -> str: - """Not enough room, and what to do: on a card setup's own card, room is - made on the card, another folder being one its system does not read.""" +def space_remedy(short: int, plat: str, hint: Invocation | None, commands: bool = True, + card: bool = False, screen: bool = False, refused: bool = False) -> list[str]: + """What makes room for a run its drive cannot hold, the one remedy of the + plan and of the run's refusal (refused): on a card setup's own card, room + made there, another folder being one its system does not read; on the + screen, its folder row. Line mode has no folder row, so it and the + refusal name --dest, as the command once the platform is named. A second + line is that command.""" if card: - return (f"Not enough free space: {format_size(needed)} needed, " - f"{format_size(free)} free. Free some space on the card first.") - return (f"Not enough free space: {format_size(needed)} needed. Free some, or " - "choose another folder.") + # Its system reads this card alone: another drive, with RetroArch's + # list, was offered for an Onion card. + if refused: + return [f"Free up {format_size(short)} on the card, then run it again: its system " + "reads its BIOS files there only."] + return ["Free some space on the card first."] + if screen: + return ["Free some, or choose another folder."] + if not commands: + return [f"Free up {format_size(short)}, or run it again and choose another folder."] + if not plat or hint is None: + return [f"Free up {format_size(short)}, or use --dest to install to another drive."] + # --dest alone used to mean RetroArch's list: the platform is named, so + # a Batocera install moved to a USB drive stays Batocera's. + return [f"Free up {format_size(short)}, or install to another drive:", + hint.command(plat, "")] + + +def space_words(needed: int, free: int, card: bool, screen: bool = True, plat: str = "", + hint: Invocation | None = None, commands: bool = True) -> list[str]: + """Not enough room before the question, and what to do (space_remedy).""" + said = f"Not enough free space: {format_size(needed)} needed" + if card: + said += f", {format_size(free)} free" + remedy = space_remedy(needed - free, plat, hint, commands, card, screen) + return [f"{said}. {remedy[0]}"] + remedy[1:] def unlisted_saves_words(display: str) -> str: diff --git a/installer/tui_plan_view.py b/installer/tui_plan_view.py index a770a75b6..ae062a92c 100644 --- a/installer/tui_plan_view.py +++ b/installer/tui_plan_view.py @@ -318,7 +318,7 @@ def _plan_lines(check: dict, dest: Path | None, state: TuiState) -> list: if free is not None: lines.append(_detail(f"Free space: {format_size(free)}")) if space_needed(check) > free: - lines.append(space_words(space_needed(check), free, _on_its_card(state))) + lines += space_words(space_needed(check), free, _on_its_card(state)) backup = _plan_backups(check, state, fig) misplaced = _tui_misplaced(state) if check is state.check else [] if misplaced: diff --git a/tests/test_install_tui.py b/tests/test_install_tui.py index 0c59b4684..d6a354c90 100644 --- a/tests/test_install_tui.py +++ b/tests/test_install_tui.py @@ -7980,6 +7980,25 @@ class _LineModeFindings(_CardFixtures): lines = install.folder_warnings("retroarch", self.root, [], hint, True, True) self.assertEqual(lines, [install.read_only_words(self.root)]) + def test_line_mode_names_the_way_to_another_drive(self): + """The line plan said "choose another folder", a choice the line menu + does not have, and the refusal after Enter named --dest: both name + the same command now.""" + hint = install.Invocation() + with mock.patch.object(install, "_space_short", return_value=(5000, 1000)), \ + mock.patch.object(install, "_folder_writable", return_value=True): + lines = install.folder_warnings("batocera", self.root, [], hint, True, False) + command = hint.command("batocera", "") + self.assertEqual(lines, ["Not enough free space: 4.9 KB needed. Free up 3.9 KB, " + "or install to another drive:", command]) + with mock.patch.object(install.shutil, "disk_usage", + return_value=mock.Mock(free=1000)), \ + contextlib.redirect_stderr(io.StringIO()) as err, \ + self.assertRaises(SystemExit): + reported(install._check_free_space, self.root, 5000, "batocera") + self.assertIn(" Free up 3.9 KB, or install to another drive:\n " + command, + err.getvalue()) + def test_the_plan_warns_on_the_space_the_run_refuses_on(self): """The screen held the files missing or wrong against the free space, the run those and the data trees: a plan without a warning stopped