refactor: read declared hashes with one helper

core.hashing.declared_hash_lists gives an entry's declared values per
field in the order written, and declared_hashes builds its sets on it.
The gap page, the doubled-destination report and the file lookup used
their own copies of that reader. The wanted page keeps its filters on
top of it. sitegen.lookup.hash_pairs replaces sorted_hash_values for
the lookup, the data exports and the structured data. The one-field
aliases parse_md5_list and reconcile.hash_values are gone, and
model.profiles reads HASH_FIELDS instead of a fourth tuple.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 10:29:37 +01:00
1 parent ea68e85c06
commit 02969dda06
30 files changed
+176 -195

No files matched your search

+8 -11
View File
@@ -198,10 +198,16 @@ def parse_hash_list(raw: str | list | int | None) -> list[str]:
HASH_FIELDS = ("sha1", "md5", "sha256", "crc32")
def declared_hash_lists(entry: dict, fields: Iterable[str] = HASH_FIELDS) -> dict[str, list[str]]:
"""Hash field -> the values an entry declares, in the order written, for
each field it declares, the fields in the order given."""
found = {f: parse_hash_list(entry.get(f)) for f in fields}
return {f: values for f, values in found.items() if values}
def declared_hashes(entry: dict, fields: Iterable[str] = HASH_FIELDS) -> dict[str, set[str]]:
"""Hash field -> the values an entry declares, for each field it declares."""
found = {f: set(parse_hash_list(entry.get(f))) for f in fields}
return {f: values for f, values in found.items() if values}
return {f: set(values) for f, values in declared_hash_lists(entry, fields).items()}
def lists_hashes(entry: dict) -> bool:
@@ -209,15 +215,6 @@ def lists_hashes(entry: dict) -> bool:
return bool(declared_hashes(entry))
def parse_md5_list(raw: str | list | None) -> list[str]:
"""Normalize an md5 field into a lowercase list.
Platform YAMLs carry Recalbox multi-hash as one comma-separated string,
emulator profiles carry a YAML list. Both reach here.
"""
return parse_hash_list(raw)
def parse_sha256sums(text: str) -> dict[str, str]:
"""`sha256sum` output by file name: digest, a space, then the mode
character (space for text, `*` for binary) before the name."""