refactor: read offline from the screen state

The rows asked state.offline while the plan, the estimate and the
result read the environment, kept in step only by the session loop.
tui_offline_only(state) is the one question; the variable only carries
the choice to the runs and the wording.
This commit is contained in:
Abdessamad Derraz committed 2026-11-22 00:58:06 +01:00
1 parent af34c81d71
commit 9f3fc2e0c1
10 files changed
+63 -47

No files matched your search

+4 -3
View File
@@ -15,7 +15,7 @@ from installer.frontend_folders import save_directory_for, save_where_words
from installer.games import GAMES_REASONS
from installer.manifest import OTHER_SYSTEMS, entry_copies
from installer.narrowing import narrow
from installer.offline import LOCAL, _offline_only
from installer.offline import LOCAL
from installer.pack_source import pack_holds_trees, pack_lacks
from installer.paths import SavePlace, spelled
from installer.plan_words import NO_CORE_FILES, _core_sized, emptied_words
@@ -26,6 +26,7 @@ from installer.tally import tally
from installer.text import _names_and, _plural, agree
from installer.tui_commands import _core_base, _tui_system_flags, _tui_systems_chosen, tui_flags, tui_run_files
from installer.tui_paint import _detail, _short_path
from installer.tui_state import tui_offline_only
if TYPE_CHECKING:
from installer.tally import Tally
@@ -219,7 +220,7 @@ def _tui_estimating(state: TuiState) -> bool:
check itself."""
if not (_choice_line(state) and state.systems and state.check is not None):
return False
if _offline_only():
if tui_offline_only(state):
# Offline the estimate is of the ticks alone: a folder to copy from
# is counted by the check it starts.
def ticked(flags: list) -> list:
@@ -550,7 +551,7 @@ def _ticked_estimate(state: TuiState) -> tuple[int, int]:
data files in them, or offline what the folders copied from hold: the
plan's headline and its Install row both say it. One system ticked,
the headline said 82.2 MB and Install 6.6 GB, the whole list's size."""
if _offline_only():
if tui_offline_only(state):
held = _ticked_held(state)
return len(held), sum(event["size"] for event in held)
chosen = _ticked_files(state)
+3 -2
View File
@@ -11,7 +11,7 @@ from installer.from_folders import sources_line
from installer.handheld_app import NO_PYTHON_CARDS, app_lines, no_python_words
from installer.host_fs import NOT_WRITABLE
from installer.invocation import Invocation
from installer.offline import LOCAL, _offline_only, offline_named
from installer.offline import LOCAL, offline_named
from installer.outcome import (
EVERYTHING_IN_PLACE,
NEXT_ON_CARD,
@@ -33,6 +33,7 @@ from installer.tui_commands import _removing_misplaced, _tui_card, _tui_installe
from installer.tui_paint import _FOLDER_LABEL, _command_line, _detail, _details, _short_path, _styled
from installer.tui_plan_view import _commands, _saves_lines, _unavailable_brief, _unavailable_lines, _unplaced_lines
from installer.tui_routes import TUI_PAD_ROUTES
from installer.tui_state import tui_offline_only
if TYPE_CHECKING:
from installer.tui_state import TuiState
@@ -97,7 +98,7 @@ def _outcome_counts(state: TuiState) -> _OutcomeCounts:
offline_failed = [failure for failure in failed if _offline_failure(failure["reason"])]
failed = [failure for failure in failed if not _offline_failure(failure["reason"])]
left = len(offline_failed) + (max(0, summary.get("pending", 0) - len(failed))
if _offline_only() and not offline_failed else 0)
if tui_offline_only(state) and not offline_failed else 0)
up_to_date = summary.get("up_to_date", 0)
total = (state.download or {}).get("files", 0)
space = "" if summary else state.full_drive
+5 -4
View File
@@ -9,7 +9,7 @@ from installer.from_folders import MAX_SCANNED_FILES
from installer.frontend_folders import save_where_words
from installer.install_record import record_changes, record_says
from installer.manifest import GAME_DATA, OTHER_SYSTEMS
from installer.offline import LOCAL, _offline_only, offline_named, offline_undo
from installer.offline import LOCAL, offline_named, offline_undo
from installer.outcome import EVERYTHING_IN_PLACE, _offline_remedy, write_remedy
from installer.pack_source import pack_lacks_words
from installer.paths import shown_path
@@ -57,6 +57,7 @@ from installer.tui_frame import _compose, _text_lines
from installer.tui_paint import _FOLDER_LABEL, _command_line, _detail, _details, _is_detail, _short_path, _styled
from installer.tui_routes import TUI_PAD_ROUTES
from installer.tui_rows import _plan_rows, tui_rows
from installer.tui_state import tui_offline_only
if TYPE_CHECKING:
from installer.tui_paint import TuiLine
@@ -116,7 +117,7 @@ def _plan_figures(check: dict, state: TuiState) -> _PlanFigures:
fetch_bytes = fetched - (check.get("data_bytes", 0) if data else 0)
elsewhere = (_tui_found_elsewhere(state, set(copied) if dry else None)
if check is state.check or dry else {})
offline = _offline_only()
offline = tui_offline_only(state)
# The data files are files to fetch like the others: one count and one
# size, the kinds apart on the line under the folder. "8358 files and
# 2636 data files" read as two kinds of one thing.
@@ -438,7 +439,7 @@ def _estimated_head(state: TuiState, check: dict, lines: list, data: int) -> lis
count, size = _ticked_estimate(state)
lines[0] = _styled(f"About {_plural(count, 'file')}, {format_size(size)}"
f", for {len(state.ticked)} of {len(state.systems)} systems", "title")
if _offline_only():
if tui_offline_only(state):
# Offline, what the folders copied from hold of the systems
# ticked: the plan counted the whole list beside "For your 1 of
# 11 systems".
@@ -523,7 +524,7 @@ def _plan_kinds(state: TuiState, check: dict, estimating: bool, data: int,
# above it: inserted second, it pushed the folder off a 40x12 plan.
kinds_of = (_ticked_files(state) if estimating else
[event for event in state.files if event["state"] != "present"])
found = (_tui_found_elsewhere(state) if not estimating and _offline_only()
found = (_tui_found_elsewhere(state) if not estimating and tui_offline_only(state)
and state.check is check else {})
if found:
# Some were found in a folder: the kinds split those the headline
+3 -8
View File
@@ -74,7 +74,7 @@ from installer.tui_commands import (
)
from installer.tui_folder_scan import FolderScan
from installer.tui_paint import _short_path
from installer.tui_state import TUI_MAX_WIDTH, TuiRow, _matches
from installer.tui_state import TUI_MAX_WIDTH, TuiRow, _matches, tui_offline_only
if TYPE_CHECKING:
from installer.tui_state import TuiState
@@ -242,11 +242,6 @@ def _core_screen_rows(state: TuiState) -> list[TuiRow]:
return rows + _CHECKLIST_END
def _tui_offline_only(state: TuiState) -> bool:
"""Without the internet and without a pack: what is not here cannot come."""
return state.offline and LOCAL.pack is None
def _confirm_screen_rows(state: TuiState) -> list[TuiRow]:
"""The rows of the confirm screen."""
if state.running or state.dry is None:
@@ -255,7 +250,7 @@ def _confirm_screen_rows(state: TuiState) -> list[TuiRow]:
# Counted again, every file is in place: Install wrote nothing
# and said Done.
return [TuiRow("close", "Close"), TuiRow("back", "Back")]
if _tui_offline_only(state) and not _dry_copies(state):
if tui_offline_only(state) and not _dry_copies(state):
# The plan's rule: Install would only fail every file.
return [TuiRow("back", "Back")]
return [TuiRow("install", "Install"), TuiRow("back", "Back")]
@@ -330,7 +325,7 @@ def _plan_rows(state: TuiState) -> list[TuiRow]:
label = (f"{TUI_INSTALL_ROW} {format_size(size)}" if size >= CONFIRM_FROM_BYTES
else TUI_INSTALL_ROW)
rows = [TuiRow("install", label)]
if _tui_offline_only(state) and not _plan_copies(state, check):
if tui_offline_only(state) and not _plan_copies(state, check):
# Nothing here to copy, and the network refused: Install would
# only fail every file, in this folder or another.
rows = []
+8
View File
@@ -7,6 +7,7 @@ from pathlib import Path
from typing import TYPE_CHECKING, NamedTuple
from installer.invocation import offline_requested
from installer.offline import LOCAL
if TYPE_CHECKING:
from installer.handheld_app import CardApp
@@ -374,3 +375,10 @@ class TuiState:
@property
def screen(self) -> str:
return self.stack[-1]
def tui_offline_only(state: TuiState) -> bool:
"""Without the internet and without a pack: what is not here cannot
come. The screens ask state.offline, never the environment, which only
carries the choice to the runs."""
return state.offline and LOCAL.pack is None