mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
fix: one space count for both plans and the run
This commit is contained in:
1 parent
1e6f106525
commit
61a4e909bd
20 files changed
+1803
-1608
No files matched your search
+1
-1
@@ -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 = "2a38706740f45353c47221180ef32046d5bc6cac3338c76196c1597939dd6914"
|
||||
$defaultInstallSha256 = "f84869fba3c8af9eb75118fa2e0a1e435a79d8918f7523d3c55800a0dd2f8478"
|
||||
# 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
|
||||
|
||||
+1546
-1499
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -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="2a38706740f45353c47221180ef32046d5bc6cac3338c76196c1597939dd6914"
|
||||
DEFAULT_INSTALL_SHA256="f84869fba3c8af9eb75118fa2e0a1e435a79d8918f7523d3c55800a0dd2f8478"
|
||||
# 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
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
{
|
||||
"dest": "roms/ports/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1455166,
|
||||
"sha256": "2a38706740f45353c47221180ef32046d5bc6cac3338c76196c1597939dd6914",
|
||||
"size": 1457976,
|
||||
"sha256": "f84869fba3c8af9eb75118fa2e0a1e435a79d8918f7523d3c55800a0dd2f8478",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -71,8 +71,8 @@
|
||||
"muos": {
|
||||
"archive": {
|
||||
"dest": "ARCHIVE/RetroBIOS.muxapp",
|
||||
"size": 1508791,
|
||||
"sha256": "78657ba9ae18c468ae09e3d66736012b9efa04973c2b8cbcc5c8c1bab42045d3"
|
||||
"size": 1511601,
|
||||
"sha256": "0d293378a7267c6a519d76de52bbebb40fed534840a26a032c5d6ea0ebbef279"
|
||||
},
|
||||
"members": [
|
||||
{
|
||||
@@ -92,8 +92,8 @@
|
||||
{
|
||||
"name": "RetroBIOS/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1455166,
|
||||
"sha256": "2a38706740f45353c47221180ef32046d5bc6cac3338c76196c1597939dd6914",
|
||||
"size": 1457976,
|
||||
"sha256": "f84869fba3c8af9eb75118fa2e0a1e435a79d8918f7523d3c55800a0dd2f8478",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -166,8 +166,8 @@
|
||||
{
|
||||
"dest": ".config/modules/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1455166,
|
||||
"sha256": "2a38706740f45353c47221180ef32046d5bc6cac3338c76196c1597939dd6914",
|
||||
"size": 1457976,
|
||||
"sha256": "f84869fba3c8af9eb75118fa2e0a1e435a79d8918f7523d3c55800a0dd2f8478",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
|
||||
@@ -103,6 +103,12 @@ EVENT_KEYS: dict[str, tuple[str, ...]] = {
|
||||
# data_missing) and the bytes they write. A kind of its own, since
|
||||
# schema 1 never adds a key to check.
|
||||
"data": ("platform", "files", "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 number the run's refusal for space and both plans
|
||||
# hold against the free space. A kind of its own, since schema 1 never
|
||||
# adds a key to check.
|
||||
"space": ("platform", "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
|
||||
|
||||
+4
-51
@@ -1,8 +1,6 @@
|
||||
"""Line mode's menu: the plan above it and the systems, cores and regions it narrows to."""
|
||||
from __future__ import annotations
|
||||
|
||||
import concurrent.futures
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, NamedTuple
|
||||
@@ -16,7 +14,7 @@ from installer.choices import (
|
||||
parse_selection,
|
||||
recorded_axes,
|
||||
)
|
||||
from installer.console import _ask, _live_stdout, _quit
|
||||
from installer.console import _ask, _quit
|
||||
from installer.datadirs import data_directory_state, data_fetch_bytes, select_data_directories
|
||||
from installer.destination import _last_name, on_its_card, shown_bios_folder
|
||||
from installer.from_folders import plan_local_copies
|
||||
@@ -25,7 +23,7 @@ from installer.host_fs import _is_file
|
||||
from installer.install_record import _RECORD_TAKEN
|
||||
from installer.invocation import _INVOCATION
|
||||
from installer.line_folder import _ask_from_folder
|
||||
from installer.local_check import _classify_local
|
||||
from installer.local_check import not_in_place, read_in_place
|
||||
from installer.manifest import OTHER_SYSTEMS
|
||||
from installer.narrowing import _chosen, narrow
|
||||
from installer.offline import LOCAL, _offline_only, offline_named
|
||||
@@ -463,7 +461,7 @@ def _print_menu_head(
|
||||
# Done, where the screen names it on every plan.
|
||||
print(f" BIOS folder: {shown_path(shown_bios_folder(bios_path, files))}")
|
||||
for line in folder_warnings(plat, bios_path, shown, _INVOCATION, True,
|
||||
on_its_card(plat, bios_path)):
|
||||
on_its_card(plat, bios_path), kept_trees):
|
||||
print(f" {line}")
|
||||
# The frontend's save directory, named as the end of the run and the
|
||||
# screen name it: "Onion's" before the menu, "RetroArch's" after.
|
||||
@@ -485,28 +483,7 @@ def found_head(files: list[dict], trees: list[dict], bios_path: Path) -> str:
|
||||
"nothing to download" stood over a run that left it. What is read here is
|
||||
kept for the check after Enter (_HEAD_READS): a card read twice is read at
|
||||
the speed of its reader."""
|
||||
|
||||
def held(path: Path, size: object) -> bool:
|
||||
try:
|
||||
return _is_file(path) and path.stat().st_size == size
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
needed, sized = [], []
|
||||
for entry in files:
|
||||
try:
|
||||
path = _entry_path(bios_path, entry)
|
||||
except ValueError:
|
||||
continue
|
||||
if held(path, entry.get("size")):
|
||||
sized.append((entry, path))
|
||||
else:
|
||||
needed.append(entry)
|
||||
# Only a copy of the right size is read, on the check's workers and
|
||||
# with its count: one at a time and silent, 400 files of a card read
|
||||
# as a hung run before the menu.
|
||||
needed += [entry for (entry, _path), verdict in zip(sized, read_in_place(sized))
|
||||
if verdict != "up_to_date"]
|
||||
needed = not_in_place(bios_path, files)
|
||||
copies = plan_local_copies(needed, bios_path, None, LOCAL.folders)
|
||||
if not copies:
|
||||
return ""
|
||||
@@ -557,30 +534,6 @@ def all_in_place(files: list[dict], trees: list[dict], bios_path: Path) -> bool:
|
||||
for tree in trees))
|
||||
|
||||
|
||||
def read_in_place(pairs: list[tuple[dict, Path]]) -> list[str]:
|
||||
"""_classify_local of each (entry, path), read before the line menu as
|
||||
the check after it reads: on --jobs workers, a count moving at a
|
||||
terminal, what is read kept for that check (_HEAD_READS). Each file is
|
||||
read once whatever the question: the head reads the files of the right
|
||||
size only, and the check after Enter reads none of them again."""
|
||||
if not pairs:
|
||||
return []
|
||||
live = _live_stdout()
|
||||
verdicts: list[str] = []
|
||||
last = 0.0
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=LOCAL.jobs) as pool:
|
||||
for done, verdict in enumerate(pool.map(
|
||||
lambda pair: _classify_local(pair[0], pair[1], remember=True), pairs), 1):
|
||||
verdicts.append(verdict)
|
||||
now = time.monotonic()
|
||||
if live and (now - last >= 0.1 or done == len(pairs)):
|
||||
last = now
|
||||
print(f"\r read {done}/{len(pairs)}", end="", flush=True)
|
||||
if live:
|
||||
print("\r\033[K", end="", flush=True)
|
||||
return verdicts
|
||||
|
||||
|
||||
def menu_choice(
|
||||
files: list[dict], omitted: list[dict],
|
||||
installed: tuple[list[dict], list[dict]] | None, current: object, cut: bool,
|
||||
|
||||
@@ -3,11 +3,13 @@ from __future__ import annotations
|
||||
|
||||
import concurrent.futures
|
||||
import hashlib
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import IO, TYPE_CHECKING
|
||||
|
||||
from installer.console import ReadCounter
|
||||
from installer.host_fs import _held
|
||||
from installer.console import ReadCounter, _live_stdout
|
||||
from installer.host_fs import _held, _is_file
|
||||
from installer.offline import LOCAL
|
||||
from installer.paths import _entry_path
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -164,3 +166,53 @@ def check_local(
|
||||
counter.end()
|
||||
|
||||
return to_download, up_to_date, mismatched
|
||||
|
||||
|
||||
def read_in_place(pairs: list[tuple[dict, Path]]) -> list[str]:
|
||||
"""_classify_local of each (entry, path), read before the line menu as
|
||||
the check after it reads: on --jobs workers, a count moving at a
|
||||
terminal, what is read kept for that check (_HEAD_READS). Each file is
|
||||
read once whatever the question: the head reads the files of the right
|
||||
size only, and the check after Enter reads none of them again."""
|
||||
if not pairs:
|
||||
return []
|
||||
live = _live_stdout()
|
||||
verdicts: list[str] = []
|
||||
last = 0.0
|
||||
with concurrent.futures.ThreadPoolExecutor(max_workers=LOCAL.jobs) as pool:
|
||||
for done, verdict in enumerate(pool.map(
|
||||
lambda pair: _classify_local(pair[0], pair[1], remember=True), pairs), 1):
|
||||
verdicts.append(verdict)
|
||||
now = time.monotonic()
|
||||
if live and (now - last >= 0.1 or done == len(pairs)):
|
||||
last = now
|
||||
print(f"\r read {done}/{len(pairs)}", end="", flush=True)
|
||||
if live:
|
||||
print("\r\033[K", end="", flush=True)
|
||||
return verdicts
|
||||
|
||||
|
||||
def not_in_place(bios_path: Path, files: list[dict]) -> list[dict]:
|
||||
"""The files a run puts in place: absent, of another size, or of the
|
||||
right size and not the list's. Only a copy of the right size is read,
|
||||
on the check's workers and with its count (read_in_place): judged by
|
||||
its size, a wrong copy of the right size was in place."""
|
||||
|
||||
def held(path: Path, size: object) -> bool:
|
||||
try:
|
||||
return _is_file(path) and path.stat().st_size == size
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
needed, sized = [], []
|
||||
for entry in files:
|
||||
try:
|
||||
path = _entry_path(bios_path, entry)
|
||||
except ValueError:
|
||||
continue
|
||||
if held(path, entry.get("size")):
|
||||
sized.append((entry, path))
|
||||
else:
|
||||
needed.append(entry)
|
||||
return needed + [entry for (entry, _path), verdict in zip(sized, read_in_place(sized))
|
||||
if verdict != "up_to_date"]
|
||||
+3
-10
@@ -1,14 +1,12 @@
|
||||
"""The plan shown before a download: what comes, its size and the space it needs."""
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
import sys
|
||||
from collections.abc import Collection
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from installer.datadirs import data_fetch_bytes
|
||||
from installer.host_fs import _exists
|
||||
from installer.invocation import _INVOCATION
|
||||
from installer.narrowing import _filter_by_target
|
||||
from installer.offline import LOCAL, _offline_only, offline_named, offline_undo
|
||||
@@ -16,6 +14,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.tally import _bytes, parts_words, tally
|
||||
from installer.terminal import terminal_size
|
||||
from installer.text import _plural, cell_width, format_size
|
||||
@@ -243,14 +242,8 @@ 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.
|
||||
"""
|
||||
probe = bios_path
|
||||
while not _exists(probe) and probe != probe.parent:
|
||||
probe = probe.parent
|
||||
try:
|
||||
free = shutil.disk_usage(probe).free
|
||||
except OSError:
|
||||
return
|
||||
if free >= needed:
|
||||
free = free_space(bios_path)
|
||||
if free is None or free >= needed:
|
||||
return
|
||||
print(f"\nNot enough space on the drive holding {bios_path}.", file=sys.stderr)
|
||||
print(f" Needed: {format_size(needed)}. Free: {format_size(free)}.",
|
||||
|
||||
+27
-23
@@ -1,19 +1,21 @@
|
||||
"""What a plan says on the line and on the screen: sizes, systems kept, space and folders."""
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
from collections.abc import Collection
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from installer.choices import GamesChoice, available_choices, recorded_axes
|
||||
from installer.destination import shown_bios_folder
|
||||
from installer.host_fs import _exists, _folder_writable, _nearest_folder
|
||||
from installer.datadirs import data_directory_state
|
||||
from installer.host_fs import _exists, _folder_writable
|
||||
from installer.local_check import not_in_place
|
||||
from installer.manifest import GAME_DATA, OTHER_SYSTEMS
|
||||
from installer.narrowing import _chosen, narrow
|
||||
from installer.outcome import _on_read_only_mount, write_remedy
|
||||
from installer.paths import _entry_path
|
||||
from installer.platforms import entry_systems, system_title
|
||||
from installer.space import bytes_written, free_space
|
||||
from installer.tally import game_data_missing, sized_words, tally
|
||||
from installer.text import _names_and, _no_widow, _wrap, cell_width, format_size
|
||||
|
||||
@@ -149,35 +151,37 @@ def systems_in_order(systems: list[str], files: list[dict], manifest: dict | Non
|
||||
in_place(system), system_title(system, manifest).casefold()))
|
||||
|
||||
|
||||
def _space_short(bios_path: Path, files: list[dict]) -> tuple[int, int] | None:
|
||||
"""(bytes needed, bytes free) when the files absent from the folder do
|
||||
not fit on its drive, None when they fit or it cannot be told. The
|
||||
screen's plan warns of this before Install, line mode only after Enter."""
|
||||
probe = _nearest_folder(bios_path)
|
||||
try:
|
||||
free = shutil.disk_usage(probe).free
|
||||
except OSError:
|
||||
def _space_short(bios_path: Path, files: list[dict],
|
||||
trees: Collection[dict] = ()) -> tuple[int, int] | None:
|
||||
"""(bytes needed, bytes free) when what the run writes (bytes_written:
|
||||
the files not in place, missing or replaced, and the data trees) does
|
||||
not fit on the folder's drive, None when it fits or it cannot be told.
|
||||
Counted as the run's refusal counts it: the absent files alone said
|
||||
nothing of a run that then stopped for space after Enter."""
|
||||
free = free_space(bios_path)
|
||||
if free is None:
|
||||
return None
|
||||
needed = 0
|
||||
for entry in files:
|
||||
try:
|
||||
where = _entry_path(bios_path, entry)
|
||||
except ValueError:
|
||||
continue
|
||||
if not _exists(where):
|
||||
needed += entry.get("size", 0)
|
||||
# Every file and every tree file written: what fits so needs no read.
|
||||
if bytes_written(files, [(tree, (bios_path, tree.get("files") or {}, 0))
|
||||
for tree in trees]) <= free:
|
||||
return None
|
||||
needed = bytes_written(not_in_place(bios_path, files),
|
||||
[(tree, data_directory_state(tree, bios_path, remember=True))
|
||||
for tree in trees])
|
||||
return (needed, free) if needed > free else None
|
||||
|
||||
|
||||
def folder_warnings(plat: str, bios_path: Path, files: list[dict], hint: Invocation,
|
||||
commands: bool = True, card: bool = False) -> list[str]:
|
||||
"""What the plan says of a folder the files cannot go to, before the
|
||||
question that installs them: the folder refused, or too small. card is
|
||||
a setup that runs from that card, whose own folder is the one it reads."""
|
||||
commands: bool = True, card: bool = False,
|
||||
trees: Collection[dict] = ()) -> list[str]:
|
||||
"""What the plan says of a folder the files and the data trees cannot go
|
||||
to, before the question that installs them: the folder refused, or too
|
||||
small. card is a setup that runs from that card, whose own folder is the
|
||||
one it reads."""
|
||||
lines = []
|
||||
if not _folder_writable(bios_path):
|
||||
lines += cannot_write_words(bios_path, plat, hint, commands, card)
|
||||
short = _space_short(bios_path, files)
|
||||
short = _space_short(bios_path, files, trees)
|
||||
if short is not None:
|
||||
lines.append(space_words(short[0], short[1], card))
|
||||
return lines
|
||||
|
||||
+14
-7
@@ -8,7 +8,7 @@ from pathlib import Path
|
||||
from typing import TYPE_CHECKING, TextIO
|
||||
|
||||
from installer.console import OUTPUT, Progress, _confirm, detail
|
||||
from installer.datadirs import data_directory_state, data_fetch_bytes, data_space_bytes, install_data_directory
|
||||
from installer.datadirs import data_directory_state, data_fetch_bytes, install_data_directory
|
||||
from installer.destination import _missing_dest, _refuse_closed, _refuse_file, on_its_card
|
||||
from installer.detect_frontends import launchbox_bios_dirs, launchbox_root
|
||||
from installer.detect_os import detected_shown
|
||||
@@ -68,6 +68,7 @@ from installer.run_setups import (
|
||||
_start_install,
|
||||
)
|
||||
from installer.safe_replace import KEPT, NOT_KEPT, plan_kept
|
||||
from installer.space import bytes_written
|
||||
from installer.standalone import do_standalone_copies, standalone_folders_here
|
||||
from installer.tally import (
|
||||
CheckTally,
|
||||
@@ -178,12 +179,17 @@ 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)),
|
||||
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)),
|
||||
chosen=selection[0] if selection else None,
|
||||
)
|
||||
emit_copies(p.plat_name, to_download, copies, bios_index, bios_path, files)
|
||||
@@ -401,13 +407,13 @@ def _pass_download_head(run: _InstallRun, p: _PlatformPass, fetched: list[dict],
|
||||
"carries on from here.")
|
||||
|
||||
|
||||
def _pass_make_folder(run: _InstallRun, p: _PlatformPass, dl_size: int) -> bool:
|
||||
def _pass_make_folder(run: _InstallRun, p: _PlatformPass, written: int) -> bool:
|
||||
"""The space checked and the BIOS folder made. True when it was created."""
|
||||
args, plat_name, bios_path = run.args, p.plat_name, p.bios_path
|
||||
# Checked before the folder is created: a run stopped for space
|
||||
# left an empty BIOS folder behind. The data trees count too,
|
||||
# written after the files on the same drive.
|
||||
_check_free_space(bios_path, dl_size + data_space_bytes(p.data_states), plat_name,
|
||||
_check_free_space(bios_path, written, plat_name,
|
||||
1 if run.total_downloaded else 2, on_its_card(plat_name, bios_path))
|
||||
p.space_checked = True
|
||||
created = not bios_path.exists()
|
||||
@@ -501,7 +507,8 @@ 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"
|
||||
dl_size = sum(f.get("size", 0) for f in p.to_download if id(f) not in lacking)
|
||||
coming = [f for f in p.to_download if id(f) not in lacking]
|
||||
dl_size = _bytes(coming)
|
||||
fetch_size = _bytes([f for f in fetched if id(f) not in lacking])
|
||||
if not p.to_download:
|
||||
run.total_up_to_date += len(p.up_to_date)
|
||||
@@ -515,7 +522,7 @@ def _pass_download(run: _InstallRun, p: _PlatformPass) -> str:
|
||||
return "next"
|
||||
EVENTS.emit("download", platform=p.plat_name, files=len(p.to_download), bytes=dl_size)
|
||||
_pass_download_head(run, p, fetched, lacking, dl_size)
|
||||
created = _pass_make_folder(run, p, dl_size)
|
||||
created = _pass_make_folder(run, p, bytes_written(coming, p.data_states))
|
||||
return "stop" if _pass_fetch(run, p, dl_size, created) else "go"
|
||||
|
||||
|
||||
@@ -603,7 +610,7 @@ def _pass_data_trees(run: _InstallRun, p: _PlatformPass) -> None:
|
||||
if writable and not p.space_checked:
|
||||
# With every BIOS file in place, the trees alone: checked
|
||||
# before the first archive is written.
|
||||
_check_free_space(p.bios_path, data_space_bytes(writable), p.plat_name,
|
||||
_check_free_space(p.bios_path, bytes_written([], writable), p.plat_name,
|
||||
1 if run.total_downloaded else 2,
|
||||
on_its_card(p.plat_name, p.bios_path))
|
||||
if writable:
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
"""What a run writes on the drive of its BIOS folder, and the free space it is held against."""
|
||||
from __future__ import annotations
|
||||
|
||||
import shutil
|
||||
from collections.abc import Iterable
|
||||
from pathlib import Path
|
||||
|
||||
from installer.datadirs import data_space_bytes
|
||||
from installer.host_fs import _nearest_folder
|
||||
|
||||
|
||||
def bytes_written(files: Iterable[dict],
|
||||
data_states: list[tuple[dict, tuple[Path, dict[str, dict], int]]]) -> int:
|
||||
"""The files a run puts in place, missing or replaced, and the data
|
||||
trees it rebuilds beside them (data_space_bytes). The line plan, the
|
||||
screen's plan and the run's refusal hold this one number against the
|
||||
free space: the plans counted the files absent alone, and a run they
|
||||
said nothing of stopped for space right after Enter."""
|
||||
return sum(entry.get("size", 0) for entry in files) + data_space_bytes(data_states)
|
||||
|
||||
|
||||
def free_space(bios_path: Path) -> int | None:
|
||||
"""The bytes free on the drive that holds bios_path, read at its nearest
|
||||
existing folder since it may not exist yet. None when it cannot be told."""
|
||||
try:
|
||||
return shutil.disk_usage(_nearest_folder(bios_path)).free
|
||||
except OSError:
|
||||
return None
|
||||
@@ -30,6 +30,7 @@ class CheckTally(NamedTuple):
|
||||
data_missing: int = 0
|
||||
not_installable: int = 0
|
||||
data_bytes: int = 0
|
||||
space_bytes: int = 0
|
||||
|
||||
|
||||
def _emit_check(
|
||||
@@ -99,6 +100,7 @@ def _emit_check(
|
||||
dests=[dest for dest, _s, _state in own_states],
|
||||
)
|
||||
EVENTS.emit("data", platform=plat, files=tally.data_missing, bytes=tally.data_bytes)
|
||||
EVENTS.emit("space", platform=plat, bytes=tally.space_bytes)
|
||||
|
||||
|
||||
def _declared_state(copy: dict, entry: dict, bios_path: Path) -> str:
|
||||
|
||||
@@ -281,9 +281,16 @@ def _dry_copies(state: TuiState) -> list[str]:
|
||||
return [event["dest"] for event in state.dry_files if event["dest"] in local]
|
||||
|
||||
|
||||
def space_needed(check: dict) -> int:
|
||||
"""What the run writes on the folder's drive, as its space event says
|
||||
it: the files and the data trees, the number its refusal holds against
|
||||
the free space. bytes_needed for a check that names none."""
|
||||
return check.get("space_bytes", check.get("bytes_needed", 0))
|
||||
|
||||
|
||||
def _short_of_space(state: TuiState, check: dict) -> bool:
|
||||
free = state.facts.get("free")
|
||||
return free is not None and check.get("bytes_needed", 0) > free
|
||||
return free is not None and space_needed(check) > free
|
||||
|
||||
|
||||
def _shared_needed(state: TuiState) -> dict[str, tuple[int, int]]:
|
||||
|
||||
@@ -48,6 +48,7 @@ from installer.tui_choice import (
|
||||
_tui_tally,
|
||||
games_plan_words,
|
||||
games_where,
|
||||
space_needed,
|
||||
tui_systems,
|
||||
tui_verbose,
|
||||
)
|
||||
@@ -315,8 +316,8 @@ def _plan_lines(check: dict, dest: Path | None, state: TuiState) -> list:
|
||||
free = state.facts.get("free")
|
||||
if free is not None:
|
||||
lines.append(_detail(f"Free space: {format_size(free)}"))
|
||||
if check["bytes_needed"] > free:
|
||||
lines.append(space_words(check["bytes_needed"], free, _on_its_card(state)))
|
||||
if space_needed(check) > free:
|
||||
lines.append(space_words(space_needed(check), free, _on_its_card(state)))
|
||||
backup = _plan_backups(check, state, fig)
|
||||
misplaced = _tui_misplaced(state) if check is state.check else []
|
||||
if misplaced:
|
||||
|
||||
@@ -119,6 +119,8 @@ def _take_check_event(state: TuiState, kind: str | None, event: dict) -> None:
|
||||
state.saves = event
|
||||
elif kind == "data" and state.check is not None:
|
||||
state.check["data_bytes"] = event["bytes"]
|
||||
elif kind == "space" and state.check is not None:
|
||||
state.check["space_bytes"] = event["bytes"]
|
||||
elif kind == "check":
|
||||
state.check = event
|
||||
elif kind == "file":
|
||||
@@ -136,6 +138,8 @@ def _take_dry_event(state: TuiState, kind: str | None, event: dict) -> None:
|
||||
state.dry_saves = event
|
||||
elif kind == "data" and state.dry is not None:
|
||||
state.dry["data_bytes"] = event["bytes"]
|
||||
elif kind == "space" and state.dry is not None:
|
||||
state.dry["space_bytes"] = event["bytes"]
|
||||
elif kind == "check":
|
||||
state.dry = event
|
||||
elif kind == "file" and event.get("state") != "present":
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"check",
|
||||
"declared",
|
||||
"data",
|
||||
"space",
|
||||
"found",
|
||||
"unreadable",
|
||||
"saves",
|
||||
@@ -106,6 +107,9 @@
|
||||
{
|
||||
"$ref": "#/$defs/data"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/space"
|
||||
},
|
||||
{
|
||||
"$ref": "#/$defs/found"
|
||||
},
|
||||
@@ -779,6 +783,27 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"space": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": [
|
||||
"event",
|
||||
"platform",
|
||||
"bytes"
|
||||
],
|
||||
"properties": {
|
||||
"event": {
|
||||
"const": "space"
|
||||
},
|
||||
"platform": {
|
||||
"type": "string"
|
||||
},
|
||||
"bytes": {
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
}
|
||||
},
|
||||
"found": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
|
||||
+54
-1
@@ -451,10 +451,60 @@ class TestFreeSpaceGuard(unittest.TestCase):
|
||||
|
||||
def test_the_space_check_comes_before_the_folder(self):
|
||||
source = (REPO_ROOT / "install.py").read_text(encoding="utf-8")
|
||||
check = source.index("_check_free_space(bios_path, dl_size")
|
||||
check = source.index("_check_free_space(bios_path, written")
|
||||
self.assertLess(check, source.index("bios_path.mkdir(parents=True, exist_ok=True)"))
|
||||
|
||||
|
||||
class ThePlansCountWhatTheRunRefusesOn(unittest.TestCase):
|
||||
"""The line plan counted the absent files alone: a file in place with
|
||||
the wrong bytes, to be replaced, gave no warning at 100 B free, and the
|
||||
run stopped for space right after Enter."""
|
||||
|
||||
def setUp(self):
|
||||
self.root = scratch_dir(self)
|
||||
self.addCleanup(shutil.rmtree, self.root, True)
|
||||
# The plan's reads are kept for the check after it.
|
||||
install.head_reads_done()
|
||||
self.addCleanup(install.head_reads_done)
|
||||
wrong = b"w" * 1000
|
||||
(self.root / "a.bin").write_bytes(wrong)
|
||||
right = b"r" * 1000
|
||||
self.files = [{"dest": "a.bin", "size": 1000,
|
||||
"sha1": hashlib.sha1(right).hexdigest()}]
|
||||
|
||||
def short(self, free: int, trees: list[dict] | None = None) -> tuple[int, int] | None:
|
||||
with unittest.mock.patch.object(install.shutil, "disk_usage",
|
||||
lambda _p: SimpleNamespace(free=free)):
|
||||
return install._space_short(self.root, self.files, trees or [])
|
||||
|
||||
def test_a_file_to_replace_is_counted(self):
|
||||
self.assertEqual(self.short(100), (1000, 100))
|
||||
self.assertEqual(self.short(100), (install.bytes_written(self.files, []), 100))
|
||||
|
||||
def test_a_file_in_place_is_not(self):
|
||||
(self.root / "a.bin").write_bytes(b"r" * 1000)
|
||||
self.assertIsNone(self.short(100))
|
||||
|
||||
def test_the_data_trees_count(self):
|
||||
(self.root / "a.bin").write_bytes(b"r" * 1000)
|
||||
tree = {"ref": "t", "dest": "tree", "systems": [], "files": {
|
||||
"x.bin": {"sha1": hashlib.sha1(b"x").hexdigest(), "size": 500}}}
|
||||
with unittest.mock.patch.object(install, "_offline_only", return_value=False):
|
||||
# The tree's file, and its source beside it until it is read:
|
||||
# a list that records no archive size gives the files' sizes.
|
||||
self.assertEqual(self.short(100, [tree]), (1000, 100))
|
||||
|
||||
def test_what_fits_whole_reads_nothing(self):
|
||||
with unittest.mock.patch.object(install, "read_in_place") as read:
|
||||
self.assertIsNone(self.short(10_000))
|
||||
read.assert_not_called()
|
||||
|
||||
def test_a_check_says_the_space_it_needs(self):
|
||||
self.assertIn("space", install.EVENT_KEYS)
|
||||
source = (REPO_ROOT / "install.py").read_text(encoding="utf-8")
|
||||
self.assertIn('EVENTS.emit("space", platform=plat, bytes=tally.space_bytes)', source)
|
||||
|
||||
|
||||
class TheDataTreesCountInTheFreeSpace(unittest.TestCase):
|
||||
"""The space check held only the BIOS files: 18.8 KB passed on a card
|
||||
with 20 MB free, then 55.4 MB of archives came and 81.8 MB were written,
|
||||
@@ -7050,6 +7100,9 @@ class EventsDescribeTheRun(unittest.TestCase, _SyntheticTree):
|
||||
"dests": ["a.bin", "b.bin", "c.bin", "d.bin"]},
|
||||
# No data tree in this list.
|
||||
{"event": "data", "platform": "retroarch", "files": 0, "bytes": 0},
|
||||
# The missing and the wrong copy, written: what the run holds
|
||||
# against the free space.
|
||||
{"event": "space", "platform": "retroarch", "bytes": 245},
|
||||
]
|
||||
|
||||
SKIPPED = [{"reason": "not_found", "label": "not found", "files": 1, "required": 1}]
|
||||
|
||||
@@ -7873,6 +7873,18 @@ class _LineModeFindings(_CardFixtures):
|
||||
lines = install.folder_warnings("retroarch", self.root, [], hint, True, True)
|
||||
self.assertEqual(lines, [install.read_only_words(self.root)])
|
||||
|
||||
def test_the_plan_warns_on_the_space_the_run_refuses_on(self):
|
||||
"""The screen held the files missing or wrong against the free space,
|
||||
the run those and the data trees: a plan without a warning stopped
|
||||
for space right after Install."""
|
||||
state = fresh_state()
|
||||
state.facts["free"] = 1000
|
||||
check = {"bytes_needed": 500}
|
||||
self.assertFalse(install._short_of_space(state, check))
|
||||
check["space_bytes"] = 5000
|
||||
self.assertTrue(install._short_of_space(state, check))
|
||||
self.assertEqual(install.space_needed(check), 5000)
|
||||
|
||||
|
||||
|
||||
class _OutsideTextFindings:
|
||||
|
||||
@@ -503,7 +503,7 @@ those it imports:
|
||||
| This machine | `detection_notes`, `detect_os`, `detect_frontends`, `cards`, `device`, `cores`, `frontend_folders`, `setups` |
|
||||
| Sources of files | `offline`, `network`, `pack_source`, `from_folders`, `diagnosis`, `download`, `datadirs`, `standalone` |
|
||||
| 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` |
|
||||
| What a run keeps | `narrowing`, `choices`, `romm`, `install_record`, `game_files`, `games`, `tally`, `space` |
|
||||
| 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_engine`, `tui_session` |
|
||||
|
||||
+2
-1
@@ -2241,6 +2241,7 @@ other schemas under `api/v1/schemas/`.
|
||||
| `check` | `platform`, `name`, `bios_dir`, `files`, `present`, `missing`, `wrong_hash`, `bytes_needed`, `data_missing`, `not_installable` | The platform's totals. `data_missing` counts data-tree files to fetch, `not_installable` the files the collection cannot supply |
|
||||
| `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 |
|
||||
| `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 `<system>` and `<core>` 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`) |
|
||||
@@ -2260,7 +2261,7 @@ other schemas under `api/v1/schemas/`.
|
||||
|
||||
<!-- /generated: events -->
|
||||
|
||||
Schema 1 can gain a kind (`found` came with `--from`, `declared` with `--declared-only`, `unsearched` with the search that goes on past a closed folder, `app` with `--add-app`, `data` with the size of the data trees, `version` with the list's version, `record` with the install record, `removal_plan`, `removed`, `restored` and `backup` with removal, `pack` with `--pack`), never a key of an
|
||||
Schema 1 can gain a kind (`found` came with `--from`, `declared` with `--declared-only`, `unsearched` with the search that goes on past a closed folder, `app` with `--add-app`, `data` with the size of the data trees, `space` with the space the run writes, `version` with the list's version, `record` with the install record, `removal_plan`, `removed`, `restored` and `backup` with removal, `pack` with `--pack`), never a key of an
|
||||
existing kind: a reader skips a kind it does not know. An option refused
|
||||
before the run starts (`install.py: error:`, code 2) writes
|
||||
no event at all. A program reads a missing `end` as that case, or as a
|
||||
|
||||
Reference in new issue
Block a user