mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 02:27:52 -06:00
fix: name every export change on the site page
The run's summary and the exports page each built the sentence from their own table, and the page dropped sizes and hashes removed and md5 lists. Both now read one table of change kinds, and each report stores a count per kind. The committed reports gain those counts from their own records.
This commit is contained in:
1 parent
74c59ad3b9
commit
04e1d2d3ab
20 files changed
+227
-63
No files matched your search
+26
-27
@@ -21,6 +21,7 @@ from .doubled import doubled_destinations
|
||||
from .landed import LandedChanges, landed_changes
|
||||
from .originals import collect_originals, unpinned, wanted_sources
|
||||
from model.database import load_database
|
||||
from model.exportchanges import change_phrases
|
||||
from model.platforms import load_platform_config, native_layer
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.registry import load_data_dir_registry, load_platform_registry
|
||||
@@ -249,9 +250,10 @@ def build_export(
|
||||
landed, refused, lost = _entry_outcomes(exporter, systems)
|
||||
|
||||
own_summary = exporter.outcome(systems, produced)
|
||||
counts = _change_counts(report, changes, landed, refused, lost)
|
||||
summary = own_summary
|
||||
if summary is None:
|
||||
summary = _landed_summary(report, changes, landed, lost)
|
||||
summary = _landed_summary(counts)
|
||||
withheld = exporter.withheld()
|
||||
unwritten = _unwritten(refused, withheld, report)
|
||||
# Reported, never removed: the platform's file keeps every entry.
|
||||
@@ -267,12 +269,7 @@ def build_export(
|
||||
"originals": wanted_sources(exporter, systems, scraped),
|
||||
"files": sorted(produced),
|
||||
"summary": summary,
|
||||
"counts": None if own_summary is not None else {
|
||||
"kept": report.files_kept,
|
||||
"added": landed,
|
||||
"not_added": refused,
|
||||
"not_kept": lost,
|
||||
},
|
||||
"counts": None if own_summary is not None else counts,
|
||||
"changes": changes.records,
|
||||
"hashes_updated": applied,
|
||||
"hashes_filled": filled,
|
||||
@@ -349,27 +346,29 @@ def _entry_outcomes(exporter: BaseExporter, systems: dict) -> tuple[int, int, in
|
||||
return landed, refused, lost
|
||||
|
||||
|
||||
def _landed_summary(report: Report, changes: LandedChanges, landed: int, lost: int) -> str:
|
||||
# What the written file carries, in the terms the exports page uses.
|
||||
def _change_counts(
|
||||
report: Report, changes: LandedChanges, landed: int, refused: int, lost: int
|
||||
) -> dict[str, int]:
|
||||
"""How many entries each kind of change touches, as the report stores them."""
|
||||
return {
|
||||
"kept": report.files_kept,
|
||||
"added": landed,
|
||||
"not_added": refused,
|
||||
"not_kept": lost,
|
||||
"hash_updated": len(changes.applied),
|
||||
"required_aligned": changes.requirements,
|
||||
"hash_filled": len(changes.filled),
|
||||
"size_updated": len(changes.resized),
|
||||
"size_removed": len(changes.unsized),
|
||||
"hash_cleared": len(changes.cleared),
|
||||
"md5_lists": changes.lists,
|
||||
}
|
||||
|
||||
|
||||
def _landed_summary(counts: dict[str, int]) -> str:
|
||||
# What the written file carries, the same changes the exports page names.
|
||||
# What it does not carry is counted on a line of its own below.
|
||||
parts = [f"{report.files_kept} kept"]
|
||||
landed_counts = (
|
||||
(landed, "file", "", "added"),
|
||||
(len(changes.applied), "hash", "", "updated to the emulator source"),
|
||||
(changes.requirements, "required flag", "", "aligned with the code"),
|
||||
(len(changes.filled), "hash", "", "added to an existing entry"),
|
||||
(len(changes.resized), "size", "", "updated to the emulator source"),
|
||||
(len(changes.unsized), "size", "", "removed"),
|
||||
(len(changes.cleared), "hash", "", "removed"),
|
||||
(lost, "entry", "entries", "removed, the format cannot state them"),
|
||||
(changes.lists, "md5 list", "", "written, any listed value passes"),
|
||||
)
|
||||
parts += [
|
||||
f"{count_text(number, noun, plural)} {verb}"
|
||||
for number, noun, plural, verb in landed_counts
|
||||
if number
|
||||
]
|
||||
return ", ".join(parts)
|
||||
return ", ".join([f"{counts['kept']} kept", *change_phrases(counts)])
|
||||
|
||||
|
||||
def _unwritten(refused: int, withheld: list[str], report: Report) -> list[str]:
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""The kinds of change an export writes into a platform's file, and how each is said."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import NamedTuple
|
||||
|
||||
from core.text import count_text
|
||||
|
||||
|
||||
class ChangeKind(NamedTuple):
|
||||
"""One kind of change, its count key in the report and its two wordings."""
|
||||
|
||||
key: str
|
||||
noun: str
|
||||
plural: str
|
||||
terse: str
|
||||
plain: str
|
||||
|
||||
|
||||
# In the order both sentences name them. `terse` is the run's summary,
|
||||
# `plain` the exports page.
|
||||
CHANGE_KINDS = (
|
||||
ChangeKind("added", "file", "", "added", "added"),
|
||||
ChangeKind("hash_updated", "hash", "", "updated to the emulator source", "updated"),
|
||||
ChangeKind("required_aligned", "required flag", "",
|
||||
"aligned with the code", "aligned with the code"),
|
||||
ChangeKind("hash_filled", "hash", "", "added to an existing entry", "added"),
|
||||
ChangeKind("size_updated", "size", "", "updated to the emulator source", "updated"),
|
||||
ChangeKind("size_removed", "size", "", "removed", "removed"),
|
||||
ChangeKind("hash_cleared", "hash", "", "removed", "removed"),
|
||||
ChangeKind("not_kept", "entry", "entries", "removed, the format cannot state them",
|
||||
"not written, the format cannot state them"),
|
||||
ChangeKind("md5_lists", "md5 list", "",
|
||||
"written, any listed value passes", "written, any listed value passes"),
|
||||
)
|
||||
|
||||
|
||||
def change_phrases(counts: dict, plain: bool = False) -> list[str]:
|
||||
"""Each change the counts hold, as "2 hashes removed", none for a zero."""
|
||||
return [
|
||||
f"{count_text(counts[kind.key], kind.noun, kind.plural)} "
|
||||
f"{kind.plain if plain else kind.terse}"
|
||||
for kind in CHANGE_KINDS
|
||||
if counts[kind.key]
|
||||
]
|
||||
@@ -12,6 +12,7 @@ import json
|
||||
from pathlib import Path
|
||||
|
||||
from core.text import count_text
|
||||
from model.exportchanges import change_phrases
|
||||
from sitegen import markup
|
||||
|
||||
EXPORTS_DIR = "exports"
|
||||
@@ -95,24 +96,15 @@ def _lookup_only(block: list[str]) -> list[str]:
|
||||
def change_text(report: dict) -> str:
|
||||
"""What the updated file changes, from the report's numbers.
|
||||
|
||||
The command line prints its own terse summary. The page states each
|
||||
kind of change once, in plain terms, and leaves out what did not
|
||||
happen. RetroPie's unit is a package, so its own sentence is kept.
|
||||
The page names the changes the run's summary names, in plain terms,
|
||||
and leaves out what did not happen. RetroPie's unit is a package, so
|
||||
its own sentence is kept.
|
||||
"""
|
||||
counts = report.get("counts")
|
||||
if not counts:
|
||||
return report["summary"]
|
||||
parts = [f"{count_text(counts['kept'], 'entry', 'entries')} kept"]
|
||||
extra = [
|
||||
(counts["added"], "file", "files", "added"),
|
||||
(len(report.get("hashes_updated") or []), "hash", "hashes", "updated"),
|
||||
(report.get("required_aligned") or 0, "required flag", "required flags",
|
||||
"aligned with the code"),
|
||||
(len(report.get("hashes_filled") or []), "hash", "hashes", "added"),
|
||||
(len(report.get("sizes_updated") or []), "size", "sizes", "updated"),
|
||||
]
|
||||
parts += [f"{count_text(n, one, many)} {verb}" for n, one, many, verb in extra if n]
|
||||
return ", ".join(parts)
|
||||
kept = f"{count_text(counts['kept'], 'entry', 'entries')} kept"
|
||||
return ", ".join([kept, *change_phrases(counts, plain=True)])
|
||||
|
||||
|
||||
# Beyond this many entries a reason's list folds away.
|
||||
@@ -301,12 +293,6 @@ def generate_exports_page(reports: list[dict], names: dict[str, str]) -> str:
|
||||
"reasons above.",
|
||||
"",
|
||||
])
|
||||
if counts.get("not_kept"):
|
||||
lines.extend([
|
||||
f"{count_text(counts['not_kept'], 'entry', 'entries')} of the original "
|
||||
"cannot be written in this format and should be checked by hand.",
|
||||
"",
|
||||
])
|
||||
lines.extend(candidate_lines(report.get("removal_candidates") or []))
|
||||
lines.extend(doubled_lines(report.get("doubled") or []))
|
||||
if report.get("invalid"):
|
||||
|
||||
Reference in new issue
Block a user