refactor: look up a path's sha1 with sha1_at

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 05:59:51 +01:00
1 parent 82d3f595de
commit 8fdc00e07f
8 files changed
+43 -51

No files matched your search

+2 -6
View File
@@ -6,16 +6,13 @@ import urllib.parse
from collections.abc import Callable
from model.collection import group_by_manufacturer, manufacturer_slug
from model.database import sha1_at
from model.systemnames import system_name
from sitegen.config import SITE_URL
from sitegen.lookup import sorted_hash_values, site_path
from sitegen.render import console_href
def sha1_index_by_path(db: dict | None) -> dict[str, str]:
return {str(e.get("path", "")): sha1 for sha1, e in ((db or {}).get("files") or {}).items()}
def system_index_items(db: dict, coverages: dict, profiles: dict) -> list[dict]:
"""Each system id the platforms and profiles write, reachable by that id.
@@ -28,14 +25,13 @@ def system_index_items(db: dict, coverages: dict, profiles: dict) -> list[dict]:
"""
from sitegen.render import card_page, system_ids, system_section
sha1_by_path = sha1_index_by_path(db)
files = db.get("files") or {}
by_md5 = (db.get("indexes") or {}).get("by_md5") or {}
held: dict[str, set[str]] = {}
for coverage in coverages.values():
for detail in coverage.get("details") or []:
path = str(detail.get("path") or "")
sha1 = sha1_by_path.get(path) if detail.get("status") != "missing" else None
sha1 = sha1_at(db, path) if detail.get("status") != "missing" else None
if sha1:
held.setdefault(str(detail.get("system", "")), set()).add(sha1)
for profile in profiles.values():
+7 -7
View File
@@ -16,10 +16,11 @@ from pathlib import Path
from core.artifacts import json_text as _json_text
from core.hashing import file_digest
from model import retired as model_retired
from model.database import sha1_at
from model.dumpcatalog import load_provenance_snapshots
from packs.crossref import FileConsumers
from acquire.provenance import build_report
from sitegen.apiitems import sha1_index_by_path, core_index_items, system_index_items
from sitegen.apiitems import core_index_items, system_index_items
from sitegen.config import DATA_LICENSE, REPO_URL, build_commit, data_timestamp
from core.paths import REPO_ROOT
from sitegen.install import release_pack_platforms
@@ -91,7 +92,7 @@ def _csv_document(fieldnames: list[str], rows: list[dict]) -> str:
def _verify_outcomes(
coverage: dict, sha1_by_path: dict[str, str]
coverage: dict, db: dict
) -> Callable[[str, str], dict]:
"""For each declared entry, in declaration order: what verify found.
@@ -114,7 +115,7 @@ def _verify_outcomes(
"status": detail.get("status", ""),
"category": detail.get("category", ""),
"collection_path": path,
"resolved_sha1": sha1_by_path.get(path, "") if path else "",
"resolved_sha1": sha1_at(db, path) or "",
}
return outcome
@@ -180,10 +181,9 @@ def _platform_export_rows(
"""Normalized platform summaries and one row per declared file."""
items: list[dict] = []
file_rows: list[dict] = []
sha1_by_path = sha1_index_by_path(db)
for key, coverage in sorted(coverages.items()):
config = coverage["config"]
outcome = _verify_outcomes(coverage, sha1_by_path)
outcome = _verify_outcomes(coverage, db or {})
contract, registry = _split_contract(config)
items.append({
"id": key,
@@ -302,7 +302,7 @@ def _gap_export_rows(
A `layer` column keeps the two apart instead of publishing only one.
"""
rows: list[dict] = []
sha1_by_path = sha1_index_by_path(db)
db = db or {}
for key, coverage in sorted(coverages.items()):
for detail in coverage.get("details", []):
if detail.get("status") == "ok" and not detail.get("discrepancy"):
@@ -311,7 +311,7 @@ def _gap_export_rows(
rows.append({
"category": detail.get("category", "bios"),
"collection_path": path,
"resolved_sha1": sha1_by_path.get(path, "") if path else "",
"resolved_sha1": sha1_at(db, path) or "",
"layer": "platform",
"platform_id": key,
"platform": coverage["platform"],
+7 -8
View File
@@ -10,6 +10,7 @@ import urllib.parse
from model import siteinputs
from model.collection import profiles_in, profiles_on_disk
from model.database import load_database, sha1_at
from model.profiles import upstream_profile_index
from model.systemnames import system_name
from sitegen import entries as siteentries, markup
@@ -38,16 +39,14 @@ from sitegen.render import (
)
def _collection_sha1_by_path() -> dict[str, str]:
"""The sha1 of each file the collection holds, by its path."""
return _sha1_by_path_in(str(siteinputs.current().db))
def _collection_sha1(path: str) -> str:
"""The sha1 of the file the collection holds at a path."""
return sha1_at(_collection_db(str(siteinputs.current().db)), path) or ""
@functools.cache
def _sha1_by_path_in(db_path: str) -> dict[str, str]:
with open(db_path, encoding="utf-8") as handle:
files = json.load(handle).get("files", {})
return {str(entry.get("path", "")): sha1 for sha1, entry in files.items()}
def _collection_db(db_path: str) -> dict:
return load_database(db_path)
def _system_heading_link(sys_id: str, prefix: str = "") -> str:
@@ -96,7 +95,7 @@ def _served_line(f: dict, declared_sha1: str = "") -> str:
if not path:
# A slot the pack fills from a release asset or leaves to the user.
return ""
sha1 = _collection_sha1_by_path().get(path, "")
sha1 = _collection_sha1(path)
label = "Served by" if f.get("status") == "ok" else "Held, not the declared hash"
parts = path.split("/")
if not sha1 or len(parts) < 3 or parts[0] != "bios":