fix: a full drive is an event, not stderr text

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 19:51:02 +01:00
1 parent 0b0bf29089
commit 8fc294ef97
15 files changed
+457 -491

No files matched your search

+7 -1
View File
@@ -42,8 +42,14 @@ EVENT_KEYS: dict[str, tuple[str, ...]] = {
# targets (the board list a run cannot go on without, reason: the
# manifest's codes, http for a refused answer) or pack (--from-pack,
# reason: invalid, other_platform for a pack of another platform, or
# no_platform when none is named and the pack does not say).
# no_platform when none is named and the pack does not say) or space
# (reason: drive_full, the drive cannot hold the download, after
# no_space, before any file of the setup is written).
"error": ("stage", "reason", "platform", "message"),
# Right before the error of stage space: the BIOS folder, and the bytes
# the run needs and the drive has free. A kind of its own, since schema
# 1 never adds a key to error.
"no_space": ("platform", "folder", "bytes_needed", "bytes_free"),
# A folder named with --from, once read: the files it holds (counted
# up to MAX_SCANNED_FILES, truncated past them), and the folders below
# it on another drive, not entered.
+10 -3
View File
@@ -7,6 +7,7 @@ from pathlib import Path
from typing import TYPE_CHECKING
from installer.datadirs import data_fetch_bytes
from installer.events import EVENTS
from installer.invocation import _INVOCATION
from installer.narrowing import _filter_by_target
from installer.offline import LOCAL, _offline_only, offline_named, offline_undo
@@ -14,7 +15,7 @@ from installer.outcome import EVERYTHING_IN_PLACE
from installer.paths import shown_path
from installer.plan_words import _sized
from installer.platforms import OTHER_TITLE, entry_systems, system_title
from installer.space import free_space
from installer.space import space_shortfall
from installer.tally import _bytes, parts_words, tally
from installer.terminal import terminal_size
from installer.text import _plural, cell_width, format_size
@@ -242,9 +243,15 @@ def _check_free_space(bios_path: Path, needed: int, plat: str = "", code: int =
the status a script reads as "nothing installed", 1 after an earlier
platform of the run installed files.
"""
free = free_space(bios_path)
if free is None or free >= needed:
shortfall = space_shortfall(bios_path, needed)
if shortfall is None:
return
free = shortfall[1]
EVENTS.emit("no_space", platform=plat, folder=str(bios_path), bytes_needed=needed,
bytes_free=free)
EVENTS.emit("error", stage="space", reason="drive_full", platform=plat,
message=f"Not enough space on the drive holding {bios_path}: "
f"{format_size(needed)} needed, {format_size(free)} free.")
print(f"\nNot enough space on the drive holding {bios_path}.", file=sys.stderr)
print(f" Needed: {format_size(needed)}. Free: {format_size(free)}.",
file=sys.stderr)
+7
View File
@@ -26,3 +26,10 @@ def free_space(bios_path: Path) -> int | None:
return shutil.disk_usage(_nearest_folder(bios_path)).free
except OSError:
return None
def space_shortfall(bios_path: Path, needed: int) -> tuple[int, int] | None:
"""Needed and free when the drive holding bios_path cannot hold needed
bytes, else None, also when its free space cannot be told."""
free = free_space(bios_path)
return None if free is None or free >= needed else (needed, free)
+7 -15
View File
@@ -1,7 +1,6 @@
"""The result screen: what an install, a pack or a More action did, in words."""
from __future__ import annotations
import re
from pathlib import Path
from typing import TYPE_CHECKING, NamedTuple
@@ -38,24 +37,17 @@ from installer.tui_routes import TUI_PAD_ROUTES
if TYPE_CHECKING:
from installer.tui_state import TuiState
_SPACE_NEEDED = re.compile(r"Needed: (\S+ \S+)\. Free: (\S+ \S+)\.")
def _space_stop(state: TuiState) -> re.Match | None:
"""Needed and free, when the run stopped for lack of space."""
return next(filter(None, (_SPACE_NEEDED.search(line) for line in state.tail)), None)
def full_drive_words(state: TuiState) -> str:
"""The run's stop for lack of space, in words, "" for another stop: read
once, when the run ends."""
match = _space_stop(state)
if match is None:
"""The run's stop for lack of space (its no_space event), in words, ""
for another stop: read once, when the run ends."""
if state.no_space is None:
return ""
needed, free = state.no_space
dest = (state.dest or Path(".")).absolute()
card = any((mount == dest or mount in dest.parents) and card_system(mount)
for mount in _mounted_cards())
return f"The {'card' if card else 'drive'} is full: {match[1]} needed, {match[2]} free."
return (f"The {'card' if card else 'drive'} is full: {format_size(needed)} needed, "
f"{format_size(free)} free.")
def _tui_sources(state: TuiState, installed: int, missing: int, wrong: int = 0,
@@ -428,7 +420,7 @@ def tui_keeps_log(state: TuiState) -> bool:
return True
# A full card is said in words on the screen: its log adds nothing.
return (bool(state.log) and state.code not in (0, 130, None)
and _space_stop(state) is None)
and not state.full_drive)
def _removal_text(state: TuiState) -> list:
+4
View File
@@ -177,6 +177,9 @@ def _take_event(state: TuiState, event: dict) -> None:
if _take_action_event(state, event):
return
kind = event.get("event")
if kind == "no_space":
state.no_space = (event["bytes_needed"], event["bytes_free"])
return
if kind == "checking" and state.run in ("check", "install"):
state.reading = (event["files_done"], event["files_total"])
elif kind == "games_reading" and state.run in ("check", "install"):
@@ -315,6 +318,7 @@ def tui_receive(state: TuiState, message: tuple) -> list[tuple]:
state.tail = [line for line in tail if not line.startswith("RetroBIOS ")]
tail = state.tail
state.full_drive = full_drive_words(state)
state.no_space = None
if state.run in TUI_ACTION_RUNS:
return _action_ended(state, code, tail)
if state.run == "check":
+2
View File
@@ -286,6 +286,8 @@ class TuiState:
# The run's stop for lack of space in words, read when it ended: the
# result screen looked through the mounted drives on every frame.
self.full_drive: str = ""
# Needed and free bytes, from the no_space event of the run going on.
self.no_space: tuple[int, int] | None = None
self.log: str = ""
self.exit_code: int | None = None
# The RetroBIOS app on the card the BIOS folder is on: asked for