Files
libretro/scripts/probes/entries.py
T
Abdessamad Derraz 3a76cf48ba refactor: share resolver, content and nightly
The probes resolve held files, read content.yml, list the buildbot and
fetch nightlies through one function each.

- region_check resolves BIOS files from the repo root (probes.entries
  held_file), so a run outside the root no longer sees every file missing.
- region_check reads content.yml as Content objects, and a malformed
  content folder raises Unavailable instead of FileNotFoundError.
- region_check and pack_probe fetch nightlies like the campaign: retried
  on network errors, streamed to disk, and replaced when the buildbot's
  ETag or Last-Modified moves. region_check keeps its cores under
  .cache/region/cores/<core>/ with a build.json record. pack_probe
  --refresh-cores now downloads only a nightly the buildbot replaced.
- The campaign loads profiles with load_emulator_profiles, so *.old.yml
  backups are skipped and hashes are normalized. Profile digests still
  come from the file on disk, so recorded checks keep their digest.
2026-11-20 20:03:26 +01:00

70 lines
2.4 KiB
Python

"""Profile entries as the probes read them: systems, destination, regions, category."""
from __future__ import annotations
import hashlib
from pathlib import Path
from model import measurements as mr
from probes.host import working_directory
def profile_digest(profile: dict) -> str:
"""What a check depends on in a profile: its entries, evidence left out,
so the campaign's own evidence never makes it run again."""
entries = [{k: v for k, v in entry.items() if k != "evidence"}
for entry in profile.get("files") or []]
body = {"files": entries, "cores": profile.get("cores"), "type": profile.get("type"),
"systems": profile.get("systems")}
return hashlib.sha1(mr.canonical(body)).hexdigest()
def held_file(entry: dict, db: dict, root: Path) -> Path | None:
"""The collection's copy of an entry in the checkout at root, by its
declared hashes or its name."""
from resolve.localfile import resolve_local_file
hint = entry.get("path") if isinstance(entry.get("path"), str) else ""
# The database names files relative to the checkout it describes.
with working_directory(root):
path, status = resolve_local_file(entry, db, dest_hint=hint or "")
if not path or status in ("not_found", "hash_mismatch"):
return None
local = Path(path)
local = local if local.is_absolute() else root / local
return local if local.is_file() else None
def entry_systems(entry: dict, profile: dict) -> list[str]:
if entry.get("systems"):
return list(entry["systems"])
if entry.get("system"):
return [entry["system"]]
return list(profile.get("systems") or [])
def entry_dest(entry: dict) -> str:
"""Where the core reads the entry, relative to its system directory."""
path = entry.get("path")
if isinstance(path, str) and path and not path.endswith("/"):
return path
return entry["name"]
def region_matches(entry: dict, region: str | None) -> bool:
regions = entry.get("region")
if not regions or not region:
return True
if isinstance(regions, str):
regions = [regions]
return region in regions or "world" in regions
def regions_of(entry: dict) -> list[str]:
regions = entry.get("region") or []
return [regions] if isinstance(regions, str) else list(regions)
def is_bios(entry: dict) -> bool:
return entry.get("category", "bios") == "bios" and entry.get("type") != "directory"