mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-12-02 14:28:54 -06:00
refactor: one rule for failed files in both modes
This commit is contained in:
1 parent
bd82a502c2
commit
7b0a5d5d4a
8 files changed
+93
-83
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 = "05baee4e5726bbd8fff854f373b77d86293db2fc47b838ba5bae677df8a1da45"
|
||||
$defaultInstallSha256 = "4e30340981c2e28c197256042d005361196eda47f3490fae52f823b7da1f4a20"
|
||||
# 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
|
||||
|
||||
+29
-36
@@ -11660,6 +11660,31 @@ def split_offline(records: list[Failure]) -> tuple[list[Failure], list[Failure]]
|
||||
[record for record in records if record.kind == "offline"])
|
||||
|
||||
|
||||
FAILED_LINES_CAP = 10
|
||||
|
||||
|
||||
def failed_lines(records: list[Failure], said: Iterable[str] = ()) -> list[str]:
|
||||
"""The failed files in both modes: a reason two files or more share is
|
||||
said once with their count, so each cause reads once like its remedy, and
|
||||
at most FAILED_LINES_CAP lines. said: files the progress already named."""
|
||||
causes: dict[str, list[str]] = {}
|
||||
for record in records:
|
||||
causes.setdefault(record.reason, []).append(record.dest)
|
||||
named = set(said)
|
||||
entries: list[tuple[str, int]] = []
|
||||
for reason, dests in causes.items():
|
||||
if reason and len(dests) > 1:
|
||||
# A read-only folder fails every file alike: said once.
|
||||
entries.append((f" failed: {_plural(len(dests), 'file')} ({reason}), "
|
||||
f"first {dests[0]}", len(dests)))
|
||||
continue
|
||||
entries += [(f" failed: {dest}" + (f" ({reason})" if reason else ""), 1)
|
||||
for dest in dests if dest not in named]
|
||||
lines = [line for line, _count in entries[:FAILED_LINES_CAP]]
|
||||
more = sum(count for _line, count in entries[FAILED_LINES_CAP:])
|
||||
return lines + ([f" ... and {more} more"] if more else [])
|
||||
|
||||
|
||||
def _http_failure_lines(records: list[Failure]) -> list[str]:
|
||||
"""The address the first refused file was asked at, and what chose it:
|
||||
a mirror named with RETROBIOS_BASE_URL that holds the lists and not yet
|
||||
@@ -16467,21 +16492,11 @@ class _Ending(NamedTuple):
|
||||
|
||||
|
||||
def _say_failures(say: Callable[..., None], failures: list[Failure]) -> None:
|
||||
"""The failed files the progress has not named, one cause said once."""
|
||||
reasons = {record.reason for record in failures}
|
||||
"""The failed files the progress has not named, as the screen lists them."""
|
||||
# A failure the progress already named on its FAILED line is not named
|
||||
# again: line mode listed each one twice.
|
||||
unsaid = [record for record in failures if record.dest not in SAID_FAILED]
|
||||
if failures and len(failures) > 1 and len(reasons) == 1 and reasons != {""}:
|
||||
# One cause, said once: a read-only folder listed ten of its files
|
||||
# and "... and 266 more" above the advice that fixes them all.
|
||||
said = f", first {unsaid[0].dest}" if unsaid else ""
|
||||
say(f" failed: {_plural(len(failures), 'file')} ({reasons.pop()}){said}")
|
||||
else:
|
||||
for dest, reason, _kind, _url in unsaid[:10]:
|
||||
say(f" failed: {dest}" + (f" ({reason})" if reason else ""))
|
||||
if len(unsaid) > 10:
|
||||
say(f" ... and {len(unsaid) - 10} more")
|
||||
for line in failed_lines(failures, SAID_FAILED):
|
||||
say(line)
|
||||
|
||||
|
||||
def _failure_advice(
|
||||
@@ -27824,28 +27839,6 @@ def _outcome_placed(state: TuiState, counts: _OutcomeCounts, title: str) -> list
|
||||
return lines
|
||||
|
||||
|
||||
def _failure_lines(failed: list[Failure]) -> list[str]:
|
||||
"""Each file that failed with its reason, a reason shared by many said once."""
|
||||
lines: list[str] = []
|
||||
causes: dict[str, list[str]] = {}
|
||||
for failure in failed:
|
||||
causes.setdefault(failure.reason, []).append(failure.dest)
|
||||
shown = 0
|
||||
for reason, dests in causes.items():
|
||||
if len(dests) > 3:
|
||||
# A read-only folder fails every file alike: said once.
|
||||
lines.append(f" {len(dests)} files failed, all for one reason: "
|
||||
f"{reason or 'none given'}.")
|
||||
continue
|
||||
for dest in dests:
|
||||
if shown < 20:
|
||||
lines.append(f" failed: {dest}" + (f" ({reason})" if reason else ""))
|
||||
shown += 1
|
||||
if shown > 20:
|
||||
lines.append(f" ... and {shown - 20} more")
|
||||
return lines
|
||||
|
||||
|
||||
def _remedy_lines(state: TuiState, failed: list[Failure]) -> list[str]:
|
||||
"""What to do about each cause, the words line mode gives: the screen
|
||||
ended a mirror's 404 or a proxy's refusal on "Run it again"."""
|
||||
@@ -27936,7 +27929,7 @@ def tui_outcome(state: TuiState) -> tuple[str, list[str]]:
|
||||
title, head = _outcome_head(state, counts)
|
||||
lines = _outcome_counted(state, counts, title, head)
|
||||
lines += _outcome_placed(state, counts, title)
|
||||
lines += _failure_lines(counts.failed)
|
||||
lines += failed_lines(counts.failed)
|
||||
lines += _remedy_lines(state, counts.failed)
|
||||
if title == "Finished with errors":
|
||||
lines += _retry_lines(counts.failed)
|
||||
|
||||
+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="05baee4e5726bbd8fff854f373b77d86293db2fc47b838ba5bae677df8a1da45"
|
||||
DEFAULT_INSTALL_SHA256="4e30340981c2e28c197256042d005361196eda47f3490fae52f823b7da1f4a20"
|
||||
# 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": 1487998,
|
||||
"sha256": "05baee4e5726bbd8fff854f373b77d86293db2fc47b838ba5bae677df8a1da45",
|
||||
"size": 1487677,
|
||||
"sha256": "4e30340981c2e28c197256042d005361196eda47f3490fae52f823b7da1f4a20",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -71,8 +71,8 @@
|
||||
"muos": {
|
||||
"archive": {
|
||||
"dest": "ARCHIVE/RetroBIOS.muxapp",
|
||||
"size": 1541623,
|
||||
"sha256": "176e5a7e04ac8e61e34204e320fac43a88d398971be1deefa7d715654b839f8d"
|
||||
"size": 1541302,
|
||||
"sha256": "e4ad81376894def15823a914b5173b8f6b67ee10be663836ca33c05044134937"
|
||||
},
|
||||
"members": [
|
||||
{
|
||||
@@ -92,8 +92,8 @@
|
||||
{
|
||||
"name": "RetroBIOS/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1487998,
|
||||
"sha256": "05baee4e5726bbd8fff854f373b77d86293db2fc47b838ba5bae677df8a1da45",
|
||||
"size": 1487677,
|
||||
"sha256": "4e30340981c2e28c197256042d005361196eda47f3490fae52f823b7da1f4a20",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -166,8 +166,8 @@
|
||||
{
|
||||
"dest": ".config/modules/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1487998,
|
||||
"sha256": "05baee4e5726bbd8fff854f373b77d86293db2fc47b838ba5bae677df8a1da45",
|
||||
"size": 1487677,
|
||||
"sha256": "4e30340981c2e28c197256042d005361196eda47f3490fae52f823b7da1f4a20",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
|
||||
@@ -96,6 +96,31 @@ def split_offline(records: list[Failure]) -> tuple[list[Failure], list[Failure]]
|
||||
[record for record in records if record.kind == "offline"])
|
||||
|
||||
|
||||
FAILED_LINES_CAP = 10
|
||||
|
||||
|
||||
def failed_lines(records: list[Failure], said: Iterable[str] = ()) -> list[str]:
|
||||
"""The failed files in both modes: a reason two files or more share is
|
||||
said once with their count, so each cause reads once like its remedy, and
|
||||
at most FAILED_LINES_CAP lines. said: files the progress already named."""
|
||||
causes: dict[str, list[str]] = {}
|
||||
for record in records:
|
||||
causes.setdefault(record.reason, []).append(record.dest)
|
||||
named = set(said)
|
||||
entries: list[tuple[str, int]] = []
|
||||
for reason, dests in causes.items():
|
||||
if reason and len(dests) > 1:
|
||||
# A read-only folder fails every file alike: said once.
|
||||
entries.append((f" failed: {_plural(len(dests), 'file')} ({reason}), "
|
||||
f"first {dests[0]}", len(dests)))
|
||||
continue
|
||||
entries += [(f" failed: {dest}" + (f" ({reason})" if reason else ""), 1)
|
||||
for dest in dests if dest not in named]
|
||||
lines = [line for line, _count in entries[:FAILED_LINES_CAP]]
|
||||
more = sum(count for _line, count in entries[FAILED_LINES_CAP:])
|
||||
return lines + ([f" ... and {more} more"] if more else [])
|
||||
|
||||
|
||||
def _http_failure_lines(records: list[Failure]) -> list[str]:
|
||||
"""The address the first refused file was asked at, and what chose it:
|
||||
a mirror named with RETROBIOS_BASE_URL that holds the lists and not yet
|
||||
|
||||
+4
-13
@@ -18,6 +18,7 @@ from installer.detect_os import detected_os
|
||||
from installer.failure_causes import (
|
||||
Failure,
|
||||
connection_only,
|
||||
failed_lines,
|
||||
failure_records,
|
||||
failure_remedies,
|
||||
retry_helps,
|
||||
@@ -203,21 +204,11 @@ class _Ending(NamedTuple):
|
||||
|
||||
|
||||
def _say_failures(say: Callable[..., None], failures: list[Failure]) -> None:
|
||||
"""The failed files the progress has not named, one cause said once."""
|
||||
reasons = {record.reason for record in failures}
|
||||
"""The failed files the progress has not named, as the screen lists them."""
|
||||
# A failure the progress already named on its FAILED line is not named
|
||||
# again: line mode listed each one twice.
|
||||
unsaid = [record for record in failures if record.dest not in SAID_FAILED]
|
||||
if failures and len(failures) > 1 and len(reasons) == 1 and reasons != {""}:
|
||||
# One cause, said once: a read-only folder listed ten of its files
|
||||
# and "... and 266 more" above the advice that fixes them all.
|
||||
said = f", first {unsaid[0].dest}" if unsaid else ""
|
||||
say(f" failed: {_plural(len(failures), 'file')} ({reasons.pop()}){said}")
|
||||
else:
|
||||
for dest, reason, _kind, _url in unsaid[:10]:
|
||||
say(f" failed: {dest}" + (f" ({reason})" if reason else ""))
|
||||
if len(unsaid) > 10:
|
||||
say(f" ... and {len(unsaid) - 10} more")
|
||||
for line in failed_lines(failures, SAID_FAILED):
|
||||
say(line)
|
||||
|
||||
|
||||
def _failure_advice(
|
||||
|
||||
@@ -10,6 +10,7 @@ from installer.detect_os import detected_os
|
||||
from installer.failure_causes import (
|
||||
Failure,
|
||||
event_records,
|
||||
failed_lines,
|
||||
failure_records,
|
||||
failure_remedies,
|
||||
retry_helps,
|
||||
@@ -244,28 +245,6 @@ def _outcome_placed(state: TuiState, counts: _OutcomeCounts, title: str) -> list
|
||||
return lines
|
||||
|
||||
|
||||
def _failure_lines(failed: list[Failure]) -> list[str]:
|
||||
"""Each file that failed with its reason, a reason shared by many said once."""
|
||||
lines: list[str] = []
|
||||
causes: dict[str, list[str]] = {}
|
||||
for failure in failed:
|
||||
causes.setdefault(failure.reason, []).append(failure.dest)
|
||||
shown = 0
|
||||
for reason, dests in causes.items():
|
||||
if len(dests) > 3:
|
||||
# A read-only folder fails every file alike: said once.
|
||||
lines.append(f" {len(dests)} files failed, all for one reason: "
|
||||
f"{reason or 'none given'}.")
|
||||
continue
|
||||
for dest in dests:
|
||||
if shown < 20:
|
||||
lines.append(f" failed: {dest}" + (f" ({reason})" if reason else ""))
|
||||
shown += 1
|
||||
if shown > 20:
|
||||
lines.append(f" ... and {shown - 20} more")
|
||||
return lines
|
||||
|
||||
|
||||
def _remedy_lines(state: TuiState, failed: list[Failure]) -> list[str]:
|
||||
"""What to do about each cause, the words line mode gives: the screen
|
||||
ended a mirror's 404 or a proxy's refusal on "Run it again"."""
|
||||
@@ -356,7 +335,7 @@ def tui_outcome(state: TuiState) -> tuple[str, list[str]]:
|
||||
title, head = _outcome_head(state, counts)
|
||||
lines = _outcome_counted(state, counts, title, head)
|
||||
lines += _outcome_placed(state, counts, title)
|
||||
lines += _failure_lines(counts.failed)
|
||||
lines += failed_lines(counts.failed)
|
||||
lines += _remedy_lines(state, counts.failed)
|
||||
if title == "Finished with errors":
|
||||
lines += _retry_lines(counts.failed)
|
||||
|
||||
@@ -2319,7 +2319,29 @@ class TicksBarAndPaths(unittest.TestCase):
|
||||
_title, lines = install.tui_outcome(state)
|
||||
self.assertEqual([line for line in lines if "failed" in line],
|
||||
["Nothing was installed: 50 files failed.",
|
||||
" 50 files failed, all for one reason: folder not writable."])
|
||||
" failed: 50 files (folder not writable), first f0.bin"])
|
||||
|
||||
def test_failures_read_alike_in_both_modes(self):
|
||||
"""The screen grouped a reason past three files and capped at 20
|
||||
lines, line mode grouped one shared reason and capped at 10."""
|
||||
failed = ([{"dest": f"ro{n}.bin", "reason": "folder not writable"} for n in range(5)]
|
||||
+ [{"dest": "a.bin", "reason": "HTTP 404"}]
|
||||
+ [{"dest": f"cut{n}.bin", "reason": f"timed out {n}"} for n in range(12)])
|
||||
state = checked_state()
|
||||
state.stack.append("result")
|
||||
state.code = 1
|
||||
state.summary = {"installed": 1, "up_to_date": 0, "failed": failed}
|
||||
_title, lines = install.tui_outcome(state)
|
||||
screen = [line for line in lines if line.startswith((" failed:", " ..."))]
|
||||
said: list[str] = []
|
||||
records = install.event_records(failed)
|
||||
with mock.patch.object(install, "SAID_FAILED", set()):
|
||||
install._say_failures(said.append, records)
|
||||
self.assertEqual(screen, said)
|
||||
self.assertEqual(said[0], " failed: 5 files (folder not writable), first ro0.bin")
|
||||
self.assertEqual(said[1], " failed: a.bin (HTTP 404)")
|
||||
self.assertEqual(len(said), install.FAILED_LINES_CAP + 1)
|
||||
self.assertEqual(said[-1], " ... and 4 more")
|
||||
|
||||
def test_folder_inside_a_card_offers_its_root(self):
|
||||
card = Path(tempfile.mkdtemp())
|
||||
|
||||
Reference in new issue
Block a user