fix: gaps and wanted read one sendable rule

This commit is contained in:
Abdessamad Derraz committed 2026-11-23 23:07:44 +01:00
1 parent 7ad22248b5
commit 2ccd7bb88f
6 files changed
+120 -64

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
"""Whether a contributor can send a file the collection lacks."""
from __future__ import annotations
import re
from resolve.gamedata import is_game_data
from resolve.validation import installed_everywhere
# A name the code builds from the content (<serial>.txt, *.ini) is a
# pattern, not a file anyone can upload.
PATTERN = re.compile(r"[<>*?]")
# A file not collected yet stays wanted, however hard it is to find ("no
# public dump located", "retail data the collection does not hold"). It
# leaves the list only when its reason (the profile's `unsourceable:`)
# says no copy can be shared, read by the rules below.
NOT_SHAREABLE = re.compile("|".join([
# Any file of the name serves: there is no one file to collect.
r"\bno canonical\b",
# The user writes, picks, records or places it (WHDLoad's key aside,
# emucorev's config.txt: "plugin list the user writes").
r"\bthe user\b|\buser[- ](?:supplied|authored|created|settings|overlay|placeholder)\b"
r"|\bother users\b",
# The emulator or the guest writes it: a save, a state, a generated key.
r"\bwritten by (?:the (?:emulator|guest|firmware editor)|bam)\b|\bgenerated by the emulator\b"
r"|\bwith the debug key\b|\bmachine state\b|\bcreat\w* (?:this directory )?empty\b",
# It belongs to one person, one account or one copy (puae's WHDLoad.key).
r"\bper[- ]user\b|\btied to the (?:account|tag)\b|\bnever distributed generically\b"
r"|\bissued for one copy\b",
# Nothing was ever released under the name.
r"\bno (?:distributed form|released artefact|hardware dump equivalent)\b"
r"|\bno file of this name is distributed\b",
]), re.I)
def shareable(reason: str) -> bool:
"""False when a reason says no copy of the file can be shared."""
return not NOT_SHAREABLE.search(reason)
def can_send(name: str, reason: str = "") -> bool:
"""Whether a declared name and the reason it is not collected leave a
file someone can upload: not a pattern, not a file no copy of which can
be shared."""
return not PATTERN.search(name) and shareable(reason)
def sendable(entry: dict, reason: str = "") -> bool:
"""Whether a profile entry the collection lacks is a file to ask for:
can_send() holds, it is not game data (no contributor's to send), and
the emulator does not install it on every setup."""
return (can_send(str(entry.get("name", "")), reason)
and not is_game_data(entry) and not installed_everywhere(entry))
+32 -8
View File
@@ -15,6 +15,7 @@ from model.profiles import is_emulator
from packs.crossref import gap_source_counts
from resolve.cores import resolve_platform_cores
from resolve.nativemode import check_label
from resolve.sendable import sendable
from sitegen import markup, wanted as sitewanted
from sitegen.cards import PROVENANCE_LABELS, fetch_url
from sitegen.config import date_line
@@ -96,13 +97,29 @@ def _hash_cell(hashes: dict[str, list[str]]) -> str:
)
def catalog_listings(report: dict | None, labels: dict[str, str]) -> dict[tuple[str, str], list[tuple[str, str]]]:
"""(profile, file name casefolded) -> (catalog or romset, the name it
lists the file under), from a provenance report built with the
profiles' needs: the "Listed in" column of the gaps page."""
out: dict[tuple[str, str], list[tuple[str, str]]] = {}
for source, data in sorted((report or {}).items()):
label = labels.get(source, source)
for entry in data.get("missing", []):
where = [(label, str(entry.get("name", "")))]
where += [(str(hit["source"]), str(hit["archive"])) for hit in entry.get("romsets", [])]
for need in entry.get("needed_by", []):
held = out.setdefault((need["emulator"], str(need["name"]).casefold()), [])
held += [w for w in where if w not in held]
return out
def _catalogued_needs(report: dict | None) -> dict[tuple[str, str], list[str]]:
"""(profile, file name casefolded) -> where a dump catalog or an
imported romset lists that file, from a provenance report built with
the profiles' needs."""
return {
need: [f"{escape_tags(where)} `{escape_tags(name)}`" for where, name in listed]
for need, listed in sitewanted.catalog_listings(report, PROVENANCE_LABELS).items()
for need, listed in catalog_listings(report, PROVENANCE_LABELS).items()
}
@@ -783,6 +800,9 @@ def _not_collected_section(report_all: dict, profiles: dict, catalogued: dict |
"emu_key": emu_name,
"reason": u["reason"],
"source_ref": u.get("source_ref", ""),
# The wanted page's own rule, on the entries behind the row.
"wanted": any(sendable(entry, str(u["reason"])) for entry in sitewanted.gap_entries(
profiles.get(emu_name) or {}, str(u["name"]), "", True)),
}
for emu_name, data in sorted(report_all.items())
for u in data.get("unsourceable", [])
@@ -797,8 +817,11 @@ def _not_collected_section(report_all: dict, profiles: dict, catalogued: dict |
"## Not collected yet",
"",
f"{len(all_unsourceable)} files the collection does not hold. A file "
"with the same name is never served in their place. Each is still "
"wanted, and the last column names a catalog or romset that lists it.",
"with the same name is never served in their place. The [wanted "
f"page](wanted.md) asks for the {sum(u['wanted'] for u in all_unsourceable)} "
"marked wanted. No one can send the others: a name the code builds, a "
"file no copy of which can be shared, game data, or a file the emulator "
"installs itself. \"Listed in\" names a catalog or romset that lists a file.",
"",
]
rows = []
@@ -807,15 +830,16 @@ def _not_collected_section(report_all: dict, profiles: dict, catalogued: dict |
rows.append(
f"| `{u['name']}` | {u['emulator']} | {_reason_cell(u['reason'])} "
f"| {source_ref_markdown(profiles[u['emu_key']], u['source_ref'])} "
f"| {', '.join(where) or '-'} |"
f"| {', '.join(where) or '-'} | {'yes' if u['wanted'] else 'no'} |"
)
lines.extend(_moved_table(
NOT_COLLECTED_STEM, "Files not collected yet",
f"{count_text(len(rows), 'file')} the collection does not hold, each with the "
"emulator that loads it, why it is not collected and the catalog or romset "
"that lists it. Part of [What the packs do not hold](gaps.md#not-collected-yet).",
["| File | Emulator | Reason | Source ref | Listed in |",
"|------|----------|--------|-----------|-----------|"],
"emulator that loads it, why it is not collected, the catalog or romset "
"that lists it and whether the [wanted page](wanted.md) asks for it. Part of "
"[What the packs do not hold](gaps.md#not-collected-yet).",
["| File | Emulator | Reason | Source ref | Listed in | Wanted |",
"|------|----------|--------|-----------|-----------|--------|"],
rows, "file", moved))
return lines
+6 -50
View File
@@ -16,7 +16,6 @@ the review of the pull request asks for that same folder.
from __future__ import annotations
import re
import urllib.parse
from collections.abc import Callable, Iterable
from pathlib import Path
@@ -28,7 +27,8 @@ from model.profiles import unique_emulator_profiles
from packs.crossref import first_hash
from core.hashing import cut_md5_owner, declared_hash_lists, parse_hash_list
from resolve.review import LARGE_FILE_ISSUE_URL, Placement, placement
from resolve.validation import deliverable, filter_files_by_mode, installed_everywhere
from resolve.sendable import can_send, sendable
from resolve.validation import deliverable, filter_files_by_mode
from sitegen.config import UPLOAD_ROOT
ALGORITHMS = ("sha1", "sha256", "md5", "crc32")
@@ -229,73 +229,29 @@ def wanted_declarations(profiles: dict, coverages: dict, gap_report: dict) -> li
if gap.get("source") == "missing" and not gap.get("bundled")]
rows += [(row, True) for row in data.get("unsourceable") or []]
for row, unsourceable in rows:
reason = str(row.get("reason") or "") if unsourceable else ""
for entry in gap_entries(profile, str(row.get("name", "")),
str(row.get("identity") or ""), unsourceable):
if entry.get("category") == GAME_DATA or installed_everywhere(entry):
if not sendable(entry, reason):
continue
system = entry.get("system") or (systems[0] if len(systems) == 1 else "")
found.append({
"name": str(entry["name"]), "system": str(system),
"required": bool(row.get("required", False)),
"reader": ("emulator", key, str(data.get("emulator", key))), "entry": entry,
"reason": str(row.get("reason") or "") if unsourceable else "",
"reason": reason,
"category": BIOS,
"directory": _directory(entry),
})
return found
def catalog_listings(report: dict | None, labels: dict[str, str]) -> dict[tuple[str, str], list[tuple[str, str]]]:
"""(profile, file name casefolded) -> (catalog or romset, the name it
lists the file under), from a provenance report built with the
profiles' needs: the "Listed in" column of the gaps page."""
out: dict[tuple[str, str], list[tuple[str, str]]] = {}
for source, data in sorted((report or {}).items()):
label = labels.get(source, source)
for entry in data.get("missing", []):
where = [(label, str(entry.get("name", "")))]
where += [(str(hit["source"]), str(hit["archive"])) for hit in entry.get("romsets", [])]
for need in entry.get("needed_by", []):
held = out.setdefault((need["emulator"], str(need["name"]).casefold()), [])
held += [w for w in where if w not in held]
return out
BIOS = "bios"
GAME_DATA = "game_data"
# verify's category for a platform entry no core the platform runs reads.
UNREAD = "unread"
# Firmware first, then what a platform lists and no core reads.
RANK = {BIOS: 0, UNREAD: 1}
# A name the code builds from the content (<serial>.txt, *.ini) is a
# pattern, not a file anyone can upload.
PATTERN = re.compile(r"[<>*?]")
# A file not collected yet stays wanted, however hard it is to find ("no
# public dump located", "retail data the collection does not hold"). It
# leaves the list only when its reason (the profile's `unsourceable:`)
# says no copy can be shared, read by the rules below.
NOT_SHAREABLE = re.compile("|".join([
# Any file of the name serves: there is no one file to collect.
r"\bno canonical\b",
# The user writes, picks, records or places it (WHDLoad's key aside,
# emucorev's config.txt: "plugin list the user writes").
r"\bthe user\b|\buser[- ](?:supplied|authored|created|settings|overlay|placeholder)\b"
r"|\bother users\b",
# The emulator or the guest writes it: a save, a state, a generated key.
r"\bwritten by (?:the (?:emulator|guest|firmware editor)|bam)\b|\bgenerated by the emulator\b"
r"|\bwith the debug key\b|\bmachine state\b|\bcreat\w* (?:this directory )?empty\b",
# It belongs to one person, one account or one copy (puae's WHDLoad.key).
r"\bper[- ]user\b|\btied to the (?:account|tag)\b|\bnever distributed generically\b"
r"|\bissued for one copy\b",
# Nothing was ever released under the name.
r"\bno (?:distributed form|released artefact|hardware dump equivalent)\b"
r"|\bno file of this name is distributed\b",
]), re.I)
def shareable(reason: str) -> bool:
"""False when a reason says no copy of the file can be shared."""
return not NOT_SHAREABLE.search(reason)
def _settle_cut(records: list[dict]) -> None:
@@ -444,7 +400,7 @@ def _collect_records(declarations: Iterable[dict], held: Held,
share are left out."""
records: dict[tuple, dict] = {}
for declaration in declarations:
if PATTERN.search(declaration["name"]) or not shareable(declaration["reason"]):
if not can_send(declaration["name"], declaration["reason"]):
continue
entry = declaration["entry"]
sizes = _sizes(entry)