refactor: read hashes and the registry one way

Hash fields go through core.hashing.parse_hash_list, which also splits comma-joined list items: the truth model compared a comma-joined sha256 list as one value. _registry.yml goes through load_platform_registry (required= where an absent file must stop the run), database.json through load_database, file and member digests through file_digest and stream_hashes. download.py and check_release read SHA256SUMS.txt with one parser: a sha256sum -b line matched nothing in download.py and the pack went unchecked.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 18:28:40 +01:00
1 parent 7cd499531d
commit 348d5b51c3
32 files changed
+130 -217

No files matched your search

+2 -2
View File
@@ -7,6 +7,7 @@ import textwrap
from dataclasses import dataclass, fields
from pathlib import Path
from model.registry import load_platform_registry
from core.paths import REPO_ROOT
from model.safeparse import require_yaml
@@ -344,8 +345,7 @@ def load_guides(path: Path = GUIDES_FILE, registry: dict | None = None) -> dict:
"""
yaml = require_yaml()
if registry is None:
with open(PLATFORMS_DIR / "_registry.yml", encoding="utf-8") as handle:
registry = (yaml.safe_load(handle) or {}).get("platforms", {})
registry = load_platform_registry(PLATFORMS_DIR, required=True)
with open(path, encoding="utf-8") as handle:
data = yaml.safe_load(handle) or {}
if not isinstance(data, dict):
+2 -3
View File
@@ -21,7 +21,7 @@ from collections.abc import Iterable
from pathlib import Path
from core.artifacts import set_plain_mode
from core.hashing import compute_hashes
from core.hashing import compute_hashes, parse_hash_list
from core.paths import REPO_ROOT
@@ -436,6 +436,5 @@ def _matches(hashes: dict, expected_sha1: str, expected_md5: str) -> bool:
if expected_sha1 and hashes["sha1"].lower() != expected_sha1.lower():
return False
if expected_md5:
md5_list = [m.strip().lower() for m in expected_md5.split(",") if m.strip()]
return hashes["md5"].lower() in md5_list
return hashes["md5"].lower() in parse_hash_list(expected_md5)
return True
+14 -7
View File
@@ -6,11 +6,12 @@ import json
import os
from pathlib import Path
from core.paths import PLATFORMS_DIR
from core.cli import InputMissing
from model.sources import source_yaml
def load_data_dir_registry(platforms_dir: str = "platforms") -> dict:
def load_data_dir_registry(platforms_dir: str = PLATFORMS_DIR) -> dict:
"""Load the data directory registry from _data_dirs.yml."""
registry_path = os.path.join(platforms_dir, "_data_dirs.yml")
if not os.path.exists(registry_path):
@@ -20,16 +21,22 @@ def load_data_dir_registry(platforms_dir: str = "platforms") -> dict:
return data.get("data_directories", {})
def load_platform_registry(platforms_dir: str = "platforms") -> dict:
"""Return the `platforms:` mapping from _registry.yml, empty if absent."""
def load_platform_registry(platforms_dir: str | Path = PLATFORMS_DIR, required: bool = False) -> dict:
"""Return the `platforms:` mapping from _registry.yml.
An absent file is an empty registry, or with ``required`` an input the
command cannot run without.
"""
registry_path = os.path.join(platforms_dir, "_registry.yml")
if not os.path.exists(registry_path):
if required:
raise InputMissing(f"{registry_path} not found")
return {}
with open(registry_path) as f:
return (source_yaml(f) or {}).get("platforms", {})
with open(registry_path, encoding="utf-8") as f:
return (source_yaml(f) or {}).get("platforms") or {}
def list_registered_platforms(platforms_dir: str = "platforms") -> list[str]:
def list_registered_platforms(platforms_dir: str = PLATFORMS_DIR) -> list[str]:
"""List platforms registered in _registry.yml.
Only registered platforms generate packs and appear in CI.
@@ -55,7 +62,7 @@ def list_registered_platforms(platforms_dir: str = "platforms") -> list[str]:
return platforms
def list_release_pack_platforms(platforms_dir: str = "platforms") -> list[str]:
def list_release_pack_platforms(platforms_dir: str = PLATFORMS_DIR) -> list[str]:
"""Registered platforms a release publishes a ZIP pack for.
`release_pack: true` in _registry.yml is the whole list: the build of
+3 -5
View File
@@ -97,14 +97,12 @@ def ensure_console_sections() -> None:
them, so a page rendered on its own names systems as the site does."""
if _sections_installed[0]:
return
import json
from model.profiles import load_emulator_profiles
from model.collection import group_by_manufacturer
from model.database import load_database
from model.profiles import load_emulator_profiles
inputs = siteinputs.current()
with open(inputs.db, encoding="utf-8") as handle:
db = json.load(handle)
db = load_database(str(inputs.db))
profiles = load_emulator_profiles(str(inputs.emulators), skip_aliases=False)
set_console_sections(group_by_manufacturer(db), program_names(profiles))