From 77115be7380550c1ae2d4cc07dc45278a8e97b83 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:35:01 +0100 Subject: [PATCH] refactor: the run decides what it fetches, once --- install.ps1 | 2 +- install.py | 232 +++++++++++++++---------- install.sh | 2 +- install/launchers/index.json | 16 +- installer/events.py | 9 + installer/fetch_plan.py | 61 +++++++ installer/run.py | 47 +++-- installer/run_files.py | 2 + installer/tui_choice.py | 91 ++++------ installer/tui_plan_view.py | 22 +-- installer/tui_receive.py | 4 + installer/tui_rows.py | 16 +- schemas/install-events.schema.json | 54 ++++++ scripts/installer_build/eventschema.py | 6 +- tests/test_install.py | 4 + tests/test_install_pack.py | 48 +++++ tests/test_install_tui.py | 107 ++++++++---- wiki/architecture.md | 2 +- wiki/installer.md | 1 + 19 files changed, 490 insertions(+), 236 deletions(-) create mode 100644 installer/fetch_plan.py diff --git a/install.ps1 b/install.ps1 index 676cc16ba..a2d111d25 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 = "6f5ccd34b7095ddf994648e8596ad30349e5b181517a535731f34f7440787605" + $defaultInstallSha256 = "d965c45c0fd7aa15d3376e06467644e6762f87bbc1f8f6d3e61891020bcfe9d3" # 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 c3dd0e321..ceaa54b8d 100644 --- a/install.py +++ b/install.py @@ -1547,6 +1547,15 @@ EVENT_KEYS: dict[str, tuple[str, ...]] = { # hold against the free space. A kind of its own, since schema 1 never # adds a key to check. "space": ("platform", "bytes"), + # Right after space: what an install fetches, decided once by the run. + # files and bytes come from the network, or from the pack when one is + # given and holds them. copied: the dests a copy on this machine gives + # (each named by a found event), lacking: the dests the pack does not + # hold, data_files and data_bytes: the data trees' files the run brings + # (none from a pack that holds no tree). A kind of its own, since + # schema 1 never adds a key to check. + "fetch_plan": ("platform", "files", "bytes", "copied", "lacking", "data_files", + "data_bytes"), # A file to install that this machine already holds: misplaced in the # BIOS folder (folder is its bios_dir, reason says why in words) or in # a folder named with --from (reason empty). member names the ZIP member @@ -17819,6 +17828,59 @@ def select_data_directories(manifest: dict, files: list[dict], narrowed: bool, or (other and not e.get("systems"))] +# --- installer/fetch_plan.py ------------------------------------------------- + +class FetchPlan(NamedTuple): + """The files a run fetches, decided once for --check, --dry-run, the + install and the screen's plan, which reads it from the fetch_plan event.""" + + copied: list[dict] + fetched: list[dict] + lacking: list[dict] + data_files: int + data_bytes: int + + @property + def coming(self) -> list[dict]: + """The files fetched that the pack, when one is given, holds.""" + return self.without_lacking(self.fetched) + + def without_lacking(self, entries: list[dict]) -> list[dict]: + """entries without those the pack lacks: the files a run writes.""" + lacking = {id(entry) for entry in self.lacking} + return [entry for entry in entries if id(entry) not in lacking] + + +def fetch_plan(to_download: list[dict], copies: dict, + data_states: list[tuple[dict, tuple[Path, dict[str, dict], int]]]) -> FetchPlan: + """The files to install that no copy on this machine gives, those of + them the pack lacks, and the data files the run brings: all of them + from the network, from a pack only when it holds the trees. The screen + counted the data files from a pack that held none, --check left them + out of a pack that held them all.""" + copied = [entry for entry in to_download if id(entry) in copies] + fetched = [entry for entry in to_download if id(entry) not in copies] + trees = LOCAL.pack is None or pack_holds_trees([entry for entry, _state in data_states]) + return FetchPlan( + copied, fetched, pack_lacks(fetched), + sum(len(state[1]) for _entry, state in data_states) if trees else 0, + sum(data_fetch_bytes(entry, state[1]) for entry, state in data_states) if trees else 0, + ) + + +def emit_fetch_plan(plat: str, plan: FetchPlan) -> None: + """The plan as the screen reads it: files and bytes from the network or + the pack, the dests copied from this machine, those the pack lacks.""" + coming = plan.coming + EVENTS.emit( + "fetch_plan", platform=plat, files=len(coming), + bytes=sum(entry.get("size", 0) for entry in coming), + copied=[entry["dest"] for entry in plan.copied], + lacking=[entry["dest"] for entry in plan.lacking], + data_files=plan.data_files, data_bytes=plan.data_bytes, + ) + + # --- installer/handheld_app.py ----------------------------------------------- # The RetroBIOS app on a handheld's card. A card prepared on a computer can @@ -22154,6 +22216,7 @@ class _PlatformPass: self.bios_index: FolderIndex | None = None self.copies: dict[int, LocalCopy] = {} self.unread: list[Unreadable] = [] + self.plan = FetchPlan([], [], [], 0, 0) self.hint: list[str] = [] self.space_checked = False @@ -23586,6 +23649,7 @@ def _pass_check_existing(run: _InstallRun, p: _PlatformPass) -> None: if bios_index is not None: run.bios_indexes.append(bios_index) p.copies = copies = plan_local_copies(to_download, bios_path, bios_index, LOCAL.folders) + p.plan = plan = fetch_plan(to_download, copies, data_states) p.unread = unread = unreadable_copies(to_download, copies, LOCAL.folders) selection = p.selection p.hint = [] if LOCAL.pack is not None else bulk_hint( @@ -23599,17 +23663,16 @@ def _pass_check_existing(run: _InstallRun, p: _PlatformPass) -> None: if EVENTS.on: # What the run would write, as _pass_download holds it against the # free space: the screen's plan warns on this number. - lacking = {id(f) for f in pack_lacks([f for f in to_download if id(f) not in copies])} _emit_check( p.plat_name, p.manifest, bios_path, CheckTally(files, up_to_date, mismatched, sum(len(state[1]) for _entry, state in data_states), len(p.omitted_files), sum(data_fetch_bytes(entry, state[1]) for entry, state in data_states), - bytes_written([f for f in to_download if id(f) not in lacking], - data_states)), + bytes_written(plan.without_lacking(to_download), data_states)), chosen=selection[0] if selection else None, ) + emit_fetch_plan(p.plat_name, plan) emit_copies(p.plat_name, to_download, copies, bios_index, bios_path, files) emit_unreadable(p.plat_name, unread) run.total_verified += len(up_to_date) @@ -23618,7 +23681,7 @@ def _pass_check_existing(run: _InstallRun, p: _PlatformPass) -> None: def _pass_check_missing(run: _InstallRun, p: _PlatformPass) -> None: """--check: the files not in place named, and how to get them.""" args, bios_path = run.args, p.bios_path - to_download, mismatched, copies = p.to_download, p.mismatched, p.copies + to_download, mismatched, copies, plan = p.to_download, p.mismatched, p.copies, p.plan # Named, not only counted: a user looking for the one bad # BIOS learned "1 files need downloading" and nothing else. # A wrong hash comes first and always in full: listed after @@ -23632,9 +23695,8 @@ def _pass_check_missing(run: _InstallRun, p: _PlatformPass) -> None: offline = _offline_only() # What the pack lacks is said before the count, as the # screen says it. - lacking = pack_lacks([f for f in to_download if id(f) not in copies]) - if lacking: - print(f"\n {pack_lacks_words(len(lacking), len(to_download) - len(copies))}") + if plan.lacking: + print(f"\n {pack_lacks_words(len(plan.lacking), len(plan.fetched))}") # One total with the count above it, the data files among # them as the screen counts them: "0 in place, 10805 missing" # stood over "8164 files to download". @@ -23651,9 +23713,8 @@ def _pass_check_missing(run: _InstallRun, p: _PlatformPass) -> None: print(f" BIOS folder: {shown_path(bios_path)}") # The data files need the internet too: offline, "8164 files # need the internet" stood under "10805 files not in place". - trees_fetched = p.trees_missing if LOCAL.pack is None else 0 - print(_check_fetch_line(len(to_download) - len(copies) + trees_fetched, - "the BIOS folder", len(lacking), bool(mismatched))) + print(_check_fetch_line(len(plan.fetched) + plan.data_files, + "the BIOS folder", len(plan.lacking), bool(mismatched))) run.check_pending += len(to_download) @@ -23702,14 +23763,13 @@ def _pass_dry_run(run: _InstallRun, p: _PlatformPass) -> None: {"dest": f"{entry['dest']}/{rel}" if entry.get("dest") else rel} for entry, needed in trees for rel in needed ], bios_path) - planned = [f for f in to_download if id(f) not in copies] + plan = p.plan # Said before the plan promises a count and a size, as an # install says it: the dry run promised 23 files where the pack # held 20. - lacking = {id(f) for f in pack_lacks(planned)} - if lacking: - print(f"\n {pack_lacks_words(len(lacking), len(planned))}") - _print_plan([f for f in planned if id(f) not in lacking], bios_path, run.term, + if plan.lacking: + print(f"\n {pack_lacks_words(len(plan.lacking), len(plan.fetched))}") + _print_plan(plan.coming, bios_path, run.term, trees, kept, copy_plan_lines(to_download, copies, p.bios_index, bios_path, p.files, args.verbose, True), verbose=args.verbose, manifest=p.manifest) @@ -23796,9 +23856,8 @@ def _pass_download_head(run: _InstallRun, p: _PlatformPass, fetched: list[dict], if not p.menu: # What happens and where, the two lines a run without questions # opens on: the menu's head said them where it was asked. - coming = len(p.to_download) - len(lacking) + p.trees_missing - weight = dl_size + sum(data_fetch_bytes(entry, state[1]) - for entry, state in p.data_states) + coming = len(p.to_download) - len(lacking) + p.plan.data_files + weight = dl_size + p.plan.data_bytes taken = _RECORD_TAKEN.get(plat_name) print(f"\nInstalling {_plural(coming, 'file')} ({format_size(weight)}) for " f"{detected_shown(plat_name, bios_path) or p.display}" @@ -23906,7 +23965,8 @@ def _pass_fetch(run: _InstallRun, p: _PlatformPass, dl_size: int, created: bool) def _pass_download(run: _InstallRun, p: _PlatformPass) -> str: """The missing files installed: "go" carries on with the setup, "next" moves to the next one, "stop" ends the run.""" - fetched = [f for f in p.to_download if id(f) not in p.copies] + plan = p.plan + fetched = plan.fetched if _offline_only() and fetched: _pass_offline_left(run, p, fetched) fetched = [] @@ -23914,10 +23974,11 @@ def _pass_download(run: _InstallRun, p: _PlatformPass) -> str: # a pack older than the list gave "Copy 6.6 GB" and 8358 files # failed. They are still tried, and fail as # not in the pack, the size and the question leaving them out. - lacking = {id(f) for f in pack_lacks(fetched)} + # Offline there is no pack, so nothing is lacking. + lacking = {id(f) for f in plan.lacking} if lacking: print(f"\n {pack_lacks_words(len(lacking), len(fetched))}") - if lacking and len(lacking) == len(p.to_download) and not pack_holds_trees(p.data_dirs): + if lacking and len(lacking) == len(p.to_download) and not plan.data_files: # Nothing here can come from the pack: no "Copying 0 files", no # folder made, each file failed as not in it. run.failures.extend((f["dest"], NOT_IN_PACK) for f in p.to_download) @@ -23925,9 +23986,9 @@ def _pass_download(run: _InstallRun, p: _PlatformPass) -> str: run.files_pending += len(p.to_download) run.total_up_to_date += len(p.up_to_date) return "next" - coming = [f for f in p.to_download if id(f) not in lacking] + coming = plan.without_lacking(p.to_download) dl_size = _bytes(coming) - fetch_size = _bytes([f for f in fetched if id(f) not in lacking]) + fetch_size = _bytes(plan.without_lacking(fetched)) if not p.to_download: run.total_up_to_date += len(p.up_to_date) if _offline_only(): @@ -24782,20 +24843,10 @@ def _checked_scope(state: TuiState) -> set[str]: return set(state.checked_dests) | left if state.checked_dests or left else set() -def _plan_copies(state: TuiState, check: dict) -> list[str]: - """The files to install that this machine holds, by destination.""" - if check is state.dry and check is not state.check: - return _dry_copies(state) - local = {event["dest"] for event in state.found} if check is state.check else set() - sizes = {event["dest"] for event in state.files} - return [dest for dest in local if dest in sizes] - - -def _dry_copies(state: TuiState) -> list[str]: - """The files the confirm or preview run would install that this - machine holds.""" - local = {event["dest"] for event in state.found} - return [event["dest"] for event in state.dry_files if event["dest"] in local] +def _plan_copies(check: dict) -> list[str]: + """The files to install that this machine holds, by destination, as the + run that counted check decided it (its fetch_plan event).""" + return list((check.get("fetch_plan") or {}).get("copied") or []) def space_needed(check: dict) -> int: @@ -24960,46 +25011,39 @@ def _tui_found_elsewhere(state: TuiState, dests: set | None = None) -> dict[str, return found -def _plan_fetch(state: TuiState, check: dict) -> tuple[int, int, list, list, dict]: - """(files to fetch, bytes the install fetches with the data files', - dests copied from this machine, dests the pack lacks, the size of each - file): the one size the plan's headline and its Install row say. +class PlanFetch(NamedTuple): + """What the run that counted a check fetches, from its fetch_plan event: + the BIOS files and their bytes, the data files and theirs, the dests + copied from this machine, those the pack lacks, the size of each file.""" - A file found on this machine is copied, not downloaded: the count and - the size to download leave it out, from the check's own events. On - Confirm the dry run's files are matched the same way: it called the - files a --from folder holds downloads, and sent an offline user for a - pack. The files the pack does not hold are left out too: the plan - offered "Install 6.6 GB" from a pack that held none of them. - """ + files: int + bytes: int + data_files: int + data_bytes: int + copied: list[str] + lacking: list[str] + sizes: dict[str, int] + + @property + def size(self) -> int: + """The one size the plan's headline and its Install row say.""" + return self.bytes + self.data_bytes + + +def _plan_fetch(state: TuiState, check: dict) -> PlanFetch: + """The plan of check as the run decided it: the screen reads the + counts, never works them out again. Worked out here, a file a --from + folder held was called a download, a pack that held none of the files + offered "Install 6.6 GB", and a pack without the data trees promised + them.""" dry = check is state.dry and check is not state.check - sizes = {event["dest"]: event["size"] - for event in (state.dry_files if dry else state.files)} - copied = _plan_copies(state, check) if dry or check is state.check else [] - lacking = _tui_pack_lacks(state, [dest_ for dest_ in sizes if dest_ not in copied]) - fetch = max(0, _needed(check) - len(copied) - len(lacking)) - fetch_bytes = max(0, check.get("bytes_needed", 0) - sum(sizes[dest_] for dest_ in copied) - - sum(sizes[dest_] for dest_ in lacking)) - data_bytes = check.get("data_bytes", 0) if check.get("data_missing", 0) else 0 - return fetch, fetch_bytes + data_bytes, copied, lacking, sizes - - -def _tui_pack_trees(state: TuiState) -> bool: - """Whether the pack given to the run holds a file of the list's data - trees.""" - return pack_holds_trees((state.manifest or {}).get("data_directories") or []) - - -def _tui_pack_lacks(state: TuiState, dests: list[str]) -> list[str]: - """The destinations of a plan the pack given to the run does not hold.""" - if LOCAL.pack is None or not dests: - return [] - manifest = state.manifest or {} - entries = {str(entry.get("dest")): entry for entry in [ - *(manifest.get("files") or []), *(manifest.get("case_variants") or [])]} - held = {id(entry) for entry in pack_lacks([entries[dest] for dest in dests - if dest in entries])} - return [dest for dest in dests if dest in entries and id(entries[dest]) in held] + plan = check.get("fetch_plan") or {} + return PlanFetch( + plan.get("files", 0), plan.get("bytes", 0), plan.get("data_files", 0), + plan.get("data_bytes", 0), list(plan.get("copied") or []), + list(plan.get("lacking") or []), + {event["dest"]: event["size"] for event in (state.dry_files if dry else state.files)}, + ) def _plan_folder(state: TuiState, dest: Path | None) -> Path | None: @@ -25316,7 +25360,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 _plan_copies(state.dry): # The plan's rule: Install would only fail every file. return [TuiRow("back", "Back")] return [TuiRow("install", "Install"), TuiRow("back", "Back")] @@ -25387,18 +25431,17 @@ def _plan_rows(state: TuiState) -> list[TuiRow]: # The size the headline says: "Install 6.6 GB" stood under "14930 files # to download, 6.8 GB", the copies counted in one and the data files in # the other. - size = _ticked_estimate(state)[1] if _tui_estimating(state) else _plan_fetch(state, check)[1] + plan = _plan_fetch(state, check) + size = _ticked_estimate(state)[1] if _tui_estimating(state) else plan.size 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.copied: # Nothing here to copy, and the network refused: Install would # only fail every file, in this folder or another. rows = [] - files = {event["dest"] for event in state.files} - if (LOCAL.pack is not None and files and not _plan_copies(state, check) - and len(_tui_pack_lacks(state, sorted(files))) == len(files) - and not (check.get("data_missing") and _tui_pack_trees(state))): + if (LOCAL.pack is not None and state.files and not plan.copied + and len(plan.lacking) == len(state.files) and not plan.data_files): # The pack holds none of them, nor the data files: Install would # fail every one. rows = [] @@ -26763,6 +26806,7 @@ class _PlanFigures(NamedTuple): dry: bool fetch: int fetch_bytes: int + data_fetch: int data_bytes: int copied: list lacking: list @@ -26775,26 +26819,26 @@ def _plan_figures(check: dict, state: TuiState) -> _PlanFigures: need = _needed(check) data = check.get("data_missing", 0) dry = check is state.dry and check is not state.check - fetch, fetched, copied, lacking, sizes = _plan_fetch(state, check) - fetch_bytes = fetched - (check.get("data_bytes", 0) if data else 0) + plan = _plan_fetch(state, check) + copied = plan.copied elsewhere = (_tui_found_elsewhere(state, set(copied) if dry else None) if check is state.check or dry else {}) 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. - data_bytes = check.get("data_bytes", 0) if data else 0 - return _PlanFigures(need, data, dry, fetch, fetch_bytes, data_bytes, copied, lacking, - sizes, elsewhere, offline) + return _PlanFigures(need, data, dry, plan.files, plan.bytes, plan.data_files, + plan.data_bytes, copied, plan.lacking, + plan.sizes, elsewhere, offline) def _plan_needed_headline(check: dict, fig: _PlanFigures) -> str: """The headline of a plan with files to install.""" - need, data, fetch, copied = fig.need, fig.data, fig.fetch, fig.copied + need, data, fetch, copied = fig.need, fig.data_fetch, fig.fetch, fig.copied if fig.elsewhere: # The folder by its last name: the whole path pushed the BIOS # folder off a 40x15 screen. The Options row spells it out. The - # data files are among those to fetch: one count. + # data files the run brings are among those to fetch: one count. where = ", ".join(f"{len(events)} found in {_last_name(folder)}" for folder, events in fig.elsewhere.items()) rest = fetch + data @@ -26827,7 +26871,7 @@ def _plan_needed_headline(check: dict, fig: _PlanFigures) -> str: return f"{_plural(len(copied), 'file')} to copy from this machine" -def _plan_headline(check: dict, state: TuiState, fig: _PlanFigures) -> str: +def _plan_headline(check: dict, fig: _PlanFigures) -> str: data = fig.data # The data trees' size comes from their own event: "2636 data files" # beside "6.6 GB" said nothing of what they weigh. @@ -26839,7 +26883,7 @@ def _plan_headline(check: dict, state: TuiState, fig: _PlanFigures) -> str: if fig.lacking and not fig.fetch and not fig.copied: # The data files too, when the pack holds none of them: "8252 # files" said nothing of the 2636 it cannot give either. - lacked = len(fig.lacking) + (data if data and not _tui_pack_trees(state) else 0) + lacked = len(fig.lacking) + data - fig.data_fetch return pack_lacks_words(lacked, lacked) return _plan_needed_headline(check, fig) @@ -26933,7 +26977,7 @@ def _plan_check_lines(check: dict, state: TuiState) -> list: def _plan_lines(check: dict, dest: Path | None, state: TuiState) -> list: fig = _plan_figures(check, state) data, fetch = fig.data, fig.fetch - headline = _plan_headline(check, state, fig) + headline = _plan_headline(check, fig) wrong = check["wrong_hash"] # Where some were found, the plan names the rest by kind ("Not in old: # 10 BIOS files and 6 game data files.", _view_plan), and the remedy @@ -30984,6 +31028,8 @@ def _take_check_event(state: TuiState, kind: str | None, event: dict) -> None: state.check["data_bytes"] = event["bytes"] elif kind == "space" and state.check is not None: state.check["space_bytes"] = event["bytes"] + elif kind == "fetch_plan" and state.check is not None: + state.check["fetch_plan"] = event elif kind == "check": state.check = event elif kind == "file": @@ -31003,6 +31049,8 @@ def _take_dry_event(state: TuiState, kind: str | None, event: dict) -> None: state.dry["data_bytes"] = event["bytes"] elif kind == "space" and state.dry is not None: state.dry["space_bytes"] = event["bytes"] + elif kind == "fetch_plan" and state.dry is not None: + state.dry["fetch_plan"] = event elif kind == "check": state.dry = event elif kind == "file" and event.get("state") != "present": diff --git a/install.sh b/install.sh index f133cf4dc..c2930fe5a 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="6f5ccd34b7095ddf994648e8596ad30349e5b181517a535731f34f7440787605" +DEFAULT_INSTALL_SHA256="d965c45c0fd7aa15d3376e06467644e6762f87bbc1f8f6d3e61891020bcfe9d3" # 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 a440200f7..05e6f2498 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": 1480763, - "sha256": "6f5ccd34b7095ddf994648e8596ad30349e5b181517a535731f34f7440787605", + "size": 1481970, + "sha256": "d965c45c0fd7aa15d3376e06467644e6762f87bbc1f8f6d3e61891020bcfe9d3", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1534388, - "sha256": "46f51d49c39fb356ee7c0e32480764503f388dd0cb06096b08fb05f811f89e15" + "size": 1535595, + "sha256": "34f95a5204ff52f432713a227b21443764803b340e4edde4c8ac3a1659f554eb" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1480763, - "sha256": "6f5ccd34b7095ddf994648e8596ad30349e5b181517a535731f34f7440787605", + "size": 1481970, + "sha256": "d965c45c0fd7aa15d3376e06467644e6762f87bbc1f8f6d3e61891020bcfe9d3", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1480763, - "sha256": "6f5ccd34b7095ddf994648e8596ad30349e5b181517a535731f34f7440787605", + "size": 1481970, + "sha256": "d965c45c0fd7aa15d3376e06467644e6762f87bbc1f8f6d3e61891020bcfe9d3", "executable": false }, { diff --git a/installer/events.py b/installer/events.py index 849980933..7eea16bc9 100644 --- a/installer/events.py +++ b/installer/events.py @@ -124,6 +124,15 @@ EVENT_KEYS: dict[str, tuple[str, ...]] = { # hold against the free space. A kind of its own, since schema 1 never # adds a key to check. "space": ("platform", "bytes"), + # Right after space: what an install fetches, decided once by the run. + # files and bytes come from the network, or from the pack when one is + # given and holds them. copied: the dests a copy on this machine gives + # (each named by a found event), lacking: the dests the pack does not + # hold, data_files and data_bytes: the data trees' files the run brings + # (none from a pack that holds no tree). A kind of its own, since + # schema 1 never adds a key to check. + "fetch_plan": ("platform", "files", "bytes", "copied", "lacking", "data_files", + "data_bytes"), # A file to install that this machine already holds: misplaced in the # BIOS folder (folder is its bios_dir, reason says why in words) or in # a folder named with --from (reason empty). member names the ZIP member diff --git a/installer/fetch_plan.py b/installer/fetch_plan.py new file mode 100644 index 000000000..2481ac956 --- /dev/null +++ b/installer/fetch_plan.py @@ -0,0 +1,61 @@ +"""What a run fetches: the files no copy here gives, those the pack lacks, the data files it brings.""" +from __future__ import annotations + +from pathlib import Path +from typing import NamedTuple + +from installer.datadirs import data_fetch_bytes +from installer.events import EVENTS +from installer.offline import LOCAL +from installer.pack_source import pack_holds_trees, pack_lacks + + +class FetchPlan(NamedTuple): + """The files a run fetches, decided once for --check, --dry-run, the + install and the screen's plan, which reads it from the fetch_plan event.""" + + copied: list[dict] + fetched: list[dict] + lacking: list[dict] + data_files: int + data_bytes: int + + @property + def coming(self) -> list[dict]: + """The files fetched that the pack, when one is given, holds.""" + return self.without_lacking(self.fetched) + + def without_lacking(self, entries: list[dict]) -> list[dict]: + """entries without those the pack lacks: the files a run writes.""" + lacking = {id(entry) for entry in self.lacking} + return [entry for entry in entries if id(entry) not in lacking] + + +def fetch_plan(to_download: list[dict], copies: dict, + data_states: list[tuple[dict, tuple[Path, dict[str, dict], int]]]) -> FetchPlan: + """The files to install that no copy on this machine gives, those of + them the pack lacks, and the data files the run brings: all of them + from the network, from a pack only when it holds the trees. The screen + counted the data files from a pack that held none, --check left them + out of a pack that held them all.""" + copied = [entry for entry in to_download if id(entry) in copies] + fetched = [entry for entry in to_download if id(entry) not in copies] + trees = LOCAL.pack is None or pack_holds_trees([entry for entry, _state in data_states]) + return FetchPlan( + copied, fetched, pack_lacks(fetched), + sum(len(state[1]) for _entry, state in data_states) if trees else 0, + sum(data_fetch_bytes(entry, state[1]) for entry, state in data_states) if trees else 0, + ) + + +def emit_fetch_plan(plat: str, plan: FetchPlan) -> None: + """The plan as the screen reads it: files and bytes from the network or + the pack, the dests copied from this machine, those the pack lacks.""" + coming = plan.coming + EVENTS.emit( + "fetch_plan", platform=plat, files=len(coming), + bytes=sum(entry.get("size", 0) for entry in coming), + copied=[entry["dest"] for entry in plan.copied], + lacking=[entry["dest"] for entry in plan.lacking], + data_files=plan.data_files, data_bytes=plan.data_bytes, + ) diff --git a/installer/run.py b/installer/run.py index 0bb826007..c3fc2bc7f 100644 --- a/installer/run.py +++ b/installer/run.py @@ -15,6 +15,7 @@ from installer.detect_os import detected_shown from installer.diagnosis import CheckHeld, bios_folder_index, check_lines from installer.download import download_files from installer.events import EVENTS, _event_mode +from installer.fetch_plan import emit_fetch_plan, fetch_plan from installer.filesystems import NOMEDIA, hide_from_media_scanner from installer.from_folders import ( copy_plan_lines, @@ -53,7 +54,7 @@ from installer.outcome import ( _write_advice, ) from installer.pack import run_pack, split_pack_lines -from installer.pack_source import NOT_IN_PACK, pack_holds_trees, pack_lacks, pack_lacks_words +from installer.pack_source import NOT_IN_PACK, pack_lacks_words from installer.paths import _entry_path, shown_path from installer.plan import CONFIRM_FROM_BYTES, _check_free_space, _print_plan, bulk_hint from installer.platforms import display_name @@ -169,6 +170,7 @@ def _pass_check_existing(run: _InstallRun, p: _PlatformPass) -> None: if bios_index is not None: run.bios_indexes.append(bios_index) p.copies = copies = plan_local_copies(to_download, bios_path, bios_index, LOCAL.folders) + p.plan = plan = fetch_plan(to_download, copies, data_states) p.unread = unread = unreadable_copies(to_download, copies, LOCAL.folders) selection = p.selection p.hint = [] if LOCAL.pack is not None else bulk_hint( @@ -182,17 +184,16 @@ def _pass_check_existing(run: _InstallRun, p: _PlatformPass) -> None: if EVENTS.on: # What the run would write, as _pass_download holds it against the # free space: the screen's plan warns on this number. - lacking = {id(f) for f in pack_lacks([f for f in to_download if id(f) not in copies])} _emit_check( p.plat_name, p.manifest, bios_path, CheckTally(files, up_to_date, mismatched, sum(len(state[1]) for _entry, state in data_states), len(p.omitted_files), sum(data_fetch_bytes(entry, state[1]) for entry, state in data_states), - bytes_written([f for f in to_download if id(f) not in lacking], - data_states)), + bytes_written(plan.without_lacking(to_download), data_states)), chosen=selection[0] if selection else None, ) + emit_fetch_plan(p.plat_name, plan) emit_copies(p.plat_name, to_download, copies, bios_index, bios_path, files) emit_unreadable(p.plat_name, unread) run.total_verified += len(up_to_date) @@ -201,7 +202,7 @@ def _pass_check_existing(run: _InstallRun, p: _PlatformPass) -> None: def _pass_check_missing(run: _InstallRun, p: _PlatformPass) -> None: """--check: the files not in place named, and how to get them.""" args, bios_path = run.args, p.bios_path - to_download, mismatched, copies = p.to_download, p.mismatched, p.copies + to_download, mismatched, copies, plan = p.to_download, p.mismatched, p.copies, p.plan # Named, not only counted: a user looking for the one bad # BIOS learned "1 files need downloading" and nothing else. # A wrong hash comes first and always in full: listed after @@ -215,9 +216,8 @@ def _pass_check_missing(run: _InstallRun, p: _PlatformPass) -> None: offline = _offline_only() # What the pack lacks is said before the count, as the # screen says it. - lacking = pack_lacks([f for f in to_download if id(f) not in copies]) - if lacking: - print(f"\n {pack_lacks_words(len(lacking), len(to_download) - len(copies))}") + if plan.lacking: + print(f"\n {pack_lacks_words(len(plan.lacking), len(plan.fetched))}") # One total with the count above it, the data files among # them as the screen counts them: "0 in place, 10805 missing" # stood over "8164 files to download". @@ -234,9 +234,8 @@ def _pass_check_missing(run: _InstallRun, p: _PlatformPass) -> None: print(f" BIOS folder: {shown_path(bios_path)}") # The data files need the internet too: offline, "8164 files # need the internet" stood under "10805 files not in place". - trees_fetched = p.trees_missing if LOCAL.pack is None else 0 - print(_check_fetch_line(len(to_download) - len(copies) + trees_fetched, - "the BIOS folder", len(lacking), bool(mismatched))) + print(_check_fetch_line(len(plan.fetched) + plan.data_files, + "the BIOS folder", len(plan.lacking), bool(mismatched))) run.check_pending += len(to_download) @@ -285,14 +284,13 @@ def _pass_dry_run(run: _InstallRun, p: _PlatformPass) -> None: {"dest": f"{entry['dest']}/{rel}" if entry.get("dest") else rel} for entry, needed in trees for rel in needed ], bios_path) - planned = [f for f in to_download if id(f) not in copies] + plan = p.plan # Said before the plan promises a count and a size, as an # install says it: the dry run promised 23 files where the pack # held 20. - lacking = {id(f) for f in pack_lacks(planned)} - if lacking: - print(f"\n {pack_lacks_words(len(lacking), len(planned))}") - _print_plan([f for f in planned if id(f) not in lacking], bios_path, run.term, + if plan.lacking: + print(f"\n {pack_lacks_words(len(plan.lacking), len(plan.fetched))}") + _print_plan(plan.coming, bios_path, run.term, trees, kept, copy_plan_lines(to_download, copies, p.bios_index, bios_path, p.files, args.verbose, True), verbose=args.verbose, manifest=p.manifest) @@ -379,9 +377,8 @@ def _pass_download_head(run: _InstallRun, p: _PlatformPass, fetched: list[dict], if not p.menu: # What happens and where, the two lines a run without questions # opens on: the menu's head said them where it was asked. - coming = len(p.to_download) - len(lacking) + p.trees_missing - weight = dl_size + sum(data_fetch_bytes(entry, state[1]) - for entry, state in p.data_states) + coming = len(p.to_download) - len(lacking) + p.plan.data_files + weight = dl_size + p.plan.data_bytes taken = _RECORD_TAKEN.get(plat_name) print(f"\nInstalling {_plural(coming, 'file')} ({format_size(weight)}) for " f"{detected_shown(plat_name, bios_path) or p.display}" @@ -489,7 +486,8 @@ def _pass_fetch(run: _InstallRun, p: _PlatformPass, dl_size: int, created: bool) def _pass_download(run: _InstallRun, p: _PlatformPass) -> str: """The missing files installed: "go" carries on with the setup, "next" moves to the next one, "stop" ends the run.""" - fetched = [f for f in p.to_download if id(f) not in p.copies] + plan = p.plan + fetched = plan.fetched if _offline_only() and fetched: _pass_offline_left(run, p, fetched) fetched = [] @@ -497,10 +495,11 @@ def _pass_download(run: _InstallRun, p: _PlatformPass) -> str: # a pack older than the list gave "Copy 6.6 GB" and 8358 files # failed. They are still tried, and fail as # not in the pack, the size and the question leaving them out. - lacking = {id(f) for f in pack_lacks(fetched)} + # Offline there is no pack, so nothing is lacking. + lacking = {id(f) for f in plan.lacking} if lacking: print(f"\n {pack_lacks_words(len(lacking), len(fetched))}") - if lacking and len(lacking) == len(p.to_download) and not pack_holds_trees(p.data_dirs): + if lacking and len(lacking) == len(p.to_download) and not plan.data_files: # Nothing here can come from the pack: no "Copying 0 files", no # folder made, each file failed as not in it. run.failures.extend((f["dest"], NOT_IN_PACK) for f in p.to_download) @@ -508,9 +507,9 @@ def _pass_download(run: _InstallRun, p: _PlatformPass) -> str: run.files_pending += len(p.to_download) run.total_up_to_date += len(p.up_to_date) return "next" - coming = [f for f in p.to_download if id(f) not in lacking] + coming = plan.without_lacking(p.to_download) dl_size = _bytes(coming) - fetch_size = _bytes([f for f in fetched if id(f) not in lacking]) + fetch_size = _bytes(plan.without_lacking(fetched)) if not p.to_download: run.total_up_to_date += len(p.up_to_date) if _offline_only(): diff --git a/installer/run_files.py b/installer/run_files.py index 00ec66828..4a887bcf8 100644 --- a/installer/run_files.py +++ b/installer/run_files.py @@ -29,6 +29,7 @@ from installer.destination import _unknown_target from installer.detect_os import detected_shown from installer.device import card_board, detect_board, version_note from installer.events import EVENTS +from installer.fetch_plan import FetchPlan from installer.filesystems import ( FAT_REFUSED, FAT_REFUSED_SHOWN, @@ -237,6 +238,7 @@ class _PlatformPass: self.bios_index: FolderIndex | None = None self.copies: dict[int, LocalCopy] = {} self.unread: list[Unreadable] = [] + self.plan = FetchPlan([], [], [], 0, 0) self.hint: list[str] = [] self.space_checked = False diff --git a/installer/tui_choice.py b/installer/tui_choice.py index 3a4bc7c0d..06617d06f 100644 --- a/installer/tui_choice.py +++ b/installer/tui_choice.py @@ -4,7 +4,7 @@ from __future__ import annotations import re from collections.abc import Iterable from pathlib import Path -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, NamedTuple from installer.cards import card_bound from installer.choices import available_choices, core_files, emulator_names @@ -15,8 +15,6 @@ 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 -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 from installer.platforms import _tui_system_label, system_title @@ -266,20 +264,10 @@ def _checked_scope(state: TuiState) -> set[str]: return set(state.checked_dests) | left if state.checked_dests or left else set() -def _plan_copies(state: TuiState, check: dict) -> list[str]: - """The files to install that this machine holds, by destination.""" - if check is state.dry and check is not state.check: - return _dry_copies(state) - local = {event["dest"] for event in state.found} if check is state.check else set() - sizes = {event["dest"] for event in state.files} - return [dest for dest in local if dest in sizes] - - -def _dry_copies(state: TuiState) -> list[str]: - """The files the confirm or preview run would install that this - machine holds.""" - local = {event["dest"] for event in state.found} - return [event["dest"] for event in state.dry_files if event["dest"] in local] +def _plan_copies(check: dict) -> list[str]: + """The files to install that this machine holds, by destination, as the + run that counted check decided it (its fetch_plan event).""" + return list((check.get("fetch_plan") or {}).get("copied") or []) def space_needed(check: dict) -> int: @@ -444,46 +432,39 @@ def _tui_found_elsewhere(state: TuiState, dests: set | None = None) -> dict[str, return found -def _plan_fetch(state: TuiState, check: dict) -> tuple[int, int, list, list, dict]: - """(files to fetch, bytes the install fetches with the data files', - dests copied from this machine, dests the pack lacks, the size of each - file): the one size the plan's headline and its Install row say. +class PlanFetch(NamedTuple): + """What the run that counted a check fetches, from its fetch_plan event: + the BIOS files and their bytes, the data files and theirs, the dests + copied from this machine, those the pack lacks, the size of each file.""" - A file found on this machine is copied, not downloaded: the count and - the size to download leave it out, from the check's own events. On - Confirm the dry run's files are matched the same way: it called the - files a --from folder holds downloads, and sent an offline user for a - pack. The files the pack does not hold are left out too: the plan - offered "Install 6.6 GB" from a pack that held none of them. - """ + files: int + bytes: int + data_files: int + data_bytes: int + copied: list[str] + lacking: list[str] + sizes: dict[str, int] + + @property + def size(self) -> int: + """The one size the plan's headline and its Install row say.""" + return self.bytes + self.data_bytes + + +def _plan_fetch(state: TuiState, check: dict) -> PlanFetch: + """The plan of check as the run decided it: the screen reads the + counts, never works them out again. Worked out here, a file a --from + folder held was called a download, a pack that held none of the files + offered "Install 6.6 GB", and a pack without the data trees promised + them.""" dry = check is state.dry and check is not state.check - sizes = {event["dest"]: event["size"] - for event in (state.dry_files if dry else state.files)} - copied = _plan_copies(state, check) if dry or check is state.check else [] - lacking = _tui_pack_lacks(state, [dest_ for dest_ in sizes if dest_ not in copied]) - fetch = max(0, _needed(check) - len(copied) - len(lacking)) - fetch_bytes = max(0, check.get("bytes_needed", 0) - sum(sizes[dest_] for dest_ in copied) - - sum(sizes[dest_] for dest_ in lacking)) - data_bytes = check.get("data_bytes", 0) if check.get("data_missing", 0) else 0 - return fetch, fetch_bytes + data_bytes, copied, lacking, sizes - - -def _tui_pack_trees(state: TuiState) -> bool: - """Whether the pack given to the run holds a file of the list's data - trees.""" - return pack_holds_trees((state.manifest or {}).get("data_directories") or []) - - -def _tui_pack_lacks(state: TuiState, dests: list[str]) -> list[str]: - """The destinations of a plan the pack given to the run does not hold.""" - if LOCAL.pack is None or not dests: - return [] - manifest = state.manifest or {} - entries = {str(entry.get("dest")): entry for entry in [ - *(manifest.get("files") or []), *(manifest.get("case_variants") or [])]} - held = {id(entry) for entry in pack_lacks([entries[dest] for dest in dests - if dest in entries])} - return [dest for dest in dests if dest in entries and id(entries[dest]) in held] + plan = check.get("fetch_plan") or {} + return PlanFetch( + plan.get("files", 0), plan.get("bytes", 0), plan.get("data_files", 0), + plan.get("data_bytes", 0), list(plan.get("copied") or []), + list(plan.get("lacking") or []), + {event["dest"]: event["size"] for event in (state.dry_files if dry else state.files)}, + ) def _plan_folder(state: TuiState, dest: Path | None) -> Path | None: diff --git a/installer/tui_plan_view.py b/installer/tui_plan_view.py index ae062a92c..cdee3ab32 100644 --- a/installer/tui_plan_view.py +++ b/installer/tui_plan_view.py @@ -44,7 +44,6 @@ from installer.tui_choice import ( _tui_estimating, _tui_found_elsewhere, _tui_misplaced, - _tui_pack_trees, _tui_tally, games_plan_words, games_where, @@ -101,6 +100,7 @@ class _PlanFigures(NamedTuple): dry: bool fetch: int fetch_bytes: int + data_fetch: int data_bytes: int copied: list lacking: list @@ -113,26 +113,26 @@ def _plan_figures(check: dict, state: TuiState) -> _PlanFigures: need = _needed(check) data = check.get("data_missing", 0) dry = check is state.dry and check is not state.check - fetch, fetched, copied, lacking, sizes = _plan_fetch(state, check) - fetch_bytes = fetched - (check.get("data_bytes", 0) if data else 0) + plan = _plan_fetch(state, check) + copied = plan.copied elsewhere = (_tui_found_elsewhere(state, set(copied) if dry else None) if check is state.check or dry else {}) 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. - data_bytes = check.get("data_bytes", 0) if data else 0 - return _PlanFigures(need, data, dry, fetch, fetch_bytes, data_bytes, copied, lacking, - sizes, elsewhere, offline) + return _PlanFigures(need, data, dry, plan.files, plan.bytes, plan.data_files, + plan.data_bytes, copied, plan.lacking, + plan.sizes, elsewhere, offline) def _plan_needed_headline(check: dict, fig: _PlanFigures) -> str: """The headline of a plan with files to install.""" - need, data, fetch, copied = fig.need, fig.data, fig.fetch, fig.copied + need, data, fetch, copied = fig.need, fig.data_fetch, fig.fetch, fig.copied if fig.elsewhere: # The folder by its last name: the whole path pushed the BIOS # folder off a 40x15 screen. The Options row spells it out. The - # data files are among those to fetch: one count. + # data files the run brings are among those to fetch: one count. where = ", ".join(f"{len(events)} found in {_last_name(folder)}" for folder, events in fig.elsewhere.items()) rest = fetch + data @@ -165,7 +165,7 @@ def _plan_needed_headline(check: dict, fig: _PlanFigures) -> str: return f"{_plural(len(copied), 'file')} to copy from this machine" -def _plan_headline(check: dict, state: TuiState, fig: _PlanFigures) -> str: +def _plan_headline(check: dict, fig: _PlanFigures) -> str: data = fig.data # The data trees' size comes from their own event: "2636 data files" # beside "6.6 GB" said nothing of what they weigh. @@ -177,7 +177,7 @@ def _plan_headline(check: dict, state: TuiState, fig: _PlanFigures) -> str: if fig.lacking and not fig.fetch and not fig.copied: # The data files too, when the pack holds none of them: "8252 # files" said nothing of the 2636 it cannot give either. - lacked = len(fig.lacking) + (data if data and not _tui_pack_trees(state) else 0) + lacked = len(fig.lacking) + data - fig.data_fetch return pack_lacks_words(lacked, lacked) return _plan_needed_headline(check, fig) @@ -271,7 +271,7 @@ def _plan_check_lines(check: dict, state: TuiState) -> list: def _plan_lines(check: dict, dest: Path | None, state: TuiState) -> list: fig = _plan_figures(check, state) data, fetch = fig.data, fig.fetch - headline = _plan_headline(check, state, fig) + headline = _plan_headline(check, fig) wrong = check["wrong_hash"] # Where some were found, the plan names the rest by kind ("Not in old: # 10 BIOS files and 6 game data files.", _view_plan), and the remedy diff --git a/installer/tui_receive.py b/installer/tui_receive.py index da67e6826..c3e9b0f6e 100644 --- a/installer/tui_receive.py +++ b/installer/tui_receive.py @@ -121,6 +121,8 @@ def _take_check_event(state: TuiState, kind: str | None, event: dict) -> None: state.check["data_bytes"] = event["bytes"] elif kind == "space" and state.check is not None: state.check["space_bytes"] = event["bytes"] + elif kind == "fetch_plan" and state.check is not None: + state.check["fetch_plan"] = event elif kind == "check": state.check = event elif kind == "file": @@ -140,6 +142,8 @@ def _take_dry_event(state: TuiState, kind: str | None, event: dict) -> None: state.dry["data_bytes"] = event["bytes"] elif kind == "space" and state.dry is not None: state.dry["space_bytes"] = event["bytes"] + elif kind == "fetch_plan" and state.dry is not None: + state.dry["fetch_plan"] = event elif kind == "check": state.dry = event elif kind == "file" and event.get("state") != "present": diff --git a/installer/tui_rows.py b/installer/tui_rows.py index 4c66dd9fe..3b71be581 100644 --- a/installer/tui_rows.py +++ b/installer/tui_rows.py @@ -33,7 +33,6 @@ from installer.tui_choice import ( _cores_dir_given, _device_choice, _device_words, - _dry_copies, _emulator_words, _needed, _on_its_card, @@ -50,8 +49,6 @@ from installer.tui_choice import ( _tui_categories, _tui_estimating, _tui_misplaced, - _tui_pack_lacks, - _tui_pack_trees, _yes, core_ticked, games_where, @@ -250,7 +247,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 _plan_copies(state.dry): # The plan's rule: Install would only fail every file. return [TuiRow("back", "Back")] return [TuiRow("install", "Install"), TuiRow("back", "Back")] @@ -321,18 +318,17 @@ def _plan_rows(state: TuiState) -> list[TuiRow]: # The size the headline says: "Install 6.6 GB" stood under "14930 files # to download, 6.8 GB", the copies counted in one and the data files in # the other. - size = _ticked_estimate(state)[1] if _tui_estimating(state) else _plan_fetch(state, check)[1] + plan = _plan_fetch(state, check) + size = _ticked_estimate(state)[1] if _tui_estimating(state) else plan.size 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.copied: # Nothing here to copy, and the network refused: Install would # only fail every file, in this folder or another. rows = [] - files = {event["dest"] for event in state.files} - if (LOCAL.pack is not None and files and not _plan_copies(state, check) - and len(_tui_pack_lacks(state, sorted(files))) == len(files) - and not (check.get("data_missing") and _tui_pack_trees(state))): + if (LOCAL.pack is not None and state.files and not plan.copied + and len(plan.lacking) == len(state.files) and not plan.data_files): # The pack holds none of them, nor the data files: Install would # fail every one. rows = [] diff --git a/schemas/install-events.schema.json b/schemas/install-events.schema.json index 68d5180f6..fec94487e 100644 --- a/schemas/install-events.schema.json +++ b/schemas/install-events.schema.json @@ -31,6 +31,7 @@ "declared", "data", "space", + "fetch_plan", "found", "unreadable", "saves", @@ -115,6 +116,9 @@ { "$ref": "#/$defs/space" }, + { + "$ref": "#/$defs/fetch_plan" + }, { "$ref": "#/$defs/found" }, @@ -842,6 +846,56 @@ } } }, + "fetch_plan": { + "type": "object", + "additionalProperties": false, + "required": [ + "event", + "platform", + "files", + "bytes", + "copied", + "lacking", + "data_files", + "data_bytes" + ], + "properties": { + "event": { + "const": "fetch_plan" + }, + "platform": { + "type": "string" + }, + "files": { + "type": "integer", + "minimum": 0 + }, + "bytes": { + "type": "integer", + "minimum": 0 + }, + "copied": { + "type": "array", + "items": { + "type": "string" + } + }, + "lacking": { + "type": "array", + "items": { + "type": "string" + } + }, + "data_files": { + "type": "integer", + "minimum": 0 + }, + "data_bytes": { + "type": "integer", + "minimum": 0 + } + } + }, "found": { "type": "object", "additionalProperties": false, diff --git a/scripts/installer_build/eventschema.py b/scripts/installer_build/eventschema.py index 02786c1f5..6558796e0 100644 --- a/scripts/installer_build/eventschema.py +++ b/scripts/installer_build/eventschema.py @@ -39,11 +39,13 @@ KEY_TYPES: dict[str, dict] = { "files", "files_done", "files_total", "bytes", "bytes_done", "bytes_total", "bytes_local", "bytes_network", "size", "present", "missing", "wrong_hash", "bytes_needed", "bytes_free", "data_missing", "not_installable", "installed", "up_to_date", - "pending", "code", "games", "recognised", "not_games", "gone", + "pending", "code", "games", "recognised", "not_games", "gone", "data_files", + "data_bytes", ), _COUNT), **dict.fromkeys(("truncated", "ok", "interrupted", "required_only", "applied", "info", "backup"), _FLAG), - **dict.fromkeys(("systems", "other_drives", "dests", "written", "choice", "parts"), + **dict.fromkeys(("systems", "other_drives", "dests", "written", "choice", "parts", + "copied", "lacking"), _NAMES), **dict.fromkeys(("platforms", "failed", "skipped", "left_out", "kept", "found", "fallback"), _RECORDS), diff --git a/tests/test_install.py b/tests/test_install.py index 6cb05e56b..001196ab0 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -7194,6 +7194,10 @@ class EventsDescribeTheRun(unittest.TestCase, _SyntheticTree): # The missing and the wrong copy, written: what the run holds # against the free space. {"event": "space", "platform": "retroarch", "bytes": 245}, + # Each file not in place comes from the network: no copy here, + # no pack. + {"event": "fetch_plan", "platform": "retroarch", "files": 3, "bytes": 245, + "copied": [], "lacking": [], "data_files": 0, "data_bytes": 0}, ] SKIPPED = [{"reason": "not_found", "label": "not found", "files": 1, "required": 1}] diff --git a/tests/test_install_pack.py b/tests/test_install_pack.py index 426af7871..dabec1b2c 100644 --- a/tests/test_install_pack.py +++ b/tests/test_install_pack.py @@ -623,6 +623,54 @@ class PartSizes(unittest.TestCase): install.parse_part_size(text) +class TheRunDecidesWhatItFetches(unittest.TestCase): + """The screen worked the plan out again from the events: from a pack + without the data trees it promised them, and --check counted none from + a pack that held them all. fetch_plan decides it once for both.""" + + FILES = [{"dest": "a.bin", "size": 10}, {"dest": "b.bin", "size": 20}, + {"dest": "c.bin", "size": 40}] + TREE = {"ref": "dolphin", "dest": "Sys", "files": {"font.bin": {"size": 5}}} + + def plan(self, members: set | None) -> object: + class Pack: + name = "RetroArch_BIOS_Pack.zip" + + @staticmethod + def find(entry: dict) -> tuple | None: + return (None, entry) if entry["dest"] in members else None + + Pack.members = members + a_copy = {id(self.FILES[0]): object()} + state = (Path("Sys"), {"font.bin": {"size": 5}}, 0) + with mock.patch.object(install.LOCAL, "pack", Pack() if members is not None else None): + return install.fetch_plan(self.FILES, a_copy, [(self.TREE, state)]) + + def test_without_a_pack_every_file_and_tree_comes(self): + plan = self.plan(None) + self.assertEqual([entry["dest"] for entry in plan.copied], ["a.bin"]) + self.assertEqual([entry["dest"] for entry in plan.coming], ["b.bin", "c.bin"]) + self.assertEqual((plan.lacking, plan.data_files, plan.data_bytes), ([], 1, 5)) + + def test_a_pack_without_the_trees_brings_none_of_them(self): + plan = self.plan({"b.bin"}) + self.assertEqual([entry["dest"] for entry in plan.lacking], ["c.bin"]) + self.assertEqual([entry["dest"] for entry in plan.coming], ["b.bin"]) + self.assertEqual((plan.data_files, plan.data_bytes), (0, 0)) + + def test_a_pack_holding_the_trees_brings_them(self): + plan = self.plan({"b.bin", "c.bin", "Sys/font.bin"}) + self.assertEqual(plan.lacking, []) + self.assertEqual((plan.data_files, plan.data_bytes), (1, 5)) + + def test_the_event_carries_the_plan(self): + plan = self.plan({"b.bin"}) + with mock.patch.object(install.EVENTS, "emit") as emit: + install.emit_fetch_plan("retroarch", plan) + emit.assert_called_once_with( + "fetch_plan", platform="retroarch", files=1, bytes=20, copied=["a.bin"], + lacking=["c.bin"], data_files=0, data_bytes=0) + class AListRecordsWhatItNarrowsBy(unittest.TestCase): """A pack built here, a pack built by generate_pack and the list itself diff --git a/tests/test_install_tui.py b/tests/test_install_tui.py index c7a16bdb3..36f8de0b9 100644 --- a/tests/test_install_tui.py +++ b/tests/test_install_tui.py @@ -39,6 +39,7 @@ import types import unittest import warnings import zipfile +from collections.abc import Iterable from pathlib import Path, PurePosixPath, PureWindowsPath from unittest import mock @@ -369,6 +370,28 @@ CHECK = {"event": "check", "platform": "retroarch", "name": "RetroArch", "bios_dir": "/home/user/.config/retroarch/system", "files": 5, "present": 1, "missing": 3, "wrong_hash": 1, "bytes_needed": 1064964, "data_missing": 0, "not_installable": 2} + + +def plan_event(check: dict, copied: Iterable[str] = (), lacking: Iterable[str] = (), + sizes: dict | None = None, **plan) -> dict: + """The fetch_plan event the run sends after check: every file not in + place fetched, but those copied from this machine and those the pack + lacks (sizes by dest, those of FILES by default), unless plan says + otherwise.""" + copied, lacking = list(copied), list(lacking) + sizes = {event["dest"]: event["size"] for event in FILES} if sizes is None else sizes + left = [*copied, *lacking] + return {"event": "fetch_plan", "platform": check["platform"], + "files": check["missing"] + check["wrong_hash"] - len(left), + "bytes": check["bytes_needed"] - sum(sizes[dest] for dest in left), + "copied": copied, "lacking": lacking, "data_files": check.get("data_missing", 0), + "data_bytes": check.get("data_bytes", 0), **plan} + + +def planned(check: dict, *given, **plan) -> dict: + """check as the screen holds it once its fetch_plan event came.""" + return {**check, "fetch_plan": plan_event(check, *given, **plan)} + FILES = [ {"event": "file", "platform": "retroarch", "dest": "scph5500.bin", "systems": ["sony-playstation"], "size": 524288, "state": "missing"}, @@ -379,6 +402,7 @@ FILES = [ {"event": "file", "platform": "retroarch", "dest": "gba_bios.bin", "systems": ["nintendo-gba"], "size": 16384, "state": "missing"}, ] +PLAN = plan_event(CHECK) HOME = Path("/home/user") SYSTEM_DIR = HOME / ".config" / "retroarch" / "system" @@ -428,7 +452,7 @@ def games_state() -> install.TuiState: install.tui_receive(state, ("games_here", "retroarch", SYSTEM_DIR, 2)) effects = install.tui_receive(state, ("manifest", "retroarch", MANIFEST)) assert effects == [("run", "check")], effects - for event in [GAMES, *FILES, *SYSTEMS, CHECK]: + for event in [GAMES, *FILES, *SYSTEMS, CHECK, PLAN]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True, "cores": ["pcsx_rearmed"]}): @@ -445,7 +469,7 @@ def checked_state(facts: dict | None = None) -> install.TuiState: assert effects == [("fetch", "retroarch")], effects effects = install.tui_receive(state, ("manifest", "retroarch", MANIFEST)) assert effects == [("run", "check")], effects - for event in [*FILES, *SYSTEMS, CHECK]: + for event in [*FILES, *SYSTEMS, CHECK, PLAN]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value=facts or { "free": 50 * 1024 ** 3, "writable": True, "cores": ["pcsx_rearmed"]}): @@ -640,7 +664,7 @@ class Flow(unittest.TestCase): self.assertEqual(press(state, "enter"), [("run", "preview")]) self.assertEqual(install.tui_argv(state, "preview", "py", "i.py")[-2:], ["--dry-run", "--events"]) - for event in [*FILES, CHECK]: + for event in [*FILES, CHECK, PLAN]: install.tui_receive(state, ("event", state.run_id, event)) install.tui_receive(state, ("ended", state.run_id, 0, [])) text = "\n".join(install.tui_view(state, 80, 24)) @@ -1053,7 +1077,7 @@ def _golden_plan_states() -> dict: states["cores"] = cores preview = checked_state() preview.stack += ["options", "preview"] - preview.dry, preview.dry_files = dict(CHECK), list(FILES) + preview.dry, preview.dry_files = planned(CHECK), list(FILES) states["preview"] = preview command = checked_state() command.stack += ["options", "command"] @@ -1062,8 +1086,8 @@ def _golden_plan_states() -> dict: confirm = checked_state() confirm.stack.append("confirm") confirm.ticked = {"nintendo-gba"} - confirm.dry = {**CHECK, "files": 1, "present": 0, "missing": 1, "wrong_hash": 0, - "bytes_needed": 16384, "not_installable": 0} + confirm.dry = planned({**CHECK, "files": 1, "present": 0, "missing": 1, "wrong_hash": 0, + "bytes_needed": 16384, "not_installable": 0}) states["confirm"] = confirm return states @@ -1292,7 +1316,7 @@ def record_state(setup: dict | None = None) -> install.TuiState: systems = [event for event in SYSTEMS if event["system"] == "nintendo-gba"] check = {**CHECK, "files": 1, "present": 0, "missing": 1, "wrong_hash": 0, "bytes_needed": 16384, "not_installable": 0} - for event in [*gba, *systems, check]: + for event in [*gba, *systems, check, plan_event(check)]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True, "cores": ["pcsx_rearmed"]}): @@ -1369,7 +1393,7 @@ class RecordedPlan(unittest.TestCase): state, _effects = install.tui_start(_args(), "linux") self.assertTrue(state.opened_on_plan) install.tui_receive(state, ("manifest", "retroarch", MANIFEST)) - for event in [*FILES, *SYSTEMS, CHECK]: + for event in [*FILES, *SYSTEMS, CHECK, PLAN]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True}): @@ -1416,7 +1440,7 @@ class RecordedPlan(unittest.TestCase): self.assertIn(("--all-files", None), flags) self.assertFalse([flag for flag in flags if flag[0] == "--system"]) self.assertFalse(install.tui_record_kept(state)) - for event in [*FILES, *SYSTEMS, CHECK]: + for event in [*FILES, *SYSTEMS, CHECK, PLAN]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True}): @@ -1459,8 +1483,8 @@ class RecordedPlan(unittest.TestCase): big = 2 * 1024 ** 3 state = checked_state() state.files[0] = {**state.files[0], "size": big} - state.check = {**state.check, "bytes_needed": state.check["bytes_needed"] + big, - "data_missing": 3, "data_bytes": 300 * 1024 ** 2} + state.check = planned({**state.check, "bytes_needed": state.check["bytes_needed"] + big, + "data_missing": 3, "data_bytes": 300 * 1024 ** 2}) headline = str(install._plan_lines(state.check, state.dest, state)[0]) size = headline.rsplit(", ", 1)[1] self.assertEqual(install.tui_rows(state)[0].label, f"Install {size}") @@ -2148,7 +2172,7 @@ class TicksBarAndPaths(unittest.TestCase): big = 6 * 1024 ** 3 state = checked_state() state.files[0] = {**state.files[0], "size": big} - state.check = {**state.check, "bytes_needed": state.check["bytes_needed"] + big} + state.check = planned({**state.check, "bytes_needed": state.check["bytes_needed"] + big}) self.assertEqual(install.tui_rows(state)[0].label, "Install 6.0 GB") for system, label, head in (("nintendo-gba", "Install", "About 1 file, 16.0 KB"), ("sony-playstation", "Install 6.0 GB", @@ -2602,7 +2626,9 @@ class CopyFromAnOldCard(unittest.TestCase): """--from in the interface: a row on the plan, the browser, the counts.""" def recheck(self, state: install.TuiState, events: list) -> None: - for event in [*FILES, *SYSTEMS, *events, CHECK]: + plan = plan_event(CHECK, [event["dest"] for event in events if event["event"] == "found" + and event["dest"] in {file["dest"] for file in FILES}]) + for event in [*FILES, *SYSTEMS, *events, CHECK, plan]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True, "cores": []}): @@ -3314,7 +3340,7 @@ class CardsSpaceAndConfirm(unittest.TestCase): {"event": "unreadable", "platform": "retroarch", "folder": "E:\\", "path": "E:\\backup.zip", "member": "gba_bios.bin", "reason": "it is encrypted, a password is needed"}] - for event in [*FILES, *SYSTEMS, *events, CHECK]: + for event in [*FILES, *SYSTEMS, *events, CHECK, PLAN]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True, "cores": []}): @@ -3500,7 +3526,7 @@ class SaveDirectoryLeftOut(unittest.TestCase): summary = {"event": "summary", "mode": "check", "installed": 0, "up_to_date": 0, "pending": 5, "failed": [], "skipped": [self.UNPLACED], "left_out": [], "kept": [], "interrupted": False} - for event in [*FILES, *SYSTEMS, CHECK, summary]: + for event in [*FILES, *SYSTEMS, CHECK, PLAN, summary]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True, "cores": []}): @@ -3537,7 +3563,7 @@ class SaveDirectoryLeftOut(unittest.TestCase): summary = {"event": "summary", "mode": "check", "installed": 0, "up_to_date": 0, "pending": 5, "failed": [], "skipped": [self.UNPLACED], "left_out": [], "kept": [], "interrupted": False} - for event in [*FILES, *SYSTEMS, CHECK, summary]: + for event in [*FILES, *SYSTEMS, CHECK, PLAN, summary]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True, "cores": []}): @@ -4309,6 +4335,8 @@ class OfflineInTheInterface(unittest.TestCase): state.found = [{"event": "found", "platform": "retroarch", "dest": FILES[0]["dest"], "folder": "/media/old", "path": "/media/old/scph5500.bin", "member": "", "reason": ""}] + state.check = planned(CHECK, files=3, bytes=CHECK["bytes_needed"] - FILES[0]["size"], + copied=[FILES[0]["dest"]]) text = " ".join(" ".join(install.tui_view(state, 120, 40)).split()) self.assertIn("1 found in old,", text) self.assertIn("need the internet (--offline)", text) @@ -4387,7 +4415,7 @@ class BackTicksAndSaveFolder(unittest.TestCase): def test_confirm_offline_with_nothing_on_hand_has_no_install(self): state = checked_state() state.stack.append("confirm") - state.dry = dict(CHECK) + state.dry = planned(CHECK) state.dry_files = [dict(event, state="missing") for event in FILES] state.offline = True with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}): @@ -4398,6 +4426,7 @@ class BackTicksAndSaveFolder(unittest.TestCase): state.found = [{"event": "found", "platform": "retroarch", "dest": FILES[0]["dest"], "folder": "/media/old", "path": "/media/old/x", "member": "", "reason": ""}] + state.dry = planned(CHECK, [FILES[0]["dest"]]) self.assertEqual(install.tui_rows(state)[0].action, "install") def test_the_checking_clock_starts_at_zero(self): @@ -4410,6 +4439,7 @@ class BackTicksAndSaveFolder(unittest.TestCase): state.found = [{"event": "found", "platform": "retroarch", "dest": FILES[0]["dest"], "folder": "/media/old", "path": "/media/old/x", "member": "", "reason": "misplaced"}] + state.check = planned(CHECK, [FILES[0]["dest"]]) with mock.patch.object(install.LOCAL, "pack", mock.Mock()): text = " ".join(" ".join(install.tui_view(state, 120, 40)).split()) # one count, "4 files to install" above "3 from @@ -6423,6 +6453,7 @@ class ThePlanNumbersAddUp(unittest.TestCase): def test_the_copied_files_are_the_difference(self): state = checked_state() state.found = [found("scph5500.bin", str(SYSTEM_DIR), "one folder too deep")] + state.check = planned(CHECK, ["scph5500.bin"]) screen = " ".join(" ".join(install.tui_view(state, 120, 40)).split()) self.assertIn("3 files to download", screen) # The backup line under the count it explains, then the split. @@ -7065,11 +7096,12 @@ class ConfirmRefusalsAndCardRows(unittest.TestCase): state.found = [{"event": "found", "platform": "retroarch", "dest": FILES[0]["dest"], "folder": "/media/old", "path": "/media/old/x", "member": "", "reason": ""}] + state.check = planned(CHECK, [FILES[0]["dest"]]) with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: install.OFFLINE_FLAG_VALUE}): text = " ".join(" ".join(install.tui_view(state, 120, 40)).split()) self.assertNotIn("downloaded", text) state.found = [] - state.check = dict(state.check, data_missing=2636, data_bytes=40 * 1024 * 1024) + state.check = planned(dict(CHECK, data_missing=2636, data_bytes=40 * 1024 * 1024)) text = " ".join(" ".join(install.tui_view(state, 120, 40)).split()) # One count of files, the kinds apart under the folder: "4 files and # 2636 data files" read as two kinds of one. @@ -8552,9 +8584,9 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings, "event": "file", "platform": "retroarch", "dest": "PCSX/EXTRA.BIN", "systems": ["sony-playstation"], "size": 4, "state": "missing"}] state.checked_dests.add("PCSX/EXTRA.BIN") - state.check = {**state.check, "missing": state.check["missing"] + 1, - "files": state.check["files"] + 1, - "bytes_needed": state.check["bytes_needed"] + 4} + state.check = planned({**state.check, "missing": state.check["missing"] + 1, + "files": state.check["files"] + 1, + "bytes_needed": state.check["bytes_needed"] + 4}) text = " ".join(" ".join(install.tui_view(state, 120, 40)).split()) self.assertIn("5 files to download", text) self.assertIn("3 BIOS files (1.0 MB) and 2 game data files (8 B).", text) @@ -9578,7 +9610,7 @@ class PacksWordingAndDocs(unittest.TestCase): press(state, "enter") self.assertEqual(state.screen, "checking") # The check of every system comes back, the ticks kept. - for event in [*FILES, *SYSTEMS, CHECK]: + for event in [*FILES, *SYSTEMS, CHECK, PLAN]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True, "cores": []}): @@ -9591,7 +9623,7 @@ class PacksWordingAndDocs(unittest.TestCase): state.focus["plan"] = next(i for i, row in enumerate(install.tui_rows(state)) if row.action == "systems") press(state, "enter") - for event in [*FILES, *SYSTEMS, CHECK]: + for event in [*FILES, *SYSTEMS, CHECK, PLAN]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True, "cores": []}): @@ -10000,6 +10032,7 @@ class CardFoldersAndNarrowBars(unittest.TestCase): """Under the pack and copy split it was cut.""" state = checked_state() state.found = [found("gba_bios.bin", "/media/old")] + state.check = planned(CHECK, ["gba_bios.bin"]) lines = [str(line) for line in install._plan_lines(state.check, state.dest, state)] self.assertTrue(any("copied from this machine" in line for line in lines), lines) counts = next(index for index, line in enumerate(lines) if " in place, " in line) @@ -11729,7 +11762,7 @@ class TapsGameDataAndExitCodes(_CardFixtures, unittest.TestCase): install.tui_receive(state, ("manifest", "retroarch", MANIFEST)) for event in [{"event": "version", "platform": "retroarch", "list_version": "8.3.1", "installed_version": "8.2.0.1", "message": said}, - *FILES, *SYSTEMS, CHECK]: + *FILES, *SYSTEMS, CHECK, PLAN]: install.tui_receive(state, ("event", state.run_id, event)) with mock.patch.object(install, "_tui_folder_facts", return_value={ "free": 50 * 1024 ** 3, "writable": True, "cores": []}): @@ -12330,7 +12363,9 @@ class OneChoicePerRun(unittest.TestCase): state = checked_state() state.found = [found(event["dest"], "/media/old") for event in FILES] state.stack.append("confirm") - state.dry, state.dry_files = dict(CHECK), list(FILES) + state.dry = planned(CHECK, files=0, bytes=0, + copied=[event["dest"] for event in FILES]) + state.dry_files = list(FILES) for env in ({install.OFFLINE_VARIABLE: install.OFFLINE_FLAG_VALUE}, {}): with self.subTest(offline=bool(env)), mock.patch.dict(os.environ, env): text = " ".join(" ".join(install.tui_view(state, 80, 24)).split()) @@ -12362,11 +12397,14 @@ class OneChoicePerRun(unittest.TestCase): def find(entry: dict) -> tuple | None: return (None, entry) if entry["dest"] == "gba_bios.bin" else None + dests = [event["dest"] for event in FILES] + state.check = planned(CHECK, files=1, bytes=16384, + lacking=[dest for dest in dests if dest != "gba_bios.bin"]) with mock.patch.object(install.LOCAL, "pack", Lacking()): text = " ".join(" ".join(install.tui_view(state, 80, 24)).split()) self.assertIn("1 file to install from the pack, 16.0 KB", text) self.assertIn("3 of these 4 files are not in RetroArch_BIOS_Pack.zip", text) - Lacking.find = staticmethod(lambda entry: None) + state.check = planned(CHECK, files=0, bytes=0, lacking=dests) text = " ".join(" ".join(install.tui_view(state, 80, 24)).split()) self.assertIn("RetroArch_BIOS_Pack.zip holds none of these 4 files", text) self.assertNotIn("install", [row.action for row in install.tui_rows(state)]) @@ -12503,7 +12541,7 @@ class OneChoicePerRun(unittest.TestCase): """"8358 files and 2636 data files", and the definition dropped at 80 columns.""" state = _game_state() - state.check = {**state.check, "data_missing": 7, "data_bytes": 2048} + state.check = planned({**state.check, "data_missing": 7, "data_bytes": 2048}) lines = [str(line).strip() for line in install.tui_view(state, 80, 24)] text = " ".join(" ".join(lines).split()) self.assertIn("11 files to download, 1.0 MB", text) @@ -13322,7 +13360,10 @@ class ChoiceStateInBothModes(unittest.TestCase): files nor the trees: Install was offered and failed every file, and the result never named the data files.""" state = checked_state() - state.check = {**state.check, "data_missing": 7, "data_bytes": 2048} + # The run's plan: the pack holds none of the files nor the trees. + state.check = planned({**state.check, "data_missing": 7, "data_bytes": 2048}, + lacking=[event["dest"] for event in state.files], + data_files=0, data_bytes=0) state.manifest = {**MANIFEST, "data_directories": [ {"ref": "dolphin", "dest": "dolphin-emu/Sys", "files": {}}]} @@ -14031,7 +14072,10 @@ class OneVocabularyOneCount(unittest.TestCase): archive.writestr("manifest.json", json.dumps({"files": []})) archive.writestr("other-system.bin", b"x") state = checked_state() - state.check = {**state.check, "data_missing": 2, "data_bytes": 2} + # The run's plan: the pack holds none of the files nor the trees. + state.check = planned({**state.check, "data_missing": 2, "data_bytes": 2}, + lacking=[event["dest"] for event in state.files], + data_files=0, data_bytes=0) state.manifest = {**MANIFEST, "data_directories": [ {"ref": "bluemsx", "dest": "", "files": { "Machines/a.txt": {"sha1": "0" * 40, "size": 1}, @@ -14488,8 +14532,9 @@ class ProvenCardsAndCounts(unittest.TestCase): state.offline = True folder = "/media/OLD" state.from_folders = [Path(folder)] - state.found = [found(dest, folder) for dest in ("scph5500.bin", "pcsx/extra.bin", - "gba_bios.bin")] + copied = ("scph5500.bin", "pcsx/extra.bin", "gba_bios.bin") + state.found = [found(dest, folder) for dest in copied] + state.check = planned(CHECK, copied) with mock.patch.dict(os.environ, {install.OFFLINE_VARIABLE: "1"}): text = self.screen(state, 100, 30) self.assertIn("3 found in OLD, 1 needs the internet", text) diff --git a/wiki/architecture.md b/wiki/architecture.md index a30078b85..50c87c78e 100644 --- a/wiki/architecture.md +++ b/wiki/architecture.md @@ -503,7 +503,7 @@ those it imports: | Files and folders | `host_fs`, `paths`, `filesystems`, `config_values`, `local_check`, `safe_replace` | | This machine | `detection_notes`, `detect_os`, `detect_frontends`, `cards`, `device`, `cores`, `frontend_folders`, `setups` | | Sources of files | `offline`, `network`, `lists`, `pack_source`, `from_folders`, `diagnosis`, `download`, `datadirs`, `standalone` | -| What a run keeps | `narrowing`, `choices`, `romm`, `install_record`, `game_files`, `games`, `tally`, `space` | +| What a run keeps | `narrowing`, `choices`, `romm`, `install_record`, `game_files`, `games`, `tally`, `space`, `fetch_plan` | | Line mode | `destination`, `line_folder`, `line_menu`, `plan_words`, `plan`, `outcome` | | Runs and actions | `arguments`, `run_setups`, `run_files`, `run`, `pack`, `removal`, `handheld_app`, `cli` | | Full screen | `tui_state`, `tui_routes`, `tui_commands`, `tui_keys`, `tui_paint`, `tui_choice`, `tui_folder_scan`, `tui_rows`, `tui_frame`, `tui_plan_view`, `tui_outcome`, `tui_screens`, `tui_actions`, `tui_input`, `tui_receive`, `tui_list_words`, `tui_engine`, `tui_session` | diff --git a/wiki/installer.md b/wiki/installer.md index 63f041be6..eaa023d33 100644 --- a/wiki/installer.md +++ b/wiki/installer.md @@ -2243,6 +2243,7 @@ other schemas under `api/v1/schemas/`. | `declared` | `platform`, `files`, `present`, `missing`, `wrong_hash`, `bytes_needed`, `dests` | Right after `check`, the same counts over the files the platform's own list names (`cores: null`), and their `dests` in the order of the `file` events. A setup that checks its own list reads its answer here, with or without `--declared-only` | | `data` | `platform`, `files`, `bytes` | Right after `declared`: the data-tree files to fetch (the `data_missing` of `check`) and the bytes fetching them costs: each tree's archive, or the files themselves from a pack or a list that records no archive size | | `space` | `platform`, `bytes` | Right after `data`: the bytes the run writes on the drive of the BIOS folder, the files missing or replaced and the data trees rebuilt beside them. The run refuses to start below this much free space, and both plans warn on it | +| `fetch_plan` | `platform`, `files`, `bytes`, `copied`, `lacking`, `data_files`, `data_bytes` | Right after `space`: what an install fetches, as the run decides it. `files` and `bytes` come from the network, or from the pack when one is given and holds them. `copied` lists the destinations a copy on this machine gives (each also named by a `found` event), `lacking` those the pack does not hold. `data_files` and `data_bytes` are the data-tree files the run brings, none from a pack that holds no tree | | `found` | `platform`, `dest`, `folder`, `path`, `member`, `reason` | Each file to install that this machine already holds, after `check` and before anything is written, in `--check` and `--dry-run` too. `folder` is the `--from` folder as given, or the `bios_dir` of the check when the BIOS folder holds the file at another place, and then `reason` says where in words (`nested folder: ...` for a misplaced file, `the same file is at ...` for one the list installs there too). `path` is the file, and `member` the ZIP member holding the bytes when `path` is an archive, an empty string otherwise. Its copy is reported by a `downloaded` event | | `unreadable` | `platform`, `folder`, `path`, `member`, `reason` | Each file in a `--from` folder that could not be read and may be one the run still needs, right after the `found` events: its size is that of a file no copy was found for, or unknown (a folder that could not be listed, a ZIP that would not open). `member` names the ZIP member, or is empty. `reason` says why in words (`Permission denied`, `it is encrypted, a password is needed`) | | `saves` | `platform`, `files`, `folder` | After `choices` and before `checking`, when the files the run installs (once `--system` and the other choices narrowed the list) hold some read from the frontend's save directory and that directory is known: how many, and the `folder` they go to, where `` and `` stand for one folder per system or per core (the screen and `--plain` say it in words: "a folder per core under /sdcard/RetroArch/saves"). When it is not known, the files are counted in the summary's `skipped` instead (`no_save_directory`) |