mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-28 12:28:51 -06:00
refactor: join names and date records in one place
Five sentences joined names by hand beside _names_and, the plan counted "more systems" beside _plural, a record stamped its time beside _record_now, and the record day and the backup day each formatted a date. Each now calls the one helper.
This commit is contained in:
1 parent
f412f7803d
commit
68378b4423
10 files changed
+47
-41
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 = "3533c56793b7c63942b2ee4882dd4b32bde8958a7c8ccf7ee4d60824b9e74076"
|
||||
$defaultInstallSha256 = "f1d12cfa6ab895adc88f3af123aef70f38a22d2dc1ed4832f4662b990fe1b8d9"
|
||||
# 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
|
||||
|
||||
+17
-14
@@ -9628,6 +9628,14 @@ RECORD_CHOICE = ("--system", "--core", "--emulator", "--region", "--for-games",
|
||||
RECORD_NARROWING = tuple(flag for flag in RECORD_CHOICE if flag != "--all-files")
|
||||
_MONTHS = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
|
||||
"Dec")
|
||||
|
||||
|
||||
def day_words(when: datetime.datetime) -> str:
|
||||
"""A day as a list says it: 3 Nov, its year when not this one."""
|
||||
day = f"{when.day} {_MONTHS[when.month - 1]}"
|
||||
return day if when.year == datetime.datetime.now().year else f"{day} {when.year}"
|
||||
|
||||
|
||||
# The records already said unreadable in this run, said once each.
|
||||
_RECORD_SAID: set[str] = set()
|
||||
# Per platform, the record whose choice this run took (apply_record).
|
||||
@@ -9801,8 +9809,7 @@ def record_day(setup: dict) -> str:
|
||||
local = when.astimezone()
|
||||
except (KeyError, TypeError, AttributeError, ValueError, OverflowError, OSError):
|
||||
return ""
|
||||
day = f"{local.day} {_MONTHS[local.month - 1]}"
|
||||
return day if local.year == datetime.datetime.now().year else f"{day} {local.year}"
|
||||
return day_words(local)
|
||||
|
||||
|
||||
def record_options(argv: list[str]) -> list[tuple[str, str | None]]:
|
||||
@@ -9902,7 +9909,7 @@ def write_record(
|
||||
for item in files:
|
||||
merged[(item["root"], item["dest"])] = item
|
||||
setup = {
|
||||
"written": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
||||
"written": _record_now(),
|
||||
"list": {"version": manifest.get("version"), "generated": manifest.get("generated")},
|
||||
"choice": choice,
|
||||
"files": [merged[key] for key in sorted(merged)],
|
||||
@@ -11218,7 +11225,7 @@ def installed_words(bios: int, games: int, data: int = 0) -> str:
|
||||
(bios, "BIOS file"), (games, "game data file"), (data, "data file")) if count]
|
||||
if not parts:
|
||||
return _plural(0, "file")
|
||||
return f"{', '.join(parts[:-1])} and {parts[-1]}" if len(parts) > 1 else parts[0]
|
||||
return _names_and(parts)
|
||||
|
||||
|
||||
def parts_words(counts: Tally, data: int = 0, data_size: int | None = None,
|
||||
@@ -11240,7 +11247,7 @@ def parts_words(counts: Tally, data: int = 0, data_size: int | None = None,
|
||||
+ (f" ({format_size(data_size)})" if data_size is not None else ""))
|
||||
if len(parts) < 2 and not left_out:
|
||||
return ""
|
||||
text = f"{', '.join(parts[:-1])} and {parts[-1]}" if len(parts) > 1 else parts[0]
|
||||
text = _names_and(parts)
|
||||
return text + (f". {_plural(left_out, 'game data file')} left out" if left_out else "")
|
||||
|
||||
|
||||
@@ -19434,8 +19441,7 @@ def choosable_systems(files: list[dict], omitted: list[dict],
|
||||
def emptied_words(names: list[str], game_data: bool) -> str:
|
||||
"""What a choice that keeps no file says, on the plan and in line mode,
|
||||
in place of "Everything is in place": Sega Dreamcast holds only game data."""
|
||||
subject = (", ".join(names[:-1]) + " and " + names[-1]) if len(names) > 1 else (
|
||||
names[0] if names else "This choice")
|
||||
subject = _names_and(names) if names else "This choice"
|
||||
verb = "hold" if len(names) > 1 else "holds"
|
||||
why = "only game data" if game_data else "no file under these options"
|
||||
return f"{subject} {verb} {why}: nothing is left to install."
|
||||
@@ -19570,7 +19576,7 @@ def narrowing_words(files: list[dict], omitted: list[dict]) -> str:
|
||||
("systems", "systems", len(listed_systems(files)) > 1),
|
||||
("cores", "cores", len(choices["cores"]) > 1),
|
||||
("regions", "regions", bool(choices["regions"]))) if axis in axes and enough]
|
||||
return f"{', '.join(named[:-1])} and {named[-1]}" if len(named) > 1 else "".join(named)
|
||||
return _names_and(named)
|
||||
|
||||
|
||||
def chosen_flags(choice: object) -> list[tuple[str, str | None]]:
|
||||
@@ -20362,7 +20368,7 @@ def _print_largest_systems(
|
||||
# Counted as the line above counts: the groups, when it names them.
|
||||
unit = "group" if "groups" in groups else "system"
|
||||
more = len(largest) - PLAN_LARGEST_SYSTEMS
|
||||
print(f" ... and {more} more {unit}{'s' if more > 1 else ''}: --verbose lists "
|
||||
print(f" ... and {_plural(more, 'more ' + unit)}: --verbose lists "
|
||||
"every system and its files.")
|
||||
|
||||
|
||||
@@ -21287,10 +21293,7 @@ def backup_words(date: str) -> str:
|
||||
when = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
|
||||
except ValueError:
|
||||
return date or "unknown date"
|
||||
day = f"{when.day} {_MONTHS[when.month - 1]}"
|
||||
if when.year != datetime.datetime.now().year:
|
||||
day += f" {when.year}"
|
||||
return f"{day} {when.hour:02d}:{when.minute:02d}"
|
||||
return f"{day_words(when)} {when.hour:02d}:{when.minute:02d}"
|
||||
|
||||
|
||||
def list_backups(folder: Path) -> list[dict]:
|
||||
@@ -24080,7 +24083,7 @@ def _choice_in_place(state: TuiState) -> str:
|
||||
return ""
|
||||
titles = _system_titles(state)
|
||||
names = [_tui_system_label(row, titles) for row in chosen]
|
||||
subject = (", ".join(names[:-1]) + " and " + names[-1]) if len(names) > 1 else names[0]
|
||||
subject = _names_and(names)
|
||||
return f"{subject} {'are' if len(names) > 1 else 'is'} in place: nothing is left to install."
|
||||
|
||||
|
||||
|
||||
+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="3533c56793b7c63942b2ee4882dd4b32bde8958a7c8ccf7ee4d60824b9e74076"
|
||||
DEFAULT_INSTALL_SHA256="f1d12cfa6ab895adc88f3af123aef70f38a22d2dc1ed4832f4662b990fe1b8d9"
|
||||
# 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": 1448586,
|
||||
"sha256": "3533c56793b7c63942b2ee4882dd4b32bde8958a7c8ccf7ee4d60824b9e74076",
|
||||
"size": 1448230,
|
||||
"sha256": "f1d12cfa6ab895adc88f3af123aef70f38a22d2dc1ed4832f4662b990fe1b8d9",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -71,8 +71,8 @@
|
||||
"muos": {
|
||||
"archive": {
|
||||
"dest": "ARCHIVE/RetroBIOS.muxapp",
|
||||
"size": 1502211,
|
||||
"sha256": "4cc5edafcfb9e9e2c1d42bd9814e172d6439b4ec4da68fa3bba7a81009c8f70f"
|
||||
"size": 1501855,
|
||||
"sha256": "45ca767858ca5be807703201046bbca6125f535e8fd46ef4bff672c198e27080"
|
||||
},
|
||||
"members": [
|
||||
{
|
||||
@@ -92,8 +92,8 @@
|
||||
{
|
||||
"name": "RetroBIOS/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1448586,
|
||||
"sha256": "3533c56793b7c63942b2ee4882dd4b32bde8958a7c8ccf7ee4d60824b9e74076",
|
||||
"size": 1448230,
|
||||
"sha256": "f1d12cfa6ab895adc88f3af123aef70f38a22d2dc1ed4832f4662b990fe1b8d9",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
@@ -166,8 +166,8 @@
|
||||
{
|
||||
"dest": ".config/modules/retrobios/install.py",
|
||||
"repo_path": "install.py",
|
||||
"size": 1448586,
|
||||
"sha256": "3533c56793b7c63942b2ee4882dd4b32bde8958a7c8ccf7ee4d60824b9e74076",
|
||||
"size": 1448230,
|
||||
"sha256": "f1d12cfa6ab895adc88f3af123aef70f38a22d2dc1ed4832f4662b990fe1b8d9",
|
||||
"executable": false
|
||||
},
|
||||
{
|
||||
|
||||
@@ -47,6 +47,14 @@ RECORD_CHOICE = ("--system", "--core", "--emulator", "--region", "--for-games",
|
||||
RECORD_NARROWING = tuple(flag for flag in RECORD_CHOICE if flag != "--all-files")
|
||||
_MONTHS = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov",
|
||||
"Dec")
|
||||
|
||||
|
||||
def day_words(when: datetime.datetime) -> str:
|
||||
"""A day as a list says it: 3 Nov, its year when not this one."""
|
||||
day = f"{when.day} {_MONTHS[when.month - 1]}"
|
||||
return day if when.year == datetime.datetime.now().year else f"{day} {when.year}"
|
||||
|
||||
|
||||
# The records already said unreadable in this run, said once each.
|
||||
_RECORD_SAID: set[str] = set()
|
||||
# Per platform, the record whose choice this run took (apply_record).
|
||||
@@ -220,8 +228,7 @@ def record_day(setup: dict) -> str:
|
||||
local = when.astimezone()
|
||||
except (KeyError, TypeError, AttributeError, ValueError, OverflowError, OSError):
|
||||
return ""
|
||||
day = f"{local.day} {_MONTHS[local.month - 1]}"
|
||||
return day if local.year == datetime.datetime.now().year else f"{day} {local.year}"
|
||||
return day_words(local)
|
||||
|
||||
|
||||
def record_options(argv: list[str]) -> list[tuple[str, str | None]]:
|
||||
@@ -321,7 +328,7 @@ def write_record(
|
||||
for item in files:
|
||||
merged[(item["root"], item["dest"])] = item
|
||||
setup = {
|
||||
"written": datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
||||
"written": _record_now(),
|
||||
"list": {"version": manifest.get("version"), "generated": manifest.get("generated")},
|
||||
"choice": choice,
|
||||
"files": [merged[key] for key in sorted(merged)],
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ def _print_largest_systems(
|
||||
# Counted as the line above counts: the groups, when it names them.
|
||||
unit = "group" if "groups" in groups else "system"
|
||||
more = len(largest) - PLAN_LARGEST_SYSTEMS
|
||||
print(f" ... and {more} more {unit}{'s' if more > 1 else ''}: --verbose lists "
|
||||
print(f" ... and {_plural(more, 'more ' + unit)}: --verbose lists "
|
||||
"every system and its files.")
|
||||
|
||||
|
||||
|
||||
@@ -100,8 +100,7 @@ def choosable_systems(files: list[dict], omitted: list[dict],
|
||||
def emptied_words(names: list[str], game_data: bool) -> str:
|
||||
"""What a choice that keeps no file says, on the plan and in line mode,
|
||||
in place of "Everything is in place": Sega Dreamcast holds only game data."""
|
||||
subject = (", ".join(names[:-1]) + " and " + names[-1]) if len(names) > 1 else (
|
||||
names[0] if names else "This choice")
|
||||
subject = _names_and(names) if names else "This choice"
|
||||
verb = "hold" if len(names) > 1 else "holds"
|
||||
why = "only game data" if game_data else "no file under these options"
|
||||
return f"{subject} {verb} {why}: nothing is left to install."
|
||||
@@ -236,7 +235,7 @@ def narrowing_words(files: list[dict], omitted: list[dict]) -> str:
|
||||
("systems", "systems", len(listed_systems(files)) > 1),
|
||||
("cores", "cores", len(choices["cores"]) > 1),
|
||||
("regions", "regions", bool(choices["regions"]))) if axis in axes and enough]
|
||||
return f"{', '.join(named[:-1])} and {named[-1]}" if len(named) > 1 else "".join(named)
|
||||
return _names_and(named)
|
||||
|
||||
|
||||
def chosen_flags(choice: object) -> list[tuple[str, str | None]]:
|
||||
|
||||
@@ -23,12 +23,12 @@ from installer.events import EVENTS
|
||||
from installer.filesystems import keeps_case
|
||||
from installer.host_fs import _clear_read_only, _is_link
|
||||
from installer.install_record import (
|
||||
_MONTHS,
|
||||
_backup_note,
|
||||
_below,
|
||||
_check_ours,
|
||||
_record_now,
|
||||
_update_record,
|
||||
day_words,
|
||||
load_record,
|
||||
record_argv,
|
||||
record_options,
|
||||
@@ -854,10 +854,7 @@ def backup_words(date: str) -> str:
|
||||
when = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
|
||||
except ValueError:
|
||||
return date or "unknown date"
|
||||
day = f"{when.day} {_MONTHS[when.month - 1]}"
|
||||
if when.year != datetime.datetime.now().year:
|
||||
day += f" {when.year}"
|
||||
return f"{day} {when.hour:02d}:{when.minute:02d}"
|
||||
return f"{day_words(when)} {when.hour:02d}:{when.minute:02d}"
|
||||
|
||||
|
||||
def list_backups(folder: Path) -> list[dict]:
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@ from installer.narrowing import _settle_slot
|
||||
from installer.paths import _entry_path, shown_path
|
||||
from installer.platforms import display_name, entry_systems
|
||||
from installer.remote import SITE_URL
|
||||
from installer.text import _plural, agree, format_size
|
||||
from installer.text import _names_and, _plural, agree, format_size
|
||||
|
||||
|
||||
def _bytes(files: list[dict]) -> int:
|
||||
@@ -176,7 +176,7 @@ def installed_words(bios: int, games: int, data: int = 0) -> str:
|
||||
(bios, "BIOS file"), (games, "game data file"), (data, "data file")) if count]
|
||||
if not parts:
|
||||
return _plural(0, "file")
|
||||
return f"{', '.join(parts[:-1])} and {parts[-1]}" if len(parts) > 1 else parts[0]
|
||||
return _names_and(parts)
|
||||
|
||||
|
||||
def parts_words(counts: Tally, data: int = 0, data_size: int | None = None,
|
||||
@@ -198,7 +198,7 @@ def parts_words(counts: Tally, data: int = 0, data_size: int | None = None,
|
||||
+ (f" ({format_size(data_size)})" if data_size is not None else ""))
|
||||
if len(parts) < 2 and not left_out:
|
||||
return ""
|
||||
text = f"{', '.join(parts[:-1])} and {parts[-1]}" if len(parts) > 1 else parts[0]
|
||||
text = _names_and(parts)
|
||||
return text + (f". {_plural(left_out, 'game data file')} left out" if left_out else "")
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ from installer.platforms import _tui_system_label, system_title
|
||||
from installer.regions import region_title
|
||||
from installer.removal import _served
|
||||
from installer.tally import tally
|
||||
from installer.text import _plural, agree
|
||||
from installer.text import _names_and, _plural, agree
|
||||
from installer.tui_commands import _core_base, _tui_system_flags, _tui_systems_chosen, tui_flags, tui_run_files
|
||||
from installer.tui_paint import _detail, _short_path
|
||||
|
||||
@@ -139,7 +139,7 @@ def _choice_in_place(state: TuiState) -> str:
|
||||
return ""
|
||||
titles = _system_titles(state)
|
||||
names = [_tui_system_label(row, titles) for row in chosen]
|
||||
subject = (", ".join(names[:-1]) + " and " + names[-1]) if len(names) > 1 else names[0]
|
||||
subject = _names_and(names)
|
||||
return f"{subject} {'are' if len(names) > 1 else 'is'} in place: nothing is left to install."
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user