refactor: split generate_site into sitegen modules

This commit is contained in:
Abdessamad Derraz committed 2026-11-18 19:31:28 +01:00
1 parent 231002a7c0
commit 4e50286d8c
78 files changed
+15084 -14289

No files matched your search

+3 -13546
View File
File diff suppressed because it is too large. Load diff
+120
View File
@@ -0,0 +1,120 @@
"""The static API items of systems and cores."""
from __future__ import annotations
import urllib.request
from collections.abc import Callable
from model.collection import _group_by_manufacturer, _slug
from model.systemnames import system_name
from sitegen.config import SITE_URL
from sitegen.lookup import _hash_values, _site_path
from sitegen.render import console_href
def _sha1_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.
api/v1/systems/ is keyed by manufacturer and its consoles by display
name: a frontend keying by system id (sony-playstation) had no way in.
The url is the section system_section gives, the one every page links.
An id with no section of its own (tyrian, scummvm) that holds files
takes the card of its first file, else the page of the emulator naming
it: 28 such ids sent their hashes to no page.
"""
from sitegen.render import card_page, system_ids, system_section
sha1_by_path = _sha1_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
if sha1:
held.setdefault(str(detail.get("system", "")), set()).add(sha1)
for profile in profiles.values():
if profile.get("type") == "alias" or profile.get("role") == "test":
continue
own = [str(s) for s in profile.get("systems") or []]
for entry in profile.get("files") or []:
if not isinstance(entry, dict):
continue
ids = ([str(entry["system"])] if entry.get("system")
else [str(s) for s in entry.get("systems") or []] or
(own if len(own) == 1 else []))
found = {v for v in _hash_values(entry.get("sha1")) if v in files}
for md5 in _hash_values(entry.get("md5")):
match = by_md5.get(md5)
found.update([match] if isinstance(match, str) else match or [])
for sys_id in ids:
held.setdefault(sys_id, set()).update(found)
manufacturers = {_slug(mfr): mfr for mfr in _group_by_manufacturer(db)}
base = urllib.parse.urlsplit(SITE_URL).path
items = []
for sys_id in sorted(system_ids(profiles, [c["config"] for c in coverages.values()])):
section = system_section(sys_id)
try:
name = system_name(sys_id)
except KeyError:
name = sys_id
sha1s = sorted(held.get(sys_id, set()) & files.keys())
manufacturer = manufacturers.get(section[0], "") if section else ""
url = _site_path(console_href(*section)) if section else None
if url is None and sha1s:
manufacturer, url = _first_file_place(sys_id, sha1s, files, profiles, card_page)
# The id's JSON document: api/v1/systems/ is keyed by the manufacturer
# page, and sony-playstation.json answered 404.
holder = section[0] if section else _slug(manufacturer) if manufacturer else ""
api = f"{base}api/v1/systems/{holder}.json" if holder else None
items.append({"id": sys_id, "name": name, "manufacturer": manufacturer,
"url": url, "api": api, "sha1": sha1s})
return items
def _first_file_place(
sys_id: str, sha1s: list[str], files: dict, profiles: dict,
card_page: Callable[[str, str], str],
) -> tuple[str, str | None]:
"""(manufacturer, url) of the card of an id's first collection file,
else of the page of the first emulator naming the id."""
for sha1 in sha1s:
parts = str(files[sha1].get("path", "")).split("/")
if len(parts) >= 3 and parts[0] == "bios":
page = card_page("/".join(parts), sha1)
return parts[1], _site_path(f"systems/{page}.md#sha1-{sha1[:12]}")
for key in sorted(profiles):
profile = profiles[key]
if profile.get("type") != "alias" and profile.get("role") != "test" and sys_id in (profile.get("systems") or []):
return "", _site_path(f"emulators/{key}.md")
return "", None
def core_index_items(profiles: dict) -> list[dict]:
"""Every name a core goes by, with the profile it designates.
A frontend knows mednafen_psx_libretro, and api/v1/emulators/ had only
beetle_psx.json: the reverse index resolve_platform_cores reads, aliases
included, said once. A name two profiles claim (pcsx2) lists both, the
one a platform list designates first.
"""
from model.profiles import preferred_profile, upstream_profile_index
published = {name for name, p in profiles.items() if p.get("type") != "alias" and p.get("role") != "test"}
index = upstream_profile_index(profiles)
for name, profile in profiles.items():
target = str(profile.get("alias_of") or "")
if profile.get("type") == "alias" and target in published:
index.setdefault(name, set()).add(target)
items: list[dict] = []
for name in sorted(index):
claimants = sorted(index[name] & published)
preferred = preferred_profile({name: set(claimants)}, name)
items.extend({"name": name, "profile": profile, "preferred": profile == preferred}
for profile in sorted(claimants, key=lambda p: (p != preferred, p)))
return items
+685
View File
@@ -0,0 +1,685 @@
"""One run of the generator: every page, data file and asset, in order."""
from __future__ import annotations
import argparse
import dataclasses
import json
import re
import shutil
from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path
import archive_build
import release_record
from model import siteinputs
from model.collection import _group_by_manufacturer, _slug
from model.composition import compute_composition
from model.database import load_database
from model.dumpcatalog import load_provenance_snapshots
from model.guides import HANDHELD_GUIDE
from model.profiles import load_emulator_profiles
from model.registry import list_registered_platforms
from model.safeparse import yaml_load
from model.systemnames import program_names, set_console_sections, system_name
from packs.crossref import FileConsumers
from provenance_report import build_report, profile_needs
from resolve.cores import resolve_platform_cores
from resolve.review import load_platform_hashes, load_profile_hashes
from sitegen import (
agents as siteagents,
bootstrap as sitebootstrap,
diagrams,
handheld as sitehandheld,
measurements as sitemeasurements,
starlight as sitestarlight,
steps as sitesteps,
wanted as sitewanted,
)
from sitegen.cards import _wanted_link, system_install_choices, tables_out_of_search
from sitegen.config import GENERATED_DIRS, PUBLIC_DIRS, REPO_URL, _REPO_ROOT, _timestamp, yaml
from sitegen.crossref import generate_cross_reference
from sitegen.dataexports import (
_source_commit,
build_emulator_gap_report,
generate_data_exports,
generate_stats,
system_export_item,
write_single_item,
)
from sitegen.datapage import generate_data_page
from sitegen.decorate import SEARCH_DEMOTED, _front_matter, decorate_markdown_pages
from sitegen.descriptions import PAGE_DATA, PART_PAGES
from sitegen.emulatorcards import (
ARCHIVE_RECIPES_PAGE,
ROMSET_FAQ_PAGE,
_DATA_MEMBERS,
emulator_setups,
with_archive_counts,
with_romset_table,
)
from sitegen.emulatorpage import (
_DATA_READERS,
_DATA_REVISIONS,
_EMULATOR_SETUPS,
_MEASUREMENT_ITEMS,
_availability_check,
emulator_pages,
emulator_parts,
plan_emulator_pages,
)
from sitegen.emulatorsindex import generate_emulators_index
from sitegen.exports import generate_exports_page, load_export_reports
from sitegen.gaps import SourceListing, generate_gap_analysis
from sitegen.getpages import generate_get_index, generate_get_page
from sitegen.guidepage import DEMO_ASSETS, generate_handheld_guide
from sitegen.home import generate_explore_index, generate_home
from sitegen.lookup import (
data_directory_members,
data_directory_revisions,
data_tree_pages,
generate_files_page,
page_data_directories,
)
from sitegen.nav import _overview_anchors, generate_nav
from sitegen.parts import PUBLISHED_PARTS_FILE, _published_parts, record_parts
from sitegen.places import _system_pages_from_data
from sitegen.platformfiles import _EXPORTED
from sitegen.platformindex import SETUP_TABLE_PAGE, generate_platform_index, with_setup_table
from sitegen.platformpage import _own_list_only, generate_platform_page
from sitegen.provenance import generate_provenance_page, load_derivable
from sitegen.publish import write_release_advertised
from sitegen.readme import platform_coverages
from sitegen.reference import (
generate_contributing,
generate_not_found,
generate_wiki_data_model,
reference_next,
)
from sitegen.render import (
WIKI_SRC_DIR,
_icon_name,
_pct,
_system_page_map,
prime_system_icons,
reset_console_pages,
set_system_page_map,
split_system_stems,
)
from sitegen.structured import (
dataset_structured_data,
emulator_structured_data,
platform_structured_data,
record_emulator_page,
system_structured_data,
)
from sitegen.systempages import arcade_board_sections, system_pages
from sitegen.systemsindex import generate_systems_index
from sitegen.versions import compute_stats
from sitegen.whichpack import _build_emulator_file_index, _build_file_consumers, generate_which_pack
from sitegen.write import _record, _sweep_generated, _sweep_top_pages, write_if_changed
def _write_public_assets(docs: Path, public: Path) -> None:
"""The folders every generator writes into, and the files the site
serves as they are: bootstraps, launchers, logos, diagrams, demo."""
for d in GENERATED_DIRS:
(public / d if d in PUBLIC_DIRS else docs / d).mkdir(parents=True, exist_ok=True)
# No robots.txt: a crawler reads it only at the host root (RFC 9309), and
# this project site lives under /retrobios/. Every page's head points at
# the sitemap instead (Starlight's head links it).
(public / "robots.txt").unlink(missing_ok=True)
# The one-line commands' bootstraps, at the site's root.
sitebootstrap.write_bootstraps(public, _REPO_ROOT)
# The handheld launchers, built from the same commit (sitehandheld).
sitehandheld.write_launchers(public, _REPO_ROOT)
images_dest = public / "assets" / "images"
images_dest.mkdir(parents=True, exist_ok=True)
# Logos, system icons and sharing cards are served from the site itself
# (docs_assets/*/sources.json records where each came from).
# brand: the mark, favicons and touch icon (scripts/make_site_icons.py).
folders = [("logos", "logos"), ("system-icons", "system-icons"), ("og", "og"),
("brand", "brand")]
for folder, dest in folders:
source = Path("docs_assets") / folder
if source.is_dir():
shutil.copytree(source, public / "assets" / dest, dirs_exist_ok=True)
# The diagrams and the drawn install steps, one SVG per layout and theme.
diagrams.write_diagram_files(public / diagrams.DIAGRAM_DIR,
{**diagrams.figure_files(), **sitesteps.steps_files()})
demo_dest = public / "assets" / "demo"
demo_dest.mkdir(parents=True, exist_ok=True)
for name in DEMO_ASSETS:
shutil.copy2(Path("docs_assets") / "demo" / name, demo_dest / name)
assets_src = Path(".github") / "assets"
for name, dest_name in [("logo.png", "logo.png"), ("favicon.png", "favicon.png")]:
src = assets_src / name
if src.exists():
shutil.copy2(src, images_dest / dest_name)
def _load_registry(platforms_dir: str) -> dict:
"""The platforms of _registry.yml, by name."""
registry_path = Path(platforms_dir) / "_registry.yml"
registry = {}
if registry_path.exists():
with open(registry_path) as f:
registry = (yaml_load(f) or {}).get("platforms", {})
return registry
@dataclass
class _SiteRun:
"""What one run of the generator reads and where it writes."""
args: argparse.Namespace
db: dict
docs: Path
public: Path
registry: dict
platform_names: list[str]
data_registry: dict
suppl_names: set[str]
coverages: dict
profiles: dict
consumers: FileConsumers
gap_report: dict = dataclasses.field(default_factory=dict)
file_held: Callable[[dict], bool] = bool
manufacturers: dict = dataclasses.field(default_factory=dict)
def _load_site_run(args: argparse.Namespace, db: dict, docs: Path, public: Path) -> _SiteRun:
"""The registry, the coverage of every platform and the profiles."""
from model.registry import load_data_dir_registry
from packs.crossref import _build_supplemental_index
registry = _load_registry(args.platforms_dir)
platform_names = list_registered_platforms(
args.platforms_dir
)
data_registry = load_data_dir_registry(args.platforms_dir)
suppl_names = _build_supplemental_index()
print("Computing platform coverage...")
coverages = platform_coverages(
sorted(platform_names), args.platforms_dir, db, data_registry,
emulators_dir=args.emulators_dir, db_path=args.db,
report=lambda _name, cov: print(
f" {cov['platform']}: {cov['present']}/{cov['total']} ({_pct(cov['present'], cov['total'])})"
),
)
print("Loading emulator profiles...")
profiles = load_emulator_profiles(args.emulators_dir, skip_aliases=False)
unique_count = sum(1 for p in profiles.values() if p.get("type") != "alias")
print(
f" {len(profiles)} profiles ({unique_count} unique, {len(profiles) - unique_count} aliases)"
)
consumers = _build_file_consumers(db, coverages, profiles)
return _SiteRun(args, db, docs, public, registry, platform_names, data_registry,
suppl_names, coverages, profiles, consumers)
def _write_home_pages(run: _SiteRun) -> dict:
"""The home and explore pages, stats.json and the agents' files.
Returns the stats."""
docs, public, db = run.docs, run.public, run.db
coverages, profiles = run.coverages, run.profiles
print("Generating home page...")
write_if_changed(
str(docs / "index.md"), generate_home(
db, coverages, profiles, run.registry, run.args.platforms_dir
)
)
write_if_changed(str(docs / "explore.md"), generate_explore_index(db, coverages, profiles))
stats = compute_stats(db, coverages, profiles)
stats["composition"] = compute_composition(db)
write_if_changed(str(public / "stats.json"), generate_stats(stats))
# llms.txt and the ARD manifest an agent reads first, from the registry.
siteagents.write(public, sorted(((name, cov["platform"]) for name, cov in coverages.items()),
key=lambda row: row[1].casefold()), write_if_changed)
return stats
def _write_system_pages(run: _SiteRun) -> None:
"""The system pages, each manufacturer's, and their API items."""
from sitegen.render import link_coverage, system_ids
docs, public, db = run.docs, run.public, run.db
manufacturers = run.manufacturers
print("Generating system pages...")
prime_system_icons({
_icon_name(mfr, console)
for mfr, consoles in manufacturers.items()
for console in consoles
})
# The arcade boards are recorded before any page links one, the
# system pages first among them.
reset_console_pages()
sections, console_installs = arcade_board_sections(
manufacturers, system_install_choices(run.coverages))
linked, total = link_coverage(
system_ids(run.profiles, [cov["config"] for cov in run.coverages.values()]))
print(f" {linked} of {total} system ids linked")
write_if_changed(
str(docs / "systems" / "index.md"), generate_systems_index(sections)
)
(docs / "files").mkdir(parents=True, exist_ok=True)
write_if_changed(str(docs / "files" / "index.md"), generate_files_page())
for mfr, consoles in sections.items():
slug = mfr.lower().replace(" ", "-")
pages = system_pages(mfr, consoles, run.consumers, console_installs.get(slug))
for stem, (page, held) in pages.items():
PAGE_DATA[f"systems/{stem}.md"] = system_structured_data(stem, held)
if stem != slug:
PART_PAGES.add(f"systems/{stem}.md")
write_if_changed(str(docs / "systems" / f"{stem}.md"), page)
write_single_item(
public / "api" / "v1" / "systems" / f"{slug}.json", "systems",
# The published data keeps the collection's folders.
system_export_item(slug, mfr, manufacturers[mfr]),
str(db.get("generated_at") or _timestamp()), _source_commit(),
)
clash = split_system_stems() & {_slug(m) for m in manufacturers}
if clash:
raise RuntimeError(f"a console page takes a manufacturer's address: {sorted(clash)}")
def _write_measurements(run: _SiteRun) -> sitemeasurements.Built:
"""The measurements' data files and explorer page."""
print("Compiling the measurements...")
measured = sitemeasurements.build(
run.public, emulators_dir=Path(run.args.emulators_dir), repo=REPO_URL,
system_names={sys_id: system_name(sys_id) for sys_id in sorted(set(_system_page_map))},
)
for path in measured.paths:
_record(path)
_MEASUREMENT_ITEMS.clear()
_MEASUREMENT_ITEMS.update(sitemeasurements.by_emulator(measured.index))
print(f" {measured.index['records']} records, {measured.index['count']} tests")
write_if_changed(str(run.docs / sitemeasurements.EXPLORER_PAGE),
sitemeasurements.generate_explorer_page(measured.index) + reference_next())
return measured
def _write_data_exports(run: _SiteRun, stats: dict) -> None:
"""The static API, the bulk exports and the data page."""
print("Generating static API and bulk data exports...")
exports = generate_data_exports(
run.public, run.db, run.coverages, run.profiles, stats, run.gap_report, run.consumers
)
write_release_advertised(Path(run.args.site_dir) / "src" / "generated")
write_if_changed(str(run.docs / "data.md"),
generate_data_page(exports, run.public / sitemeasurements.SQLITE_PATH)
+ reference_next())
PAGE_DATA["data.md"] = dataset_structured_data(exports, run.db)
def _write_platform_pages(run: _SiteRun) -> dict[str, str]:
"""The platform pages and the pages their long lists went to. Returns
the published parts, each part's page with the anchor it came from."""
docs, coverages = run.docs, run.coverages
emulator_files = _build_emulator_file_index(run.profiles)
print("Generating platform pages...")
write_if_changed(
str(docs / "platforms" / "index.md"),
generate_platform_index(coverages, run.registry),
)
if HANDHELD_GUIDE:
write_if_changed(str(docs / HANDHELD_GUIDE.path), generate_handheld_guide(HANDHELD_GUIDE))
published_parts = _published_parts()
for name, cov in coverages.items():
# The emulators this platform runs, not every one of the system.
runs = resolve_platform_cores(cov["config"], run.profiles)
moved: dict[str, str] = {}
write_if_changed(
str(docs / "platforms" / f"{name}.md"),
generate_platform_page(name, cov, run.registry, {
emu: data for emu, data in emulator_files.items() if emu in runs
}, moved),
)
for stem, page in moved.items():
if stem in coverages:
raise RuntimeError(f"a system page takes the platform {stem}'s address")
PART_PAGES.add(f"platforms/{stem}.md")
anchor = re.search(rf"\]\({re.escape(name)}\.md#([^)\s]+)\)", page)
if anchor:
published_parts[f"platforms/{stem}.md"] = f"platforms/{name}.md#{anchor[1]}"
# One console of one setup's list, a reference: "playstation
# bios" found five setups' lists before the console's page.
# Weighed down, they still won on their title, which the page
# weight does not reach, and their file list is already kept out
# of the index: the title alone, found again on the setup's page
# and the console's, is all the search held of them.
SEARCH_DEMOTED.add(f"platforms/{stem}.md")
front = _front_matter(page)
if front:
page = page[page.find("\n---\n", 4) + 5:].lstrip("\n")
front.update(level="reference", search="exclude",
parent={"label": cov["platform"], "link": f"{name}.md"})
page = "---\n" + yaml.safe_dump(front, sort_keys=False, allow_unicode=True) \
+ "---\n\n" + page
write_if_changed(str(docs / "platforms" / f"{stem}.md"), page)
PAGE_DATA[f"platforms/{name}.md"] = platform_structured_data(name, cov)
return published_parts
def _record_data_trees(profiles: dict) -> None:
"""The data directories: their members, revisions and readers, and the
pages their member lists go to."""
_DATA_MEMBERS.update(data_directory_members())
_DATA_REVISIONS.update(data_directory_revisions())
for key in sorted(profiles):
if profiles[key].get("type") == "alias" or profiles[key].get("role") == "test":
continue
display = str(profiles[key].get("emulator", key))
for tree in page_data_directories(key, profiles):
readers = _DATA_READERS.setdefault(str(tree.get("ref", "")), [])
if (key, display) not in readers:
readers.append((key, display))
for ref, members in _DATA_MEMBERS.items():
for stem, _names in data_tree_pages(ref, members):
PART_PAGES.add(f"emulators/{stem}.md")
def _write_emulator_pages(run: _SiteRun) -> None:
"""The emulator index, and each emulator's page and API item."""
profiles = run.profiles
print("Generating emulator pages...")
_EMULATOR_SETUPS.update(emulator_setups(run.coverages, profiles))
_record_data_trees(profiles)
write_if_changed(
str(run.docs / "emulators" / "index.md"), generate_emulators_index(profiles)
)
public_profiles = {
name: profile
for name, profile in profiles.items()
if profile.get("type") != "alias" and profile.get("role") != "test"
}
(run.public / "api" / "v1" / "emulators").mkdir(parents=True, exist_ok=True)
for name, profile in public_profiles.items():
_write_emulator_page(run, name, profile)
def _write_emulator_page(run: _SiteRun, name: str, profile: dict) -> None:
"""One emulator's API item, page and the pages its cards went to."""
docs, db = run.docs, run.db
# The profile itself, one small document per core: reusing one
# meant downloading emulators.json (5.9 MB) and filtering it.
# The envelope and item of emulators.json, one item long: the
# profile validates against the published schema, which an "id"
# beside its fields broke on all 530, and schema_version is there.
# The commit too, as every other envelope: 625 files lacked it.
write_single_item(
run.public / "api" / "v1" / "emulators" / f"{name}.json", "emulators",
{"id": name, "profile": profile},
str(db.get("generated_at") or _timestamp()), _source_commit(),
)
pages = emulator_pages(
name, profile, db, run.consumers, run.suppl_names, run.data_registry,
data_dirs=page_data_directories(name, run.profiles),
)
record_emulator_page(name, profile)
# A frozen copy answers after the emulator: a frozen_snapshot, and a
# profile pinned to the revision one platform builds (pin_frozen).
# Reicast and Flycast 2021 LE answered "dc bios missing" before Flycast.
if (profile.get("type") in ("launcher", "alias")
or profile.get("core_classification") in ("launcher", "alias", "frozen_snapshot")
or profile.get("pin_frozen")):
SEARCH_DEMOTED.add(f"emulators/{name}.md")
files = profile.get("files") or []
for stem, entries in emulator_parts(name, files, profile, run.file_held):
PAGE_DATA[f"emulators/{stem}.md"] = emulator_structured_data(
{**profile, "files": [files[i] for i in entries]})
PART_PAGES.add(f"emulators/{stem}.md")
for stem, page in pages.items():
write_if_changed(str(docs / "emulators" / f"{stem}.md"), page)
def _write_cross_reference(run: _SiteRun) -> None:
"""The cross-reference page and its parts."""
docs = run.docs
print("Generating cross-reference page...")
xref_pages: dict[str, str] = {}
write_if_changed(
str(docs / "cross-reference.md"),
tables_out_of_search(generate_cross_reference(run.coverages, run.profiles, xref_pages))
+ reference_next(),
)
for stem, page in xref_pages.items():
write_if_changed(str(docs / f"{stem}.md"), tables_out_of_search(page))
for pname, cov in run.coverages.items():
if _own_list_only(cov["config"]):
# The empty table it had is gone: its address leads to the
# platform's page, which says its own list decides alone.
sitestarlight.MOVED_PAGES.setdefault(
f"cross-reference-{pname}.md", f"platforms/{pname}.md")
def _write_gap_pages(run: _SiteRun, provenance_report: dict) -> None:
"""The gap analysis page, its parts and the wanted page."""
docs, public, db = run.docs, run.public, run.db
profiles, coverages = run.profiles, run.coverages
# Where an upload goes, by validate_pr's own rule: the gaps page and the
# wanted page send a file to the folder the review asks for.
placer = sitewanted.Placer(
db, load_platform_hashes(run.args.platforms_dir, db),
load_profile_hashes(run.args.emulators_dir, db),
)
print("Generating gap analysis page...")
gap_pages: dict[str, str] = {}
write_if_changed(
str(docs / "gaps.md"),
tables_out_of_search(generate_gap_analysis(
profiles, coverages, db, run.suppl_names, run.registry, run.gap_report,
SourceListing(gap_pages, placer), catalogued=provenance_report,
)) + reference_next(),
)
for stem, page in gap_pages.items():
write_if_changed(str(docs / f"{stem}.md"), tables_out_of_search(page))
print("Generating the wanted page...")
wanted = sitewanted.build_wanted(
profiles, coverages, run.gap_report, db, placer, system_name,
sitewanted.load_ledger(archive_build.ARCHIVES_FILE),
_wanted_link(profiles),
)
(public / "data").mkdir(parents=True, exist_ok=True)
write_if_changed(str(public / sitewanted.DATA_FILE),
json.dumps(wanted, ensure_ascii=False, separators=(",", ":")) + "\n")
write_if_changed(str(docs / "wanted.md"), sitewanted.page(
len(wanted["entries"]), sum(1 for entry in wanted["entries"] if "h" in entry)))
def _write_reference_pages(run: _SiteRun, export_reports: list[dict]) -> None:
"""The cross-reference, gaps, wanted, updated files and provenance pages."""
docs = run.docs
_write_cross_reference(run)
provenance_report = build_report(
run.db, load_provenance_snapshots(), needs=profile_needs(run.profiles, run.db))
_write_gap_pages(run, provenance_report)
print("Generating updated platform files page...")
write_if_changed(
str(docs / "exports.md"),
generate_exports_page(
export_reports,
{name: cov["platform"] for name, cov in run.coverages.items()},
) + reference_next(),
)
print("Generating dump provenance page...")
provenance_pages: dict[str, str] = {}
write_if_changed(
str(docs / "provenance.md"),
tables_out_of_search(
generate_provenance_page(run.db, provenance_report, load_derivable(), provenance_pages)
) + reference_next(),
)
for stem, page in provenance_pages.items():
write_if_changed(str(docs / f"{stem}.md"), tables_out_of_search(page))
def _write_wiki_pages(run: _SiteRun, measured: sitemeasurements.Built) -> None:
"""Wiki pages: copy manually maintained sources + generate dynamic ones."""
docs, profiles = run.docs, run.profiles
print("Generating wiki pages...")
wiki_dest = docs / "wiki"
wiki_dest.mkdir(parents=True, exist_ok=True)
wiki_src = Path(WIKI_SRC_DIR)
# The romset table is the profiles' versions, never typed: the source
# page is rewritten before it is copied, as the README is.
faq = _REPO_ROOT / ROMSET_FAQ_PAGE
if faq.is_file():
write_if_changed(str(faq), with_romset_table(faq.read_text(encoding="utf-8"), profiles))
recipes_page = _REPO_ROOT / ARCHIVE_RECIPES_PAGE
if recipes_page.is_file():
write_if_changed(str(recipes_page), with_archive_counts(
recipes_page.read_text(encoding="utf-8"), archive_build.rebuild_counts()))
if wiki_src.is_dir():
for src_file in wiki_src.glob("*.md"):
shutil.copy2(src_file, wiki_dest / src_file.name)
_record(wiki_dest / src_file.name)
method_page = docs / sitemeasurements.METHOD_PAGE
if method_page.is_file():
write_if_changed(str(method_page), sitemeasurements.with_hosts(
method_page.read_text(encoding="utf-8"), measured.index))
table_page = docs / SETUP_TABLE_PAGE
if table_page.is_file():
write_if_changed(str(table_page), with_setup_table(
table_page.read_text(encoding="utf-8"), run.coverages))
# data-model.md is generated (contains live DB stats)
write_if_changed(
str(wiki_dest / "data-model.md"), generate_wiki_data_model(run.db, profiles)
)
def _write_guide_pages(run: _SiteRun) -> None:
"""The which-pack page, the download pages and the contributing page."""
docs = run.docs
print("Generating which-pack page...")
write_if_changed(str(docs / "which-pack.md"), generate_which_pack())
# One permanent download address per registered platform: the README's
# table links each of them.
print("Generating download pages...")
get_dir = docs / release_record.GET_DIR
get_dir.mkdir(parents=True, exist_ok=True)
for name in run.platform_names:
write_if_changed(str(get_dir / f"{name}.md"), generate_get_page(name))
write_if_changed(str(get_dir / f"{sitehandheld.GROUP_PAGE}.md"),
sitehandheld.group_page(_REPO_ROOT))
write_if_changed(str(get_dir / "index.md"), generate_get_index())
print("Generating contributing page...")
write_if_changed(str(docs / "contributing.md"), generate_contributing())
def _write_navigation(run: _SiteRun, published_parts: dict[str, str]) -> None:
"""Sweep what nothing produced, decorate every page, then write the
navigation, the redirects and the picker's data."""
docs, public, coverages = run.docs, run.public, run.coverages
# Swept before the decoration, which rewrites every page it finds: a
# page no generator produced any more (a console moved back onto its
# manufacturer's page) was decorated, recorded, and kept for ever.
write_if_changed(str(docs / "404.md"), generate_not_found())
stale = _sweep_generated(docs, [d for d in GENERATED_DIRS if d not in PUBLIC_DIRS])
stale += _sweep_generated(public, list(PUBLIC_DIRS))
stale += _sweep_top_pages(docs)
print("Adding page metadata and structured data...")
lastmod = decorate_markdown_pages(docs)
nav = generate_nav(coverages, run.manufacturers, run.profiles, run.registry,
Path(WIKI_SRC_DIR))
print("Writing the navigation and the picker's data...")
site = Path(run.args.site_dir)
present = {
path.relative_to(docs).with_suffix(".md").as_posix()
for path in docs.rglob("*.md*") if path.suffix in (".md", ".mdx")
} - {"404.md"}
published_parts = record_parts(docs, present, published_parts)
write_if_changed(str(PUBLISHED_PARTS_FILE), json.dumps(published_parts, indent=1) + "\n")
generated = site / "src" / "generated"
generated.mkdir(parents=True, exist_ok=True)
write_if_changed(str(generated / "sidebar.json"),
json.dumps(sitestarlight.sidebar(nav, present, _overview_anchors(nav, docs)),
indent=1) + "\n")
write_if_changed(str(generated / "redirects.json"),
json.dumps(sitestarlight.redirects(run.profiles, present, published_parts), indent=1,
sort_keys=True) + "\n")
write_if_changed(str(generated / "lastmod.json"),
json.dumps(dict(sorted(lastmod.items())), indent=1) + "\n")
system_ids = set(_system_page_map) | {
sys_id for cov in coverages.values() for sys_id in cov["config"].get("systems", {})
}
titles = {sys_id: system_name(sys_id) for sys_id in sorted(system_ids)}
sitestarlight.picker_data(_REPO_ROOT / "install", public / "data" / "picker", titles)
total_pages = len(present)
print(f"\nGenerated {total_pages} pages in {run.args.docs_dir}/")
if stale:
print(f"Removed {stale} page(s) nothing produced this run")
def _generate(args: argparse.Namespace) -> None:
# Every page reads these, never the repository's own files.
siteinputs.use(siteinputs.SiteInputs(
db=Path(args.db).resolve(),
emulators=Path(args.emulators_dir).resolve(),
platforms=Path(args.platforms_dir).resolve(),
))
db = load_database(args.db)
docs = Path(args.docs_dir)
# Files the site serves as they are (data, downloads, images), in the
# project's public folder.
public = Path(args.site_dir) / "public"
_write_public_assets(docs, public)
run = _load_site_run(args, db, docs, public)
profiles, coverages = run.profiles, run.coverages
stats = _write_home_pages(run)
# Computed once: the gap analysis page and the published gaps export must
# report the same files.
run.gap_report = build_emulator_gap_report(profiles, coverages, db, run.suppl_names)
# The test each emulator page builds for itself: the parts a page is
# cut into weigh the status its rows show.
run.file_held = _availability_check(db, run.suppl_names)
# The plan names systems: the sections must be this run's data first.
run.manufacturers = _group_by_manufacturer(db)
set_console_sections(run.manufacturers, program_names(profiles))
plan_emulator_pages(profiles, run.file_held)
# Build system_id -> manufacturer page map (needed by all generators)
print("Building system cross-reference map...")
set_system_page_map(
_system_pages_from_data(run.manufacturers, coverages, db, profiles)
)
print(f" {len(_system_page_map)} system IDs mapped to pages")
_write_system_pages(run)
measured = _write_measurements(run)
_write_data_exports(run, stats)
export_reports = load_export_reports()
_EXPORTED.update(report["platform"] for report in export_reports)
published_parts = _write_platform_pages(run)
_write_emulator_pages(run)
_write_reference_pages(run, export_reports)
_write_wiki_pages(run, measured)
_write_guide_pages(run)
_write_navigation(run, published_parts)
+803
View File
@@ -0,0 +1,803 @@
"""A system file's card: its places, facts, hashes and romset lines."""
from __future__ import annotations
import functools
import html
import json
import re
import sys
import urllib.request
import zipfile
from collections.abc import Callable
from model.collection import _profiles_on_disk
from packs.crossref import FileConsumers
from sitegen import markup, wanted as sitewanted
from sitegen.config import REPO_URL, _REPO_ROOT
from sitegen.fields import search_excluded
from sitegen.install import _platform_display
from sitegen.render import _code, _count, _system_page_map, emulator_card_page
def emulator_file_anchors(files: list[dict]) -> list[str]:
"""The id of each file card on an emulator page, in profile order.
An entry that declares a hash is addressed by it: its anchor depends on
its own content, never on the entries beside it, and a second version
added under the same path moves nothing. An entry without one keeps
its plain anchor when its path is declared once, and otherwise takes
its size, else, when even the size is shared, its description. The
page and its JSON-LD both read this, so a structured part links to its
card. The plain anchor of a hashed card stays reachable through
emulator_file_aliases.
"""
bases = [
"file-" + (
re.sub(
r"[^a-z0-9]+", "-",
str(f.get("path") or f.get("standalone_path") or f.get("name", "")).lower(),
).strip("-") or "entry"
)
for f in files
]
repeated = {b for b in bases if bases.count(b) > 1}
def _version_key(f: dict) -> str:
digest = _first_hash_value(f)
if digest:
return digest[:8]
return f"{f['size']}b" if f.get("size") else ""
keys = [
(b, _version_key(f)) if b in repeated or _first_hash_value(f) else (b, "")
for f, b in zip(files, bases)
]
used: dict[str, int] = {}
anchors = []
for f, (base, key) in zip(files, keys):
anchor = f"{base}-{key}" if key else base
if keys.count((base, key)) > 1 and f.get("description"):
described = re.sub(r"[^a-z0-9]+", "-", str(f["description"]).lower()).strip("-")
anchor = f"{anchor}-{described[:40].strip('-')}"
used[anchor] = used.get(anchor, 0) + 1
if used[anchor] > 1:
anchor = f"{anchor}-{used[anchor]}"
anchors.append(anchor)
return anchors
_PROVENANCE_LABELS = {"redump": "Redump", "no-intro": "No-Intro", "tosec": "TOSEC"}
# TOSEC dump flags that say the dump is not a clean copy of the chip
# (TOSEC Naming Convention, "Dump info flags"); [a] alternate and [!]
# verified good are not among them.
_TOSEC_BAD_FLAGS = {
"b": "bad dump", "o": "overdump", "h": "hacked", "cr": "cracked",
"f": "fixed", "t": "trained", "p": "pirate",
}
_TOSEC_FLAG_RE = re.compile(r"\[(b|o|h|cr|f|t|p)\d*(?:\s[^\]]*)?\]")
def _dump_flags(source: str, data: dict) -> list[str]:
"""What a catalog's name says is wrong with the dump, as words."""
if source != "tosec":
return []
name = str(data.get("name") or data.get("description") or "")
seen: list[str] = []
for flag in _TOSEC_FLAG_RE.findall(name):
word = _TOSEC_BAD_FLAGS[flag]
if word not in seen:
seen.append(word)
return seen
def _provenance_lines(provenance: dict, prefix: str) -> list[str]:
"""One visible line per catalog: its badge and the entry's own name.
The name was only a title attribute, unreadable on a touch screen and
absent from the search for 793 of 803 provenances, and a TOSEC entry
flagged [b] or [o] wore the same green badge as a clean dump.
"""
lines: list[str] = []
for source, data in sorted(provenance.items()):
label = _PROVENANCE_LABELS.get(source, source)
flags = _dump_flags(source, data)
kind = "rb-badge-warning" if flags else "rb-badge-success"
badge = f'<span class="rb-badge {kind}">[{label}]({prefix}provenance.md#{source})</span>'
name = str(data.get("name") or data.get("description") or "")
line = f"- Catalogued: {badge} {_code(name)}" if name else f"- Catalogued: {badge}"
if flags:
line += f" ({', '.join(flags)}, as {label} records it)"
lines.append(line)
return lines
_ROMSET_SOURCES = {"mame": "MAME", "fbneo": "FBNeo"}
_RELEASE_ASSET_NAMES: dict[str, str] | None = None
def _download_name(path: str) -> str:
"""The name a browser saves a collection file under: the last segment
of its download URL. Neither host sends a Content-Disposition, and the
download attribute is ignored on another origin."""
return urllib.parse.unquote(_fetch_url(path).rsplit("/", 1)[-1])
def _fetch_url(path: str) -> str:
"""Where a collection file downloads from: its raw URL, or the
large-files release asset when .gitignore keeps it out of git."""
global _RELEASE_ASSET_NAMES
if _RELEASE_ASSET_NAMES is None:
from model.largefiles import (
LARGE_FILES_RELEASE,
asset_names,
load_registered_paths,
published_asset_name,
)
_RELEASE_ASSET_NAMES = {
registered: f"{REPO_URL}/releases/download/{LARGE_FILES_RELEASE}/"
+ urllib.parse.quote(published_asset_name(name))
for registered, name in asset_names(load_registered_paths()).items()
}
return _RELEASE_ASSET_NAMES.get(path) or (
"https://raw.githubusercontent.com/Abdess/retrobios/main/"
+ urllib.parse.quote(path)
)
# A setup, the link to its page, and where it puts the file.
Place = tuple[str, str, list[str]]
def _platform_places(sha1: str, consumers: FileConsumers) -> list[Place]:
"""Each platform declaring the file, linked to its system section, with
the destination it gives the file."""
systems_of = getattr(consumers, "platform_systems", {}).get(sha1, {})
destinations_of = getattr(consumers, "platform_destinations", {}).get(sha1, {})
places: list[Place] = []
for platform in consumers.platforms.get(sha1, ()):
section = sorted(systems_of.get(platform, ()))
fragment = f"#{section[0].replace(' ', '-')}" if section else ""
places.append((_platform_display(platform), f"../platforms/{platform}.md{fragment}",
sorted(destinations_of.get(platform, ()))))
return sorted(places, key=lambda place: place[0].casefold())
def _platform_links(sha1: str, consumers: FileConsumers) -> list[str]:
"""Each platform declaring the file, as Markdown: its name, linked to
its system section, then the destination it gives the file."""
return [
f"[{name}]({href})" + (": " + ", ".join(_code(d) for d in dests) if dests else "")
for name, href, dests in _platform_places(sha1, consumers)
]
_card_anchors: dict[str, tuple[list, list[str]]] = {}
def _emulator_card_anchor(emulator: str, files: list, index: int) -> str:
"""The id of a profile entry's card on its emulator page."""
cached = _card_anchors.get(emulator)
if cached is None or cached[0] is not files:
cached = _card_anchors[emulator] = (files, emulator_file_anchors(files))
return cached[1][index] if 0 <= index < len(cached[1]) else ""
def _wanted_link(profiles: dict) -> Callable[[str, str, dict], str]:
"""The page a row of the wanted list links: an emulator entry's card,
where its notes, hashes and source line are, else the setup's page."""
def link(kind: str, key: str, entry: dict) -> str:
files = (profiles.get(key) or {}).get("files") or [] if kind == "emulator" else []
index = next((i for i, f in enumerate(files) if f is entry), -1)
anchor = _emulator_card_anchor(key, files, index) if index >= 0 else ""
if anchor:
return f"emulators/{emulator_card_page(key, anchor)}/#{anchor}"
return sitewanted.reader_page(kind, key, entry)
return link
def _emulator_links(sha1: str, consumers: FileConsumers) -> list[str]:
"""Each emulator reading the file, linked to the entry that reads it.
The platform links landed on their system section, and the emulator
links on the page top: duckstation's scph5501.bin entry, with the line
that accepts it, sat 260 lines down a page of 105 entries.
"""
entries = getattr(consumers, "emulator_entries", {}).get(sha1, {})
files_of = getattr(consumers, "emulator_files", {})
links = []
# By the name the emulator's page carries: 19,499 card links read
# melonds_ds where its page says melonDS DS.
named = sorted(((_emulator_display(e), e) for e in consumers.emulators.get(sha1, ())),
key=lambda pair: (pair[0].casefold(), pair[1]))
for display, emulator in named:
index = entries.get(emulator)
anchor = (_emulator_card_anchor(emulator, files_of[emulator], index)
if index is not None and emulator in files_of else "")
page = emulator_card_page(emulator, anchor) if anchor else emulator
fragment = f"#{anchor}" if anchor else ""
# The card's facts are raw HTML: "Game & Watch" is escaped, and a
# bracket would end the link the facts are parsed from.
text = html.escape(display, quote=False).replace("[", "&#91;").replace("]", "&#93;")
links.append(f"[{text}](../emulators/{page}.md{fragment})")
return links
def _installed_places(sha1: str, consumers: FileConsumers, declared: set[str]) -> list[Place]:
"""Each pack installing the file that its platform's list does not name,
with the place the pack gives it."""
places = [
(_platform_display(platform), f"../platforms/{platform}.md", sorted(d for d in dests if d))
for platform, dests in getattr(consumers, "installed", {}).get(sha1, {}).items()
if platform not in declared
]
return sorted(places, key=lambda place: place[0].casefold())
def _places_lines(places: list[Place]) -> list[str]:
"""Setups grouped by where they put the file, one line per place:
"`scph5501.bin`: Batocera, EmuDeck". Each setup repeating the name
took five lines where one says it. A setup that names no place (EmuDeck
matches by MD5) is listed on a line of its own, last."""
def plain(text: str) -> str:
return html.escape(text, quote=False).replace("`", "&#96;")
by_place: dict[tuple[str, ...], list[str]] = {}
for name, href, dests in places:
by_place.setdefault(tuple(dests), []).append(f"[{name}]({href})")
ordered = sorted(by_place.items(), key=lambda item: (not item[0], -len(item[1]), item[0]))
return [
(" and ".join(f"<code>{plain(d)}</code>" for d in dests) + ": " if dests else "")
+ ", ".join(links)
for dests, links in ordered
]
def _places_markdown(places: list[Place]) -> list[str]:
"""_places_lines in Markdown, for a card written as a list: the places
as code spans, which the glossary and the line breaks treat as code."""
by_place: dict[tuple[str, ...], list[str]] = {}
for name, href, dests in places:
by_place.setdefault(tuple(dests), []).append(f"[{name}]({href})")
ordered = sorted(by_place.items(), key=lambda item: (not item[0], -len(item[1]), item[0]))
return [(" and ".join(_code(d) for d in dests) + ": " if dests else "") + ", ".join(links)
for dests, links in ordered]
def _inline_card_html(text: str) -> str:
"""A card value written in Markdown (code spans, links), as the HTML a
fact list holds. HTML already in the value is kept."""
out: list[str] = []
for part in re.split(r"(`[^`]*`)", text):
if len(part) > 1 and part.startswith("`") and part.endswith("`"):
out.append(f"<code>{html.escape(part[1:-1], quote=False)}</code>")
else:
out.append(re.sub(r"\[([^\]]+)\]\(([^)\s]+)\)", r'<a href="\2">\1</a>', part))
return "".join(out)
# A link icon, the way a heading anchor is drawn: the word "permalink" was
# read as part of every card title, by the search and by screen readers.
# Drawn once per page and used by each card: inline, its 400 bytes were
# 100 KB on the Sony page.
PERMALINK_SYMBOL = (
'<svg aria-hidden="true" style="display:none"><symbol id="rb-link-icon" '
'viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" '
'stroke-linecap="round" stroke-linejoin="round">'
'<path d="M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7"/>'
'<path d="M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7"/></symbol></svg>'
)
_PERMALINK_ICON = ('<svg aria-hidden="true" width="16" height="16">'
'<use href="#rb-link-icon"/></svg>')
def _icon_symbol() -> list[str]:
"""The icon's drawing, for a page of cards. None in the yardstick."""
return [PERMALINK_SYMBOL, ""] if markup.starlight() else []
RomsetMembers = tuple[tuple[str, str], ...]
# A release a recipe agrees with: its place among the imported releases of
# its source, and its name ("0.220", "1.0.0.03").
Release = tuple[int, str]
def _release_name(source: str, label: str, versions: dict) -> str:
""""MAME mame0220" as "0.220", an FBNeo DAT title as its version."""
match = re.fullmatch(r"MAME mame(\d)(\d+)", label) if source == "mame" else None
return f"{match[1]}.{match[2]}" if match else str(versions.get(label) or label)
@functools.lru_cache(maxsize=1)
def _romset_snapshots() -> list[tuple[str, dict]]:
return [(str(snapshot.get("source", path.stem)), snapshot)
for path in sorted((_REPO_ROOT / "recipes").glob("*.json"))
for snapshot in [json.loads(path.read_text(encoding="utf-8"))]]
@functools.lru_cache(maxsize=1)
def _romset_releases() -> dict[str, list[tuple[RomsetMembers, str, list[Release]]]]:
"""Archive name -> (members, source, the releases agreeing on them), from
the MAME and FBNeo recipe snapshots under recipes/.
A snapshot stores a recipe once for every version that agrees on it,
so a match reads "this set's contents in those versions".
"""
releases: dict[str, list[tuple[RomsetMembers, str, list[Release]]]] = {}
for source, snapshot in _romset_snapshots():
versions = snapshot.get("dats") or {}
order = {label: index for index, label in enumerate(versions)}
for entry in snapshot.get("entries") or []:
members = tuple(sorted(
(str(m["name"]), str(m.get("crc32") or "").lower())
for m in entry.get("members") or [] if m.get("name") is not None
))
if not entry.get("name") or not members or not all(crc for _n, crc in members):
continue
agreed = [(order.get(label, -1), _release_name(source, str(label), versions))
for label in entry.get("dats") or [entry.get("dat")]]
releases.setdefault(str(entry["name"]), []).append((members, source, agreed))
return releases
def _release_runs(releases: list[Release]) -> str:
"""Releases as runs of consecutive imports: "0.190 to 0.195, 0.220 to
0.289". One FBNeo version shared by 15 DATs reads once."""
runs: list[list[Release]] = []
for release in sorted(set(releases)):
if runs and release[1] == runs[-1][-1][1]:
continue
if runs and release[0] == runs[-1][-1][0] + 1:
runs[-1].append(release)
else:
runs.append([release])
return ", ".join(run[0][1] if len(run) == 1 else f"{run[0][1]} to {run[-1][1]}"
for run in runs)
def _source_order(source: str) -> tuple[bool, str]:
return source != "mame", source
def _romset_line(f: dict) -> str:
"""Which MAME and FBNeo releases a collected archive's contents match.
MAME and FBNeo check the members of an archive by CRC32, never its own
bytes or its member names: a set works with a release when it holds
every CRC32 the release's recipe lists, extra members or not. The
main neogeo.zip, which every MAME from 0.177 to 0.289 loads, read "No
match" when names had to agree and no member could be extra. Empty
when no recipe names the archive or the file is not on disk.
"""
recipes = _romset_releases().get(str(f.get("name", "")))
path = _REPO_ROOT / str(f.get("path", ""))
if not recipes or not path.is_file():
return ""
try:
with zipfile.ZipFile(path) as archive:
held = tuple(sorted((info.filename, f"{info.CRC:08x}")
for info in archive.infolist() if not info.is_dir()))
except (OSError, zipfile.BadZipFile) as exc:
print(f" WARNING: {path}: {exc}", file=sys.stderr)
return ""
crcs = {crc for _name, crc in held}
same: dict[str, list[Release]] = {}
holds: dict[str, list[Release]] = {}
# source -> (fewest CRC32s missing, the latest release missing that many)
closest: dict[str, tuple[int, Release]] = {}
for members, source, agreed in recipes:
missing = len({crc for _name, crc in members} - crcs)
if members == held:
same.setdefault(source, []).extend(agreed)
elif not missing:
holds.setdefault(source, []).extend(agreed)
elif agreed:
latest = max(agreed)
best = closest.get(source)
if best is None or (missing, -latest[0]) < (best[0], -best[1][0]):
closest[source] = (missing, latest)
def runs(found: dict[str, list[Release]], skip: dict[str, list[Release]]) -> str:
return " and ".join(
f"{_ROMSET_SOURCES.get(source, source)} {_release_runs(kept)}"
for source in sorted(found, key=_source_order)
for kept in [[r for r in found[source] if r not in skip.get(source, [])]] if kept)
said = []
if same:
said.append(f"Same contents as {runs(same, {})}")
if holds and runs(holds, same):
said.append(f"Holds every ROM of {runs(holds, same)}")
if said:
return ". ".join(said)
if not closest:
return f"No match in {_romset_coverage()}"
return "No match: missing " + ", ".join(
f"{_count(missing, 'ROM')} of {_ROMSET_SOURCES.get(source, source)} {release[1]}"
for source, (missing, release) in sorted(closest.items(),
key=lambda item: _source_order(item[0])))
@functools.lru_cache(maxsize=1)
def _romset_coverage() -> str:
"""The releases the recipes cover: "MAME 0.190 to 0.289 or FBNeo 1.0.0.03"."""
covered = {}
for source, snapshot in _romset_snapshots():
versions = snapshot.get("dats") or {}
if versions:
ends = [(index, _release_name(source, label, versions))
for index, label in enumerate(versions)]
# The ends of the span, read as one run.
span = [ends[0], (1, ends[-1][1])] if len(ends) > 1 else ends
covered[source] = f"{_ROMSET_SOURCES.get(source, source)} {_release_runs(span)}"
return " or ".join(covered[source] for source in sorted(covered, key=_source_order))
ROMSET_FAQ = "../wiki/technical-faq.md#which-mame-version-do-the-arcade-bios-sets-match"
def _system_file_card(
f: dict, consumers: FileConsumers, anchored: set[str] | None = None,
searchable: bool = True,
) -> list[str]:
"""One file of a system page: hashes, who reads it, its provenance.
``searchable`` false keeps even the name out of the site search: the
asset trees of game engines hold thousands of 0.ogg and tile.png.
"""
name = f["name"]
sha1_full = f.get("sha1", "unknown")
md5_full = f.get("md5", "unknown")
# The size a card names is the file's own, exact: rounded, 44,348,015
# and 44,356,548 bytes were one 42.3 MB.
size = _card_size(int(f.get("size", 0)))
# Who reads this file, not who reads a file of this name
plats = sorted(consumers.platforms.get(sha1_full, ()))
emus = sorted(consumers.emulators.get(sha1_full, ()))
installed = _installed_places(sha1_full, consumers, set(plats))
anchor = f"sha1-{sha1_full[:12]}" if sha1_full != "unknown" else ""
# A copy filed under two consoles of one maker is listed twice on its
# page: the first card holds the anchor, as an id names one element.
if anchored is not None:
if anchor in anchored:
anchor = ""
else:
anchored.add(anchor)
skip = markup.search_exclude()
lines = [markup.block_open("div", 'class="rb-sys-file"'), ""]
# The heading's own link is this page's, the icon is the file's own
# address, resolved by content wherever its card moves.
# The yardstick keeps the word, the size the page budget was set on.
icon = _PERMALINK_ICON if markup.starlight() else "permalink"
permalink = (
f' <a class="rb-permalink" href="{markup.site_href(f"files/?sha1={sha1_full}")}" '
f'aria-label="Permanent link to {html.escape(name)}" '
f'title="Permanent link, by content" {skip}>{icon}</a>'
) if anchor else ""
# A file nothing reads said so nowhere: 53 of 248 Sony cards had no
# emulator, platform or pack line and looked unfinished.
unread = (f' <span class="rb-badge rb-badge-muted" {skip}>No reader</span>'
if not (emus or plats or installed) else "")
# The download leads the card: as a "(download)" after the collection
# path, fourth of the facts, a reader of the Apple II page found none.
download = (
f' <a class="rb-download" href="{html.escape(_fetch_url(f["path"]))}" '
f'aria-label="Download {html.escape(name)}" {skip}>Download</a>'
) if f.get("path") and markup.starlight() else ""
lines.append(_card_title(
f'{_code(name)} <span class="rb-badge rb-badge-muted">{size}</span>{unread}{download}{permalink}',
anchor, searchable,
))
lines.append("")
# Each fact: its label, its values, whether the search reads it. What a
# setup does with the file comes first, the fingerprints last.
facts: list[tuple[str, list[str], bool]] = []
saved = _download_name(f["path"]) if f.get("path") else name
if saved != name:
# A .variants/ copy is stored as advision.zip.1c086064, and the
# browser names the download after the URL: copied as it came, the
# file a platform pins was not found under its name.
facts.append(("Save as", [f"{_code(name)}, the download is named {_code(saved)}"], False))
if plats:
# Each link lands on the platform's system section, and says where
# that platform puts the file. Out of the search: the card's title
# weighs the most a word can, and the list made the excerpt of
# every card a run of setup names and paths.
facts.append(("On the setup's list",
_places_lines(_platform_places(sha1_full, consumers)), False))
if installed:
# The packs that carry the file for their cores: a RetroBat user
# looking up scph5501.bin found every platform but RetroBat, whose
# pack installs it for six cores.
facts.append(("Packed for its emulators by", _places_lines(installed), False))
if emus:
facts.append(("Emulators", [", ".join(_emulator_links(sha1_full, consumers))], False))
romset = _romset_line(f)
if romset:
# The version question every arcade player asks, answered from the
# recipes: the cards named emulators and no release.
facts.append(("Romset", [romset], False))
if f.get("path"):
# The card named a file, its hashes and provenance, but not where to
# get it: a user missing scph5501.bin found the reference and no way
# to the bytes.
path = _code(f["path"])
if not markup.starlight():
path += f" ([download]({_fetch_url(f['path'])}))"
facts.append(("Collection path", [path], False))
catalogued = [line.split(": ", 1)[1]
for line in _provenance_lines(f.get("provenance") or {}, "../")]
if catalogued:
facts.append(("Catalogued", catalogued, False))
# Every hash in full: the site search indexes text, not a title
# attribute, so a pasted md5 or crc32 (what clrmamepro, RomVault or an
# emulator log prints) found nothing behind a 12-character prefix.
# files/?hash= finds them, and the index skips them.
for label, value in (("SHA1", sha1_full), ("MD5", md5_full),
("CRC32", f.get("crc32")), ("SHA256", f.get("sha256"))):
if value and value != "unknown":
# Starlight writes the value bare: its cell carries the hash
# style and the copy button (_fact_list).
shown = (html.escape(str(value)) if markup.starlight()
else f'<span class="rb-hash">{html.escape(str(value))}</span>')
facts.append((label, [shown], False))
if not markup.starlight():
# The size yardstick pages are cut by: the list a card was when the
# budget was set, so a fact grid moves no card to another page.
lines.extend(search_excluded([f"- {label}: {', '.join(values)}"
for label, values, _searched in facts]))
else:
lines.extend(_card_fact_groups(facts, sha1_full, searchable))
lines.extend(["", "</div>", ""])
return lines
# What a system card shows at a glance: who lists the file and who reads it.
# Its fingerprints and the rest open on demand, so a page of 250 cards reads
# as a list of files, not a wall of hashes.
_CARD_KEY_FACTS = ("Save as", "On the setup's list", "Packed for its emulators by", "Emulators")
_CARD_HASHES = ("SHA1", "MD5", "CRC32", "SHA256")
# The words a card's fold names its other facts by.
_CARD_MORE_WORDS = {"Romset": "romset", "Collection path": "collection path",
"Catalogued": "catalogues"}
# A hash shown short, in a card, a platform row or an emulator table: as long
# as the card's own address (sha1-<12 hex>), one length across the site.
SHORT_HASH = 12
def _listed_words(words: list[str]) -> str:
""""a", "a and b", "a, b and c", first letter capital."""
text = words[0] if len(words) == 1 else f"{', '.join(words[:-1])} and {words[-1]}"
return text[:1].upper() + text[1:]
def _fact_list(facts: list[tuple[str, list[str], bool]], skip: str,
copy: dict[str, str] | None = None) -> list[str]:
"""Facts as a grid, label then value, one value cell per label.
A label in *copy* holds one hash: its cell takes the hash style, and
the site script a copy button (site.ts). *copy* gives the cell's
classes. One element, where a span in the cell was one more per hash.
"""
if not facts:
return []
copy = copy or {}
def cell(label: str, values: list[str]) -> str:
if label in copy:
return f'<dd class="{copy[label]}">{values[0]}</dd>'
return "<dd>" + "<br>".join(_inline_card_html(v) for v in values) + "</dd>"
return [f'<dl class="rb-facts"{skip}>',
*(f"<dt>{label}</dt>{cell(label, values)}" for label, values, _searched in facts),
"</dl>"]
def card_fold(summary: str, body: list[str], skip: bool = True) -> list[str]:
"""A fold of a file card: closed, its summary naming what it holds.
Native details: no script needed, and the text inside stays in the page
(and in the search, unless *skip*). No class: the card styles its folds,
and a class was 21 bytes on each of 250 cards."""
attribute = f" {markup.search_exclude()}" if skip else ""
summary_line = f"<summary>{html.escape(summary, quote=False)}</summary>"
# Each tag on a line of its own, or MDX reads the fold as a paragraph
# left open. Markdown inside also takes a blank line around it.
gap = [] if body and body[0].startswith("<") else [""]
return [f"<details{attribute}>", summary_line, *gap, *body, *gap, "</details>"]
def _card_fact_groups(facts: list[tuple[str, list[str], bool]], sha1: str,
searchable: bool) -> list[str]:
"""A system card's facts under Starlight: the key ones open, a short
SHA1 first, then the hashes and the rest in one closed fold.
The search skips all of them, as it did when they were one list: on
each row the attribute was 77 KB of the Sony page. Hashes are found by
files/?hash=, which the search box offers for a pasted hash.
"""
skip = f" {markup.search_exclude()}"
key = [fact for fact in facts if fact[0] in _CARD_KEY_FACTS]
hashes = [fact for fact in facts if fact[0] in _CARD_HASHES]
more = [fact for fact in facts if fact not in key and fact not in hashes]
searched = [fact for fact in facts if fact[2] and searchable]
lines: list[str] = []
if searched:
# No fact is searched today. One that is keeps its label out: the
# excerpt ran the two together, "On the setup's listAmberELEC".
lines += ['<dl class="rb-facts">',
*(f"<dt{skip}>{label}</dt><dd>"
+ "<br>".join(_inline_card_html(v) for v in values) + "</dd>"
for label, values, _searched in searched),
"</dl>"]
key = [fact for fact in key if fact not in searched]
more = [fact for fact in more if fact not in searched]
glance = []
if sha1 and sha1 != "unknown":
# The first characters, enough to tell two dumps apart at a glance.
# Its button copies the whole value, read from the fold below: the
# value twice was 54 bytes more on each card.
glance.append(("SHA1", [html.escape(sha1[:SHORT_HASH])], False))
lines += _fact_list(glance + key, skip, {"SHA1": "rb-hash"})
# One fold: two were four more elements on each of 250 cards.
folded = hashes + more
if folded:
words = (["hashes"] if hashes else []) + [
_CARD_MORE_WORDS.get(label, label.lower()) for label, _values, _searched in more]
# On one line: nothing reads it as Markdown, and a page cut by size
# holds its cards in the same bytes.
lines += card_fold(_listed_words(words),
["".join(_fact_list(folded, "", dict.fromkeys(_CARD_HASHES, "rb-hash")))])
return lines
SEARCH_TABLE_BYTES = 3000
def tables_out_of_search(markdown: str, threshold: int = SEARCH_TABLE_BYTES) -> str:
"""Each table longer than ``threshold`` bytes, wrapped out of the search.
A search result shows the start of a section: a 600-row table as one
snippet helps nobody, and the gaps, provenance and cross-reference
tables were 900 KB of the index. The headings above them stay.
"""
lines = markdown.split("\n")
out: list[str] = []
index = 0
while index < len(lines):
match = re.match(r"( *)\|", lines[index])
if not match:
out.append(lines[index])
index += 1
continue
indent = match.group(1)
end = index
while end < len(lines) and re.match(rf"{indent}\|", lines[end]):
end += 1
table = lines[index:end]
if sum(len(line) for line in table) > threshold:
out += ["", indent + markup.block_open("section", markup.search_exclude()), "",
*table, "", f"{indent}</section>", ""]
else:
out += table
index = end
return "\n".join(out)
# Card lines the site search leaves out. They list where a file goes and
# who cites it, links to other pages that index the same names, and they
# were 6.6 of the 24.7 MB the browser downloads and indexes before the first
# result. The name, the hashes, the entry's path and the notes stay
# searchable.
SEARCH_SKIPPED = (
"- SHA1:", "- MD5:", "- CRC32:", "- SHA256:", "- Adler32", "- Size:",
"- Validation", "- Priority:", "- Contents (",
"- Platforms:", "- Source:", "- Asked for by:",
"- Collection path:", "- Collection copy:", "- Collection copies:",
"- Installed by the platform's own package on:",
"- Not in the platform's package", "- Never opened on these platforms",
)
def _search_skipped_apart(lines: list[str]) -> list[str]:
"""Card list lines, each run the search skips in a block of its own."""
out: list[str] = []
skipping = False
for line in lines:
skip = line.startswith(SEARCH_SKIPPED) or (skipping and line.startswith(" "))
if skip and not skipping:
out.extend(["", markup.block_open(
"div", f'class="rb-search-skip" {markup.search_exclude()}'), ""])
elif skipping and not skip:
out.extend(["", "</div>", ""])
skipping = skip
out.append(line)
if skipping:
out.extend(["", "</div>", ""])
return out
def _card_title(text: str, anchor: str, searchable: bool = True, weight: int = 10) -> str:
"""A file card's heading, so the site search lands on the card.
The search splits a page at its headings: a card titled in bold sent a
pasted md5 to the top of a page of a hundred cards. Level 3, under
the console or the Files heading: a level 4 after a level 2 skipped
one for screen readers on 551 pages. The table of contents of a page
of cards stops above it (sitestarlight.py), and a card without an
anchor keeps the id the toc gives it.
"""
if markup.starlight():
# Raw HTML: the card links to itself already, and a Markdown heading
# would add the engine's anchor link and icon to every card.
title = re.sub(r"`([^`]+)`", lambda m: f"<code>{html.escape(m[1], quote=False)}</code>", text)
ident = f' id="{anchor}"' if anchor else ""
# A system page's card is the file's own page in all but name: its
# title weighs the most a word can, so a file name typed in the
# search finds the card before a guide that cites it as an example.
# An emulator's card says who reads the file, and weighs half.
search = f' data-pagefind-weight="{weight}"' if searchable else f" {markup.search_exclude()}"
return f'<h3{ident} class="rb-file-title"{search}>{title}</h3>'
attributes = f"#{anchor} .rb-file-title" if anchor else ".rb-file-title"
if not searchable:
attributes += " data-search-exclude"
return f"### {text} {{ {attributes} }}"
def system_install_choices(coverages: dict) -> dict[str, dict[str, list[tuple[str, str]]]]:
"""slug -> console -> the (platform, system id) pairs linked to it.
Read through the same table as every system link, so a command sits in
the section the platform's system links to. Only a system the
platform's install manifest records is offered: --system refuses any
other name.
"""
from sitegen.render import _page_by_norm
choices: dict[str, dict[str, list[tuple[str, str]]]] = {}
for name, cov in sorted(coverages.items()):
manifest = _REPO_ROOT / "install" / f"{name}.json"
if not manifest.is_file():
continue
document = json.loads(manifest.read_text(encoding="utf-8"))
recorded = {
str(system)
for entry in (document.get("files") or []) + (document.get("omitted_files") or [])
for system in entry.get("systems") or []
}
for sys_id in sorted(set(cov["config"].get("systems") or {}) & recorded):
page = _system_page_map.get(sys_id) or _page_by_norm(sys_id)
if page:
slug, console = page
choices.setdefault(slug, {}).setdefault(console, []).append((name, sys_id))
return choices
def _emulator_display(emulator: str) -> str:
return str((_profiles_on_disk().get(emulator) or {}).get("emulator") or emulator)
def _first_hash_value(entry: dict) -> str:
"""The first declared hash of an entry, lowercase, for a stable anchor."""
for field in ("sha1", "md5", "crc32", "sha256"):
value = entry.get(field)
value = value[0] if isinstance(value, list) and value else value
if value:
return str(value).lower().split(",")[0].strip().removeprefix("0x")
return ""
def _card_size(size: int) -> str:
"""A file's size, exact: in whole MB or KB when it is one, else in B."""
for unit, scale in (("MB", 1024 * 1024), ("KB", 1024)):
if size >= scale and size % scale == 0:
return f"{size // scale:,} {unit}"
return f"{size:,} B"
+51
View File
@@ -0,0 +1,51 @@
"""The site's fixed names and addresses, and the date its data is read at."""
from __future__ import annotations
from datetime import datetime, timezone
import release_record
from core.paths import REPO_ROOT
from model.safeparse import require_yaml
yaml = require_yaml()
# The Starlight project, and where its pages go inside it.
STARLIGHT_DIR = "website"
STARLIGHT_CONTENT = "src/content/docs"
SITE_NAME = "RetroBIOS"
REPO_URL = "https://github.com/Abdess/retrobios"
RELEASE_URL = f"{REPO_URL}/releases/latest"
# What LICENSE grants over the published data: its MIT terms name the
# metadata. The BIOS files themselves are under NOTICE, never this.
DATA_LICENSE = "MIT (LICENSE: scripts, tooling, schemas, documentation and metadata)"
SITE_URL = "https://abdess.github.io/retrobios/"
GENERATED_DIRS = ["platforms", "systems", "emulators", "wiki", "api", "downloads", "files",
release_record.GET_DIR]
# Generated directories of files served as they are, not pages.
PUBLIC_DIRS = ("api", "downloads")
def _timestamp() -> str:
"""The build time for data files (stats, API records), ISO 8601."""
return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
def data_as_of(moment: datetime | None = None) -> str:
"""The build date for a reader, in words, with the machine form beside it.
A raw ISO stamp ("2026-10-22T22:43:08Z") closed the home page."""
moment = moment or datetime.now(timezone.utc)
return (f'<time datetime="{moment.strftime("%Y-%m-%dT%H:%M:%SZ")}">'
f"Data as of {moment.day} {moment.strftime('%B %Y')}</time>")
def _date_line() -> str:
"""The date a page closes on, in the words of data_as_of(). The search
does not read it: a query word such as the "2" of "playstation 2 bios"
also matches the start of "2026", and every page closing on the date
then held every word of the query."""
return f'<div class="rb-timestamp" data-pagefind-ignore>{data_as_of()}.</div>'
_REPO_ROOT = REPO_ROOT
+257
View File
@@ -0,0 +1,257 @@
"""The cards of one console, ranked and grouped by section and region."""
from __future__ import annotations
import re
from typing import TypeVar
from model.collection import _profiles_on_disk
from model.composition import GAME_DATA_TOPS
from model.guides import INSTALL_PS1, INSTALL_SH
from model.profiles import entry_system_ids
from packs.crossref import FileConsumers
from sitegen.cards import _emulator_display, _romset_releases, _system_file_card
# A manufacturer page above this much Markdown becomes a summary with one
# page per console, and a console above it is cut into parts. Measured as
# MkDocs Markdown, a page renders to up to 1.8 times its size in HTML with
# its structured data: at 500 KB the Sony page was 849 KB, and every page
# stays under 600 KB from 300 KB. game-engines was one 10.5 MB page that
# took 21 s of main-thread work on a phone.
SYSTEM_PAGE_BUDGET = 300_000
# Manufacturers whose every console gets a page of its own, whatever its
# size. A section shares its page's search fields with its neighbours, and
# a digit is on too many pages to weigh: "playstation 3 bios" found the
# PlayStation page before the Sony page that held the PlayStation 3.
CONSOLE_PAGES = frozenset({"Sony"})
# What the sections kept on a manufacturer's summary may weigh once
# rendered, estimated from their Markdown. Fitted on the Nintendo, Sega and
# Commodore summaries: highlighted install commands grow about eleven times
# since each carries its setup's name, cards 1.7 times. The page budget is
# 600 KB of HTML, and the frame around the content (head, navigation,
# footer) is about 45 KB.
CARD_HTML_RATIO = 1.7
INSTALL_HTML_RATIO = 11
SYSTEM_SUMMARY_HTML = 500_000
# The ratio was fitted while each command named the raw.githubusercontent.com
# bootstrap, 66 characters (67 for PowerShell). A box is weighed with its
# address at that length, so the shorter site address moves no console off
# or onto a summary and no card changes address.
FITTED_ADDRESS_CHARS = {INSTALL_PS1: 67, INSTALL_SH: 66}
def _install_box_weight(lines: list[str]) -> int:
weight = 0
for line in lines:
weight += len(line) + 1
for address, fitted in FITTED_ADDRESS_CHARS.items():
found = line.count(address)
line = line.replace(address, "")
weight += found * (fitted - len(address))
return weight
# A system card: whether it is a variant, its lines, its sha1.
Card = tuple[bool, list[str], str]
_Item = TypeVar("_Item")
def _reading_entries(sha1: str, consumers: FileConsumers) -> list[dict]:
"""The profile entries that read a file, one per emulator."""
files_of = getattr(consumers, "emulator_files", {})
entries = []
for emulator, index in getattr(consumers, "emulator_entries", {}).get(sha1, {}).items():
files = files_of.get(emulator) or []
if 0 <= index < len(files) and isinstance(files[index], dict):
entries.append(files[index])
return entries
_NO_PRIORITY = 1 << 30
def _card_rank(f: dict, consumers: FileConsumers, start: dict[str, int] | None = None) -> tuple:
"""Where a file's card sits in its console: the files the section's
start line names first, in its order (``start``, sha1 -> place), then
the files an emulator requires, then by the emulators' search order
(smallest first), then a required file by how many emulators read it,
then by how many setups list the file, then by name.
By byte order the PlayStation section opened on LibPS.exe and
PSX_DTLH2000.bin, capitals first, and scph5501.bin was 28th. Without
the reader count the Neo Geo section opened on aes.zip, which geolith
alone reads. Without the start line's order, "first below" named
neogeo.zip over a section opening on sfix.sfix.
"""
sha1 = str(f.get("sha1", ""))
entries = _reading_entries(sha1, consumers)
priorities = [e["priority"] for e in entries if isinstance(e.get("priority"), int)]
required = any(e.get("required", True) for e in entries)
return (
(start or {}).get(sha1, _NO_PRIORITY),
not required,
min(priorities, default=_NO_PRIORITY),
-len(entries) if required else 0,
-len(consumers.platforms.get(sha1, ())),
f["name"].casefold(), f["name"], f.get("path", ""),
)
def _by_name(f: dict) -> tuple:
return f["name"].casefold(), f["name"], f.get("path", "")
def _console_cards(
manufacturer: str,
files: list[dict],
consumers: FileConsumers,
anchored: set[str],
by_name: bool = False,
start: list[str] | None = None,
) -> list[Card]:
"""Each card of one console, primaries then variants, with whether it
is a variant. ``start`` is the sha1s the start line names, whose cards
come first in its order. ``by_name`` orders the rest by name alone,
for a console cut into parts named by their first and last file: the
PlayStation 2 opened on cheats_ni.zip, its BIOS far below."""
searchable = manufacturer not in GAME_DATA_TOPS
place = {sha1: index for index, sha1 in enumerate(start or [])}
def order(f: dict) -> tuple:
if by_name:
return (place.get(str(f.get("sha1", "")), _NO_PRIORITY), *_by_name(f))
return _card_rank(f, consumers, place)
# Another revision of a MAME or FBNeo set is another release's set, its
# Romset line saying which: it sits open beside the set of its name.
# Twelve neogeo.zip were on five pages, the SNK ones closed under
# Variants.
romsets = _romset_releases()
beside = [f for f in files if "/.variants/" in f["path"] and f["name"] in romsets]
main_files = [f for f in files if "/.variants/" not in f["path"]]
variant_files = [f for f in files if "/.variants/" in f["path"] and f not in beside]
# Sets of one name side by side, the first ranked leading.
ranked = sorted(main_files, key=order)
by_set: dict[str, list[dict]] = {}
for f in [*ranked, *sorted(beside, key=order)]:
if f["name"] in romsets:
by_set.setdefault(f["name"], []).append(f)
ordered: list[dict] = []
for f in ranked:
if f["name"] not in romsets:
ordered.append(f)
elif by_set.get(f["name"]):
ordered.extend(by_set.pop(f["name"]))
ordered.extend(f for files in by_set.values() for f in files)
cards = [(False, _system_file_card(f, consumers, anchored, searchable), str(f.get("sha1", "")))
for f in ordered]
cards += [(True, _system_file_card(v, consumers, anchored, searchable), str(v.get("sha1", "")))
for v in sorted(variant_files, key=order)]
return cards
# A "Start with" line names this many files at most: Game Engines'
# TheXTech requires 2,014.
START_WITH_NAMES = 6
def _region_order() -> dict[str, int]:
"""The regions a start line lists, the territories first. A file read
for every region is a region-free stand-in for the BIOS of each one:
the PlayStation section opened on psxonpsp660.bin, which one emulator
requires among the BIOS it accepts, above the scph files most read."""
from model.region import REGION_TREE, WORLD
ordered = []
for parent, members in REGION_TREE.items():
ordered += [parent, *sorted(members)]
ordered.append(WORLD)
return {region: index for index, region in enumerate(ordered)}
def _reading_pairs(sha1: str, consumers: FileConsumers) -> list[tuple[str, dict]]:
"""The profile entries that read a file, each with its emulator."""
files_of = getattr(consumers, "emulator_files", {})
pairs = []
for emulator, index in sorted(getattr(consumers, "emulator_entries", {}).get(sha1, {}).items()):
files = files_of.get(emulator) or []
if 0 <= index < len(files) and isinstance(files[index], dict):
pairs.append((emulator, files[index]))
return pairs
def _entry_systems(emulator: str, entry: dict) -> list[str]:
"""The systems an entry is read for: its own `system:` or `systems:`
(a MAME device set several systems load), else its profile's only one."""
if entry.get("system") or entry.get("systems"):
return entry_system_ids(entry, {})
systems = (_profiles_on_disk().get(emulator) or {}).get("systems") or []
return [str(systems[0])] if len(systems) == 1 else []
# id(consumers) -> (consumers, section -> the entries whose system leads there).
_SECTION_ENTRIES: dict[int, tuple[object, dict[tuple[str, str], list]]] = {}
def _entries_by_section(consumers: FileConsumers) -> dict[tuple[str, str], list]:
"""Each console section with the (sha1, emulator, entry, system) whose
system leads to it, read once per build."""
from sitegen.render import system_section
cached = _SECTION_ENTRIES.get(id(consumers))
if cached is not None and cached[0] is consumers:
return cached[1]
sections: dict[str, tuple[str, str] | None] = {}
index: dict[tuple[str, str], list] = {}
for sha1 in sorted(getattr(consumers, "emulator_entries", {})):
for emulator, entry in _reading_pairs(sha1, consumers):
for sys_id in _entry_systems(emulator, entry):
if sys_id not in sections:
sections[sys_id] = system_section(sys_id)
place = sections[sys_id]
if place is not None:
index.setdefault(place, []).append((sha1, emulator, entry, sys_id))
_SECTION_ENTRIES.clear()
_SECTION_ENTRIES[id(consumers)] = (consumers, index)
return index
def _setup_name(f: dict, consumers: FileConsumers, pairs: list[tuple[str, dict]]) -> str:
"""The name most setups give a file, else most emulators: the collection
keeps BizHawk's GBA_bios.rom where eight setups write gba_bios.bin."""
counts: dict[str, int] = {}
destinations = getattr(consumers, "platform_destinations", {}).get(str(f.get("sha1", "")), {})
for dests in destinations.values():
for base in {d.replace("\\", "/").rsplit("/", 1)[-1] for d in dests if d}:
counts[base] = counts.get(base, 0) + 1
if not counts:
for _emulator, entry in pairs:
if entry.get("name"):
name = str(entry["name"])
counts[name] = counts.get(name, 0) + 1
if not counts:
return f["name"]
most = max(counts.values())
top = sorted((n for n, c in counts.items() if c == most), key=lambda n: (n.casefold(), n))
return f["name"] if f["name"] in top else top[0]
def _without_files(emulators: list[str]) -> str:
"""Who runs without the files: every emulator reading one, up to three
by name, more counted, as their order would rank nothing."""
names = sorted({_emulator_display(e) for e in emulators}, key=str.casefold)
if len(names) > 3:
return f": none of its {len(names)} emulators requires one"
return " with " + (", ".join(names[:-1]) + f" or {names[-1]}" if len(names) > 1 else names[0])
def _visible(name: str) -> str:
"""The file name a start line shows, out of its code span and link."""
match = re.match(r"\[?`([^`]*)`", name)
return match[1] if match else name
def _add_name(names: list[str], name: str) -> None:
"""A name once per line: two copies of sfcbox.zip read as one file."""
if all(_visible(n) != _visible(name) for n in names):
names.append(name)
+298
View File
@@ -0,0 +1,298 @@
"""The cross-reference page: emulators against platforms and upstream projects."""
from __future__ import annotations
import re
import urllib.request
from model.systemnames import system_name
from resolve.cores import resolve_platform_cores
from sitegen import markup
from sitegen.config import _date_line
from sitegen.emulatorsindex import CLS_LABEL_ONE
from sitegen.parts import _parent_front_matter
from sitegen.platformpage import OWN_LIST_ONLY, _own_list_only
from sitegen.render import _count, _escape_tags
def _core_scope_note(config: dict, profiles: dict) -> str:
"""" (all libretro)" when the platform resolves every libretro core.
Read from what resolve_platform_cores returns, not from the shape of
``cores:``: RetroPie and RetroDECK name ``retroarch`` in a list, which
pulls in every libretro core as ``all_libretro`` does, and the label
showed for RetroArch and Lakka only.
"""
every_libretro = resolve_platform_cores({"cores": "all_libretro"}, profiles)
resolved = resolve_platform_cores(config, profiles)
if not every_libretro or not every_libretro <= resolved:
return ""
others = len(resolved - every_libretro)
if not others:
return " (all libretro)"
return f" (all libretro, plus {_count(others, 'other core')})"
def _gap_sources(data: dict) -> dict[str, int]:
"""Where each undeclared file of one emulator comes from.
A file the emulator's own package installs is not one to find. The
report's gap_missing counts it, and the gaps page announced 1,356 files
to source where 609 are, with a red badge on emulators that have none.
"""
counts = {"bios": 0, "data": 0, "large_file": 0, "bundled": 0, "missing": 0}
for gap in data.get("gap_details") or []:
source = gap.get("source", "")
if source == "missing" and gap.get("bundled"):
source = "bundled"
if source in counts:
counts[source] += 1
return counts
def _xref_upstream(profile: dict) -> str:
"""The project a core comes from: its upstream, else its own source."""
raw = profile.get("upstream") or profile.get("source", "")
return raw if isinstance(raw, str) else ""
_FORGES = frozenset({
"github.com", "gitlab.com", "codeberg.org", "bitbucket.org", "git.eden-emu.dev",
"git.ryujinx.app",
})
def upstream_project(url: str) -> tuple[str, str]:
"""(project key, revision or path inside it) for an upstream URL.
MAME was twelve rows: mamedev/mame and one row per release tree
(mamedev/mame/tree/mame0289 and the rest). On a forge the project is
owner/repo, a GitLab project every group before `/-/`, and the rest is
a revision. Elsewhere the address without its scheme, `www.` and
trailing slash is the project. A note written after the address
(`... (sys/src/games/nes/)`) is a path inside it.
"""
url, _, note = url.strip().partition(" ")
note = note.strip().strip("()")
if not url.startswith(("http://", "https://")):
return " ".join(filter(None, (url, note))), ""
parsed = urllib.parse.urlsplit(url)
host = parsed.netloc.lower().removeprefix("www.")
parts = [p for p in parsed.path.split("/") if p]
if host == "gitlab.com" and len(parts) >= 2:
cut = parts.index("-") if "-" in parts else len(parts)
rest = parts[cut + 1:]
if rest[:1] in (["tree"], ["blob"]):
rest = rest[1:]
return f"{host}/{'/'.join(parts[:cut])}", "/".join(filter(None, ("/".join(rest), note)))
if host in _FORGES and len(parts) >= 2:
repo = parts[1].removesuffix(".git")
rest = parts[2:]
if rest[:1] in (["tree"], ["blob"], ["src"]):
rest = rest[1:]
return f"{host}/{parts[0]}/{repo}", "/".join(filter(None, ("/".join(rest), note)))
return "/".join([host, *parts]), note
def _upstream_label(key: str) -> str:
"""owner/repo on GitHub, host/owner/repo on another forge, and a
Software Heritage revision by its short id."""
swh = re.fullmatch(r"archive\.softwareheritage\.org/browse/revision/([0-9a-f]{12})[0-9a-f]*", key)
if swh:
return f"Software Heritage revision {swh[1]}"
return key.removeprefix("github.com/")
def _breakable(label: str) -> str:
"""A project address that may wrap after each slash: unbroken, the
longest pushed three of five columns off a 1,440 px screen."""
return "/<wbr>".join(_escape_tags(part) for part in label.split("/"))
def _xref_platform_rows(config: dict, unique: dict) -> tuple[int, list[str]]:
"""The cores a platform pulls in, as table rows, with their count."""
# The cores the builder and verify resolve: a hand copy here dropped
# the libretro set a list naming retroarch pulls in, and the system
# fallback EmuDeck relies on.
matched = sorted(key for key in resolve_platform_cores(config, unique) if key in unique)
rows = []
for emu_name in matched:
p = unique[emu_name]
cls_raw = p.get("core_classification", "-")
systems = p.get("systems", []) or []
sys_str = ", ".join(_escape_tags(system_name(s)) for s in systems[:3])
if len(systems) > 3:
sys_str += f" +{len(systems) - 3}"
files = p.get("files", []) or []
libretro_only = sum(1 for f in files if f.get("mode") == "libretro")
standalone_only = sum(1 for f in files if f.get("mode") == "standalone")
file_str = str(len(files))
parts = [f"{n} {label}" for n, label in ((libretro_only, "libretro-only"),
(standalone_only, "standalone-only")) if n]
if parts:
file_str += f" ({', '.join(parts)})"
upstream = _xref_upstream(p)
key, _rest = upstream_project(upstream)
upstream_display = (f"[{_breakable(_upstream_label(key))}]({upstream.split()[0]})"
if upstream.startswith("http") else (_escape_tags(upstream) or "-"))
rows.append(
f"| [{_escape_tags(p.get('emulator', emu_name))}](emulators/{emu_name}.md) "
f"| {CLS_LABEL_ONE.get(cls_raw, cls_raw)} | {sys_str or '-'} | {file_str} "
f"| {upstream_display} |"
)
return len(matched), rows
def _render_xref_by_platform(
coverages: dict, unique: dict, moved: dict[str, str] | None = None,
) -> list[str]:
"""Which cores each platform pulls in: counts here, a page per platform.
One page held every platform's table, 30,551 nodes: the overview keeps
the counts and each platform's table moves to ``moved`` by stem.
"""
lines = [
"## By platform",
"",
"| Platform | Cores | Core list |",
"|----------|------:|-----------|",
]
for pname in sorted(coverages, key=lambda x: coverages[x]["platform"]):
cov = coverages[pname]
display = cov["platform"]
config = cov["config"]
count, rows = _xref_platform_rows(config, unique)
stem = f"cross-reference-{pname}"
if _own_list_only(config):
# cores: [] (MiSTer, BizHawk): no profile describes what they
# read, and a page of cores would be an empty table.
lines.append(f"| [{_escape_tags(display)}](platforms/{pname}.md) | 0 "
f"| {OWN_LIST_ONLY} |")
continue
lines.append(
f"| [{_escape_tags(display)}](platforms/{pname}.md) | {count}"
f"{_core_scope_note(config, unique)} | [Cores on {_escape_tags(display)}]({stem}.md) |"
)
if moved is not None:
moved[stem] = "\n".join([
"---", "level: reference",
*_parent_front_matter(("Cores by platform", "/cross-reference/")), "---", "",
f"# Cores on {display}",
"",
f"{_count(count, 'core')}{_core_scope_note(config, unique)} that "
f"{display} runs, the systems each emulates and the project it comes "
f"from. Part of [Cores by platform](cross-reference.md). The files "
f"are listed on the [{display} page](platforms/{pname}.md).",
"",
"| Core | Classification | Systems | Files | Upstream |",
"|------|---------------|---------|-------|----------|",
*rows,
"",
]) + "\n"
lines.append("")
return lines
def _render_xref_by_upstream(
coverages: dict, unique: dict
) -> list[str]:
"""The same relation read the other way: one row per upstream project."""
lines: list[str] = [
"## By upstream emulator",
"",
"One row per project: the releases and folders of one repository are "
"listed in the Revisions column. Platforms counts the platforms that run "
"at least one of its cores.",
"",
"| Cores | Upstream | Revisions | Classification | Platforms |",
"|-------|----------|-----------|----------------|----------:|",
]
by_upstream: dict[str, list[tuple[str, str, str]]] = {}
for emu_name, p in sorted(unique.items()):
# A null upstream is the project's own source: grouping it under
# the string "None" put eight unrelated engines in one row.
up_str = _xref_upstream(p)
if up_str:
key, rest = upstream_project(up_str)
by_upstream.setdefault(key, []).append((emu_name, up_str, rest))
platform_membership: dict[str, set[str]] = {}
for cov in coverages.values():
for key in resolve_platform_cores(cov["config"], unique):
platform_membership.setdefault(key, set()).add(cov["platform"])
for key in sorted(by_upstream, key=lambda k: _upstream_label(k).casefold()):
members = by_upstream[key]
cores = sorted(c for c, _url, _rest in members)
classifications = sorted({
CLS_LABEL_ONE.get(unique[c].get("core_classification", "-"),
unique[c].get("core_classification", "-"))
for c in cores
})
plats = sorted(set().union(*(platform_membership.get(c, set()) for c in cores)))
revisions = sorted({rest for _c, _url, rest in members if rest})
urls = sorted({url.split()[0] for _c, url, _rest in members})
# The project's own address: the bare one when a core cites it.
home = next((u for u in urls if not upstream_project(u)[1]), urls[0])
upstream_cell = (f"[{_breakable(_upstream_label(key))}]({home})" if home.startswith("http")
else _escape_tags(key))
lines.append(
"| " + ", ".join(f"[{c}](emulators/{c}.md)" for c in cores)
+ f" | {upstream_cell} | {', '.join(_breakable(r) for r in revisions) or '-'} "
f"| {', '.join(classifications)} | {len(plats)} |"
)
return lines
def generate_cross_reference(
coverages: dict,
profiles: dict,
moved: dict[str, str] | None = None,
) -> str:
"""Cross-reference: counts per platform, then cores by upstream project.
``moved`` collects one page per platform with its core table.
"""
unique = {
k: v for k, v in profiles.items() if v.get("type") != "alias" and v.get("role") != "test"
}
total_cores = len(unique)
total_upstreams = len({
upstream_project(_xref_upstream(p))[0] for p in unique.values() if _xref_upstream(p)
})
# "623 cores across 18 platforms" counted every profile: 91 of them
# no platform runs.
run_cores = len({
key for cov in coverages.values()
for key in resolve_platform_cores(cov["config"], unique)
})
lines = [
"# Cores by platform",
"",
"Every core each platform runs, the systems it emulates, and the project "
"it comes from. A core built for RetroArch is often a port of another "
"emulator, and the two can differ in the files they read and the checks "
"they make, so each core names its upstream project. "
f"{total_cores} cores are profiled, {run_cores} of them run by the "
f"{len(coverages)} platforms, and they come from {total_upstreams} "
"upstream projects.",
"",
"The files a platform's emulators load and its own list does not name are "
"counted on [What the packs do not hold](gaps.md).",
"",
" ".join([
markup.button("Download cross-reference CSV", "downloads/cross-reference.csv"),
markup.button("Open emulator API", "api/v1/emulators.json"),
markup.button("All data exports", "data.md"),
]),
"",
]
lines.extend(_render_xref_by_platform(coverages, unique, moved))
lines.extend(_render_xref_by_upstream(coverages, unique))
lines.extend(["", _date_line()])
return "\n".join(lines) + "\n"
+927
View File
@@ -0,0 +1,927 @@
"""The bulk data exports: CSV, JSON and SQLite of the collection, platforms and gaps."""
from __future__ import annotations
import csv
import functools
import hashlib
import io
import json
import os
import re
import shutil
import sqlite3
import sys
from collections.abc import Callable
from pathlib import Path
from core.artifacts import json_text as _json_text
from model import retired as model_retired
from model.dumpcatalog import load_provenance_snapshots
from packs.crossref import FileConsumers
from provenance_report import build_report
from sitegen.apiitems import _sha1_by_path, core_index_items, system_index_items
from sitegen.config import DATA_LICENSE, REPO_URL, _REPO_ROOT, _timestamp
from sitegen.install import _release_pack_platforms
from sitegen.lookup import (
HASH_ALGORITHMS,
_hash_values,
data_directory_members,
file_location_items,
file_lookup_records,
write_lookup_shards,
)
from sitegen.provenance import load_derivable
from sitegen.publish import _publish_manifests
from sitegen.structured import _write_platform_dats, collection_dat
from sitegen.write import _record, write_if_changed
def generate_stats(stats: dict) -> str:
return json.dumps(stats, indent=2) + "\n"
def _accepted_hash_rows(platform_files: list[dict], emulator_items: list[dict]) -> list[dict]:
"""One row per accepted hash value, for both layers, lookup-ready."""
rows: list[dict] = []
for row in platform_files:
for algorithm in HASH_ALGORITHMS:
rows.extend({
"layer": "platform", "owner": row["platform_id"],
"system": row["system"], "name": row["name"],
"path": row["destination"], "algorithm": algorithm, "value": value,
} for value in _hash_values(row.get(f"{algorithm}_raw", row.get(algorithm))))
for item in emulator_items:
for entry in item["profile"].get("files", []) or []:
if not isinstance(entry, dict):
continue
for algorithm in HASH_ALGORITHMS:
rows.extend({
"layer": "emulator", "owner": item["id"],
"system": _json_text(entry.get("system")),
"name": entry.get("name", ""), "path": entry.get("path", "") or "",
"algorithm": algorithm, "value": value,
} for value in _hash_values(entry.get(algorithm)))
# Members of an archive: MAME and FBNeo hash the ROMs inside the
# set, never the set. Left out, a loose nmk004.bin (crc32
# 83b6f611) found no row while the site search found it.
archive = entry.get("name", "")
for member in entry.get("contents") or []:
if not isinstance(member, dict) or not member.get("name"):
continue
for algorithm in HASH_ALGORITHMS:
rows.extend({
"layer": "emulator", "owner": item["id"],
"system": _json_text(entry.get("system")),
"name": str(member["name"]), "path": f"{archive}/{member['name']}",
"algorithm": algorithm, "value": value,
} for value in _hash_values(member.get(algorithm)))
rows.sort(key=lambda r: (r["layer"], r["owner"], r["name"], r["algorithm"], r["value"]))
return rows
def _csv_document(fieldnames: list[str], rows: list[dict]) -> str:
stream = io.StringIO(newline="")
writer = csv.DictWriter(
stream, fieldnames=fieldnames, extrasaction="ignore", lineterminator="\n"
)
writer.writeheader()
writer.writerows(rows)
return stream.getvalue()
def _sha256_path(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as handle:
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
digest.update(chunk)
return digest.hexdigest()
def _verify_outcomes(
coverage: dict, sha1_by_path: dict[str, str]
) -> Callable[[str, str], dict]:
"""For each declared entry, in declaration order: what verify found.
Returns a function of (system, name) giving the next outcome for that
pair: status, category, the collection path that answers the entry and
that file's sha1. The CSV gave the declaration and nothing about it.
"""
details: dict[tuple[str, str], list[dict]] = {}
for detail in coverage.get("details") or []:
details.setdefault((detail.get("system", ""), detail.get("name", "")), []).append(detail)
taken: dict[tuple[str, str], int] = {}
def outcome(system: str, name: str) -> dict:
found = details.get((system, name)) or [{}]
nth = taken.get((system, name), 0)
taken[(system, name)] = nth + 1
detail = found[min(nth, len(found) - 1)]
path = str(detail.get("path") or "") if detail.get("status") != "missing" else ""
return {
"status": detail.get("status", ""),
"category": detail.get("category", ""),
"collection_path": path,
"resolved_sha1": sha1_by_path.get(path, "") if path else "",
}
return outcome
@functools.lru_cache(maxsize=1)
def _contract_keys() -> frozenset[str]:
"""The top-level keys platform.schema.json allows in a platform's list."""
schema = json.loads((_REPO_ROOT / "schemas" / "platform.schema.json").read_text(encoding="utf-8"))
return frozenset(schema.get("properties") or {})
def _split_contract(config: dict) -> tuple[dict, dict]:
"""The list, valid against platform.schema.json, and the registry entry.
load_platform_config merges the registry into the list: `install`,
`logo`, `scraper` and `_key` made all 18 contracts fail the published
schema. They stay published, beside the contract.
"""
allowed = _contract_keys()
contract = {key: value for key, value in config.items() if key in allowed}
# platform_system and platform_cores are the resolver's copies of the key
# each entry sits under and of that system's cores.
if isinstance(contract.get("systems"), dict):
contract["systems"] = {
sys_id: {
**system,
"files": [
{
k: v
for k, v in f.items()
if k not in ("platform_system", "platform_cores")
}
for f in system["files"]
],
}
if isinstance(system, dict) and system.get("files")
else system
for sys_id, system in contract["systems"].items()
}
registry = {key: value for key, value in config.items()
if key not in allowed and key != "_key"}
# The merged config gives a child its parent's release_pack: Lakka and
# RetroPie said true in the API while every page said they had no ZIP.
# The registry's own entry decides, as it does for the pages.
released = config.get("_key") in _release_pack_platforms()
if released or "release_pack" in registry:
registry["release_pack"] = released
return contract, registry
# Per-entry fields a folder check needs beyond the hashes: an md5 is a ZIP
# member's when zipped_file is set, and a CSV without it judged 106 good
# Batocera files wrong.
ENTRY_EXPORT_FIELDS = (
"zipped_file", "hash_match_mandatory", "mandatory_declared", "curated",
"shared_group", "mirror_of", "zip_digest",
)
def _platform_export_rows(
coverages: dict, db: dict | None = None,
) -> tuple[list[dict], list[dict]]:
"""Normalized platform summaries and one row per declared file."""
items: list[dict] = []
file_rows: list[dict] = []
sha1_by_path = _sha1_by_path(db)
for key, coverage in sorted(coverages.items()):
config = coverage["config"]
outcome = _verify_outcomes(coverage, sha1_by_path)
contract, registry = _split_contract(config)
items.append({
"id": key,
"name": coverage["platform"],
"coverage": {
field: coverage.get(field, 0)
for field in (
"total", "present", "verified", "untested", "missing",
"core_present", "core_missing", "core_unsourceable",
)
},
"contract": contract,
"registry": registry,
})
for system_id, system in sorted(config.get("systems", {}).items()):
file_rows.extend({
"platform_id": key,
"platform": coverage["platform"],
"system": system_id,
"name": entry.get("name", ""),
"destination": entry.get(
"destination", entry.get("dest", entry.get("name", ""))
),
"required": bool(entry.get("required", True)),
"region": _json_text(entry.get("region")),
"selection_slot": _json_text(entry.get("selection_slot")),
"size": entry.get("size"),
"sha1": _json_text(entry.get("sha1")),
"sha256": _json_text(entry.get("sha256")),
"md5": _json_text(entry.get("md5")),
"crc32": _json_text(entry.get("crc32")),
**{field: _export_flag(entry.get(field)) for field in ENTRY_EXPORT_FIELDS},
**outcome(system_id, entry.get("name", "")),
} for entry in system.get("files", []) or [])
return items, file_rows
def _export_flag(value: object) -> object:
"""A per-entry field as CSV and SQLite hold it: booleans stay booleans,
an absent field is empty."""
if value is None:
return ""
return value if isinstance(value, bool) else str(value)
def _emulator_export_items(profiles: dict) -> list[dict]:
return [
{"id": key, "profile": profile}
for key, profile in sorted(profiles.items())
]
def build_emulator_gap_report(
profiles: dict,
coverages: dict,
db: dict,
data_names: set[str] | None = None,
) -> dict:
"""Files a core loads that no platform declares, per emulator profile.
The gap analysis page and the published gaps export must not compute this
twice and drift. Both read this one report.
"""
from model.systems import _norm_system_id
from model.declarations import merged_platform_declarations
from packs.crossref import cross_reference as run_cross_reference
# Enriched with alias resolution, with each declaration's size and slot:
# a name alone settled DOSBox's 32 KiB SC-55 ROM1.BIN on Galaksija's.
all_declared = merged_platform_declarations(
[cov["config"] for cov in coverages.values()], db
)
declared: dict[str, set[str]] = {}
for cov in coverages.values():
config = cov["config"]
for sys_id, system in config.get("systems", {}).items():
for fe in system.get("files", []):
fname = fe.get("name", "")
if fname:
declared.setdefault(_norm_system_id(sys_id), set()).add(fname)
unique_profiles = {
k: v
for k, v in profiles.items()
if v.get("type") != "alias" and v.get("role") != "test"
}
from resolve.standalone import merged_standalone_set
from model.declarations import platform_declarations
from resolve.validation import case_folded_slots
# The command line passes these too: without them a RetroBat file named
# 32X_G_BIOS.BIN read as missing for a core opening 32X_G_BIOS.bin.
folded = frozenset().union(*(
case_folded_slots(cov["config"], platform_declarations(cov["config"], db))
for cov in coverages.values()
))
return run_cross_reference(
unique_profiles, declared, db,
data_names=data_names, all_declared=all_declared,
standalone_cores=merged_standalone_set(
cov["config"] for cov in coverages.values()
),
folded_slots=folded,
)
def _gap_export_rows(
coverages: dict, gap_report: dict | None = None, db: dict | None = None,
profiles: dict | None = None,
) -> list[dict]:
"""Every gap the site reports, both layers, in one table.
``platform`` rows are anomalies against a platform's own BIOS list.
``emulator`` rows are files a profiled core loads that no platform
declares, which is the larger number the gap analysis page leads with.
A `layer` column keeps the two apart instead of publishing only one.
"""
rows: list[dict] = []
sha1_by_path = _sha1_by_path(db)
for key, coverage in sorted(coverages.items()):
for detail in coverage.get("details", []):
if detail.get("status") == "ok" and not detail.get("discrepancy"):
continue
path = str(detail.get("path") or "") if detail.get("status") != "missing" else ""
rows.append({
"category": detail.get("category", "bios"),
"collection_path": path,
"resolved_sha1": sha1_by_path.get(path, "") if path else "",
"layer": "platform",
"platform_id": key,
"platform": coverage["platform"],
"emulator": "",
"system": detail.get("system", ""),
"name": detail.get("name", ""),
"status": detail.get("status", ""),
"required": bool(detail.get("required", True)),
"in_repo": "",
"reason": detail.get("reason", ""),
"discrepancy": detail.get("discrepancy", ""),
"destination": detail.get("destination", ""),
"expected": "",
})
for emu_key, data in sorted((gap_report or {}).items()):
systems = ";".join(str(s) for s in data.get("systems", []) or [])
categories = _profile_categories((profiles or {}).get(emu_key) or {})
rows.extend({
"category": categories.get(
(gap.get("name", ""), gap.get("path") or gap.get("name", "")), ""),
"collection_path": "",
"resolved_sha1": "",
"layer": "emulator",
"platform_id": "",
"platform": "",
"emulator": data.get("emulator", emu_key),
"system": systems,
"name": gap.get("name", ""),
# A file the emulator's own package installs is not one to
# find: its own status, as unsourceable has.
"status": (
"bundled" if gap.get("bundled") and gap.get("source") == "missing"
else gap.get("source", "")
),
"required": bool(gap.get("required", False)),
"in_repo": bool(gap.get("in_repo", False)),
"reason": gap.get("note", ""),
"discrepancy": "",
# What a contributor needs to supply the right revision and
# put it in the right place: the gaps table gave neither.
"destination": gap.get("path") or gap.get("name", ""),
"expected": gap.get("identity", ""),
} for gap in data.get("gap_details", []) or [])
rows.extend({
"category": categories.get(
(entry.get("name", ""), entry.get("path") or entry.get("name", "")), ""),
"collection_path": "",
"resolved_sha1": "",
"layer": "emulator",
"platform_id": "",
"platform": "",
"emulator": data.get("emulator", emu_key),
"system": systems,
"name": entry.get("name", ""),
"status": "unsourceable",
"required": bool(entry.get("required", False)),
"in_repo": False,
"reason": entry.get("reason", ""),
"discrepancy": "",
"destination": entry.get("path") or entry.get("name", ""),
"expected": "",
} for entry in data.get("unsourceable", []) or [])
# Two declarations that differ only in what the row does not carry are
# one row: AmberELEC's hardwareconfig.xml was printed twice.
unique: dict[tuple, dict] = {}
for row in rows:
unique.setdefault(tuple(sorted((k, str(v)) for k, v in row.items())), row)
return list(unique.values())
def _profile_categories(profile: dict) -> dict[tuple[str, str], str]:
"""(name, path) -> the category a profile gives the entry, bios by default."""
found: dict[tuple[str, str], str] = {}
for entry in profile.get("files") or []:
if isinstance(entry, dict) and entry.get("name"):
name = str(entry["name"])
found.setdefault((name, str(entry.get("path") or name)),
str(entry.get("category") or "bios"))
return found
def _cross_reference_export_rows(coverages: dict, profiles: dict) -> list[dict]:
from resolve.cores import resolve_platform_cores
unique = {
key: value
for key, value in profiles.items()
if value.get("type") != "alias" and value.get("role") != "test"
}
rows: list[dict] = []
for platform_id, coverage in sorted(coverages.items()):
for profile_id in sorted(resolve_platform_cores(coverage["config"], unique)):
profile = unique[profile_id]
cores = profile.get("cores") or [profile_id]
systems = profile.get("systems") or [""]
for core in cores:
rows.extend({
"platform_id": platform_id,
"platform": coverage["platform"],
"profile_id": profile_id,
"emulator": profile.get("emulator", profile_id),
"core": core,
"system": system,
"classification": profile.get("core_classification", ""),
"type": profile.get("type", ""),
"source": _json_text(profile.get("source")),
"upstream": _json_text(profile.get("upstream")),
"profiled_commit": _json_text(profile.get("source_commit", "")),
"file_count": len(profile.get("files", []) or []),
} for system in systems)
return rows
def _write_sqlite_export(
destination: Path,
db: dict,
platform_items: list[dict],
platform_files: list[dict],
emulator_items: list[dict],
gap_rows: list[dict],
) -> None:
"""Build a queryable, deterministic snapshot without embedding binaries."""
temp_dir = Path("tmp") / "site"
temp_dir.mkdir(parents=True, exist_ok=True)
temp_path = temp_dir / f"retrobios-{os.getpid()}.sqlite"
temp_path.unlink(missing_ok=True)
destination.parent.mkdir(parents=True, exist_ok=True)
connection = sqlite3.connect(temp_path)
try:
connection.executescript("""
PRAGMA journal_mode = OFF;
PRAGMA synchronous = OFF;
CREATE TABLE metadata (key TEXT PRIMARY KEY, value TEXT NOT NULL);
CREATE TABLE files (
sha1 TEXT PRIMARY KEY, path TEXT NOT NULL, name TEXT NOT NULL,
size INTEGER NOT NULL, md5 TEXT NOT NULL, sha256 TEXT NOT NULL,
crc32 TEXT NOT NULL, adler32 TEXT NOT NULL
);
CREATE TABLE file_provenance (
sha1 TEXT NOT NULL, catalog TEXT NOT NULL, details_json TEXT NOT NULL,
PRIMARY KEY (sha1, catalog),
FOREIGN KEY (sha1) REFERENCES files(sha1)
);
CREATE TABLE platforms (
id TEXT PRIMARY KEY, name TEXT NOT NULL, total INTEGER NOT NULL,
present INTEGER NOT NULL, verified INTEGER NOT NULL,
missing INTEGER NOT NULL, contract_json TEXT NOT NULL
);
CREATE TABLE platform_files (
platform_id TEXT NOT NULL, system TEXT NOT NULL, name TEXT NOT NULL,
destination TEXT NOT NULL, required INTEGER NOT NULL,
region TEXT, selection_slot TEXT, size INTEGER,
sha1 TEXT, sha256 TEXT, md5 TEXT, crc32 TEXT,
status TEXT, category TEXT, collection_path TEXT, resolved_sha1 TEXT,
zipped_file TEXT, hash_match_mandatory INTEGER, mandatory_declared INTEGER,
curated INTEGER, shared_group TEXT, mirror_of TEXT, zip_digest TEXT
);
CREATE TABLE emulators (
id TEXT PRIMARY KEY, name TEXT NOT NULL, type TEXT,
classification TEXT, source TEXT, upstream TEXT,
source_commit TEXT, profile_json TEXT NOT NULL
);
CREATE TABLE emulator_systems (
emulator_id TEXT NOT NULL, system TEXT NOT NULL,
PRIMARY KEY (emulator_id, system)
);
CREATE TABLE emulator_files (
emulator_id TEXT NOT NULL, system TEXT, name TEXT NOT NULL,
path TEXT, required INTEGER NOT NULL, mode TEXT, region TEXT,
size TEXT, sha1 TEXT, sha256 TEXT, md5 TEXT, crc32 TEXT,
source_ref TEXT
);
CREATE TABLE gaps (
layer TEXT NOT NULL, platform_id TEXT, platform TEXT,
emulator TEXT, system TEXT, name TEXT NOT NULL,
status TEXT NOT NULL, required INTEGER NOT NULL,
in_repo TEXT, reason TEXT, discrepancy TEXT,
destination TEXT, expected TEXT, category TEXT,
collection_path TEXT, resolved_sha1 TEXT
);
CREATE TABLE accepted_hashes (
layer TEXT NOT NULL, owner TEXT NOT NULL, system TEXT,
name TEXT NOT NULL, path TEXT, algorithm TEXT NOT NULL,
value TEXT NOT NULL
);
CREATE INDEX accepted_hashes_value_idx ON accepted_hashes(algorithm, value);
CREATE INDEX files_name_idx ON files(name);
CREATE INDEX files_md5_idx ON files(md5);
CREATE INDEX files_sha256_idx ON files(sha256);
CREATE INDEX platform_files_name_idx ON platform_files(name);
CREATE INDEX emulator_files_name_idx ON emulator_files(name);
CREATE INDEX gaps_status_idx ON gaps(layer, status);
""")
commit = _source_commit()
metadata = {
"schema_version": "1",
"generated_at": str(db.get("generated_at") or _timestamp()),
**({"commit": commit} if commit else {}),
"source": REPO_URL,
"scope": "metadata only, no BIOS or firmware payload bytes",
"license": DATA_LICENSE,
}
connection.executemany(
"INSERT INTO metadata(key, value) VALUES (?, ?)",
sorted(metadata.items()),
)
for sha1, entry in sorted(db.get("files", {}).items()):
connection.execute(
"INSERT INTO files VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(
sha1, entry.get("path", ""), entry.get("name", ""),
entry.get("size", 0), entry.get("md5", ""),
entry.get("sha256", ""), entry.get("crc32", ""),
entry.get("adler32", ""),
),
)
for catalog, details in sorted((entry.get("provenance") or {}).items()):
connection.execute(
"INSERT INTO file_provenance VALUES (?, ?, ?)",
(sha1, catalog, _json_text(details)),
)
for item in platform_items:
coverage = item["coverage"]
connection.execute(
"INSERT INTO platforms VALUES (?, ?, ?, ?, ?, ?, ?)",
(
item["id"], item["name"], coverage.get("total", 0),
coverage.get("present", 0), coverage.get("verified", 0),
coverage.get("missing", 0), _json_text(item["contract"]),
),
)
connection.executemany(
"INSERT INTO platform_files VALUES "
"(:platform_id, :system, :name, :destination, :required, :region, "
":selection_slot, :size, :sha1, :sha256, :md5, :crc32, :status, :category, "
":collection_path, :resolved_sha1, :zipped_file, :hash_match_mandatory, "
":mandatory_declared, :curated, :shared_group, :mirror_of, :zip_digest)",
platform_files,
)
for item in emulator_items:
profile = item["profile"]
connection.execute(
"INSERT INTO emulators VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(
item["id"], profile.get("emulator", item["id"]),
profile.get("type", ""),
profile.get("core_classification", ""),
_json_text(profile.get("source")),
_json_text(profile.get("upstream")),
# source_commit is a string or, when the builds live in
# separate repositories, an object keyed by build mode.
# SQLite cannot bind the object form.
_json_text(profile.get("source_commit", "")),
_json_text(profile),
),
)
for system in sorted(set(profile.get("systems", []) or [])):
connection.execute(
"INSERT INTO emulator_systems VALUES (?, ?)",
(item["id"], system),
)
for entry in profile.get("files", []) or []:
connection.execute(
"INSERT INTO emulator_files VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
(
item["id"], _json_text(entry.get("system")),
entry.get("name", ""), entry.get("path", ""),
int(bool(entry.get("required", False))),
entry.get("mode", ""), _json_text(entry.get("region")),
_json_text(entry.get("size")), _json_text(entry.get("sha1")),
_json_text(entry.get("sha256")), _json_text(entry.get("md5")),
_json_text(entry.get("crc32")),
_json_text(entry.get("source_ref")),
),
)
connection.executemany(
"INSERT INTO accepted_hashes VALUES "
"(:layer, :owner, :system, :name, :path, :algorithm, :value)",
_accepted_hash_rows(platform_files, emulator_items),
)
connection.executemany(
"INSERT INTO gaps VALUES "
"(:layer, :platform_id, :platform, :emulator, :system, :name, "
":status, :required, :in_repo, :reason, :discrepancy, :destination, :expected, "
":category, :collection_path, :resolved_sha1)",
gap_rows,
)
connection.commit()
connection.execute("VACUUM")
finally:
connection.close()
os.replace(temp_path, destination)
def write_single_item(
path: Path, kind: str, item: dict, generated_at: str, commit: str = "",
) -> None:
"""One item in the envelope of its collection, for a page to link."""
path.parent.mkdir(parents=True, exist_ok=True)
write_if_changed(
str(path),
json.dumps(
{"schema_version": 1, "generated_at": generated_at,
**({"commit": commit} if commit else {}), "kind": kind,
"count": 1, "items": [item]},
indent=2, sort_keys=True, ensure_ascii=False, default=str,
) + "\n",
)
def system_export_item(slug: str, manufacturer: str, consoles: dict[str, list]) -> dict:
"""A system page's files by console, with the hashes its cards show."""
fields = ("name", "path", "size", "sha1", "md5", "sha256", "crc32")
return {
"id": slug,
"name": manufacturer,
"consoles": {
console: [
{field: entry[field] for field in fields if entry.get(field) is not None}
for entry in sorted(entries, key=lambda e: (e.get("name", ""), e.get("sha1", "")))
]
for console, entries in sorted(consoles.items())
},
}
@functools.lru_cache(maxsize=1)
def _source_commit() -> str:
"""The commit of the checkout the site is built from, empty outside one."""
import subprocess
try:
result = subprocess.run(
["git", "rev-parse", "HEAD"], cwd=_REPO_ROOT,
capture_output=True, text=True, check=True,
)
except (OSError, subprocess.CalledProcessError) as error:
print(f" no commit recorded in the exports: {error}", file=sys.stderr)
return ""
commit = result.stdout.strip()
return commit if re.fullmatch(r"[0-9a-f]{40}", commit) else ""
# One row per dump a catalog describes and the collection lacks: the list
# the provenance page publishes under "Wanted".
WANTED_FIELDS = ("catalog", "dat", "name", "description", "size", "crc32", "md5", "sha1")
def _provenance_wanted_rows(db: dict) -> list[dict]:
"""The Wanted list of the provenance page, as rows. A dump the
collection already produces (derivable.json) is not wanted."""
derivable = load_derivable()
rows: list[dict] = []
for catalog, data in build_report(db, load_provenance_snapshots()).items():
for entry in data["missing"]:
if (entry.get("sha1") or "").lower() in derivable:
continue
rows.extend({
"catalog": catalog, "dat": dat,
**{f: _json_text(entry.get(f)) for f in WANTED_FIELDS[2:]},
} for dat in entry.get("dats") or [entry.get("dat", "")])
rows.sort(key=lambda r: (r["catalog"], r["dat"], r["name"], r["sha1"]))
return rows
def generate_data_exports(
docs: Path,
db: dict,
coverages: dict,
profiles: dict,
stats: dict,
gap_report: dict | None = None,
consumers: FileConsumers | None = None,
) -> list[dict]:
"""Create versioned static API, CSV and SQLite metadata snapshots."""
api = docs / "api" / "v1"
downloads = docs / "downloads"
schemas_dest = api / "schemas"
for directory in (api, downloads, schemas_dest):
directory.mkdir(parents=True, exist_ok=True)
generated_at = str(db.get("generated_at") or _timestamp())
# The revision the data was read at: a tool comparing two downloads
# could not tell which commit each came from.
commit = _source_commit()
stamp = {"commit": commit} if commit else {}
platform_items, platform_files = _platform_export_rows(coverages, db)
emulator_items = _emulator_export_items(profiles)
gap_rows = _gap_export_rows(coverages, gap_report, db, profiles)
cross_rows = _cross_reference_export_rows(coverages, profiles)
members = data_directory_members()
locations = file_location_items(db, profiles, members)
wanted = _provenance_wanted_rows(db)
envelopes = {
"platforms.json": ("platforms", platform_items),
"emulators.json": ("emulators", emulator_items),
"gaps.json": ("verification-and-coverage-gaps", gap_rows),
"file-locations.json": ("file-locations", locations),
}
write_lookup_shards(
api, file_lookup_records(db, coverages, profiles, locations, members, consumers,
model_retired.load(_REPO_ROOT / "retired.json"), wanted),
generated_at, commit,
)
for filename, (kind, items) in envelopes.items():
document = {
"schema_version": 1,
"generated_at": generated_at,
**stamp,
"kind": kind,
"count": len(items),
"items": items,
}
write_if_changed(
str(api / filename),
json.dumps(document, ensure_ascii=False, indent=2, sort_keys=True) + "\n",
)
# One platform without the others, as api/v1/emulators/<id>.json is one
# profile: platforms.json is 2.8 MB for twelve platforms.
for item in platform_items:
write_single_item(api / "platforms" / f"{item['id']}.json",
"platforms", item, generated_at, commit)
write_if_changed(str(api / "stats.json"), generate_stats(stats))
write_if_changed(
str(api / "database.json"),
json.dumps(db, ensure_ascii=False, indent=2) + "\n",
)
# Every schema the published files are written against, the manifests'
# too: an integrator had the platform's list and not what the pack writes.
for schema_path in sorted((_REPO_ROOT / "schemas").glob("*.schema.json")):
shutil.copy2(schema_path, schemas_dest / schema_path.name)
_record(schemas_dest / schema_path.name)
manifest_assets = _publish_manifests(api)
for filename, (kind, items) in {
"systems.json": ("system-index", system_index_items(db, coverages, profiles)),
"cores.json": ("core-index", core_index_items(profiles)),
}.items():
write_if_changed(str(api / filename), json.dumps({
"schema_version": 1, "generated_at": generated_at, **stamp,
"kind": kind, "count": len(items), "items": items,
}, ensure_ascii=False, indent=2, sort_keys=True) + "\n")
file_rows = []
for sha1, entry in sorted(db.get("files", {}).items()):
file_rows.append({
"sha1": sha1,
"path": entry.get("path", ""),
"name": entry.get("name", ""),
"size": entry.get("size", 0),
"md5": entry.get("md5", ""),
"sha256": entry.get("sha256", ""),
"crc32": entry.get("crc32", ""),
"adler32": entry.get("adler32", ""),
"provenance_catalogs": ";".join(
sorted((entry.get("provenance") or {}).keys())
),
})
write_if_changed(str(downloads / "retrobios.dat"), collection_dat(db, generated_at))
platform_dats = _write_platform_dats(downloads / "dat", db, members, generated_at)
write_if_changed(
str(downloads / "files.csv"),
_csv_document(
[
"sha1", "path", "name", "size", "md5", "sha256",
"crc32", "adler32", "provenance_catalogs",
],
file_rows,
),
)
write_if_changed(
str(downloads / "platform-files.csv"),
_csv_document(
[
"platform_id", "platform", "system", "name", "destination",
"required", "region", "selection_slot", "size", "sha1",
"sha256", "md5", "crc32", "status", "category",
"collection_path", "resolved_sha1", *ENTRY_EXPORT_FIELDS,
],
platform_files,
),
)
write_if_changed(
str(downloads / "cross-reference.csv"),
_csv_document(
[
"platform_id", "platform", "profile_id", "emulator", "core",
"system", "classification", "type", "source", "upstream",
"profiled_commit", "file_count",
],
cross_rows,
),
)
write_if_changed(
str(downloads / "gaps.csv"),
_csv_document(
[
"layer", "platform_id", "platform", "emulator", "system",
"name", "status", "required", "in_repo", "reason",
"discrepancy", "destination", "expected", "category",
"collection_path", "resolved_sha1",
],
gap_rows,
),
)
write_if_changed(
str(downloads / "accepted-hashes.csv"),
_csv_document(
["layer", "owner", "system", "name", "path", "algorithm", "value"],
_accepted_hash_rows(platform_files, emulator_items),
),
)
_write_sqlite_export(
downloads / "retrobios.sqlite", db, platform_items, platform_files,
emulator_items, gap_rows,
)
_record(downloads / "retrobios.sqlite")
write_if_changed(
str(downloads / "provenance-wanted.csv"),
_csv_document(list(WANTED_FIELDS), wanted),
)
assets = [
(api / "database.json", "Content database", "application/json", "schemas/database.schema.json"),
(api / "platforms.json", "Platform contracts", "application/json", "schemas/site-api-envelope.schema.json"),
(api / "emulators.json", "Emulator profiles", "application/json", "schemas/site-api-envelope.schema.json"),
(api / "gaps.json", "Verification and coverage gaps", "application/json", "schemas/site-api-envelope.schema.json"),
(api / "file-locations.json", "Where each file's card is, by SHA1", "application/json", "schemas/site-api-envelope.schema.json"),
(api / "stats.json", "Project statistics", "application/json", "schemas/stats.schema.json"),
(api / "systems.json", "System ids, their names and sections", "application/json",
"schemas/site-api-envelope.schema.json"),
(api / "cores.json", "Core names and the profile each one is", "application/json",
"schemas/site-api-envelope.schema.json"),
*manifest_assets,
(downloads / "files.csv", "File hashes CSV", "text/csv", None),
(downloads / "retrobios.dat", "Collection DAT (Logiqx XML, for clrmamepro and RomVault)",
"application/xml", None),
*((path, f"Setup DAT: {path.stem}", "application/xml", None) for path in platform_dats),
(downloads / "platform-files.csv", "Platform declarations CSV", "text/csv", None),
(downloads / "cross-reference.csv", "Cross-reference CSV", "text/csv", None),
(downloads / "gaps.csv", "Verification and coverage gaps CSV", "text/csv", None),
(downloads / "accepted-hashes.csv", "Accepted hashes, one row per value", "text/csv", None),
(downloads / "provenance-wanted.csv", "Catalogued dumps the collection lacks", "text/csv", None),
(downloads / "retrobios.sqlite", "SQLite snapshot", "application/vnd.sqlite3", None),
*([(downloads / "measurements.sqlite", "Core probe measurements (SQLite)",
"application/vnd.sqlite3", None)]
if (downloads / "measurements.sqlite").is_file() else []),
]
catalog_items: list[dict] = []
published: list[dict] = []
for path, title, media_type, schema in assets:
relative = path.relative_to(docs).as_posix()
item = {
"title": title,
"url": relative,
"media_type": media_type,
"bytes": path.stat().st_size,
"sha256": _sha256_path(path),
}
if schema:
item["schema"] = schema
catalog_items.append(item)
# In the catalog both references resolve against the catalog's own
# URL, as RFC 3986 clients do: `url` was relative to the site root
# and `schema` to api/v1/, so no single base resolved both.
published.append({
**item,
"url": os.path.relpath(path, api).replace(os.sep, "/"),
})
catalog = {
"schema_version": 1,
"generated_at": generated_at,
**stamp,
"kind": "catalog",
"license": DATA_LICENSE,
"count": len(published),
"items": published,
}
write_if_changed(
str(api / "catalog.json"),
json.dumps(catalog, ensure_ascii=False, indent=2, sort_keys=True) + "\n",
)
# api/v1/ itself is a folder GitHub Pages answers with the 404 page: the
# entry point is a document of its own, naming where to start.
entry_points = [
{"title": "Catalog", "url": "catalog.json",
"description": "Each dataset, manifest, export and download with its size, "
"SHA256 and schema. The one-item documents of emulators/, "
"platforms/, systems/ and lookup/ are not listed."},
{"title": "System ids", "url": "systems.json",
"description": "Each system id with its name and the section holding its files."},
{"title": "Core names", "url": "cores.json",
"description": "Each core name and alias with the profile it designates."},
{"title": "Schemas", "url": "schemas/site-api-envelope.schema.json",
"description": "The envelope every JSON document of api/v1 shares."},
]
write_if_changed(str(api / "index.json"), json.dumps({
"schema_version": 1, "generated_at": generated_at, **stamp,
"kind": "index", "license": DATA_LICENSE,
"count": len(entry_points), "items": entry_points,
}, ensure_ascii=False, indent=2, sort_keys=True) + "\n")
return catalog_items
+449
View File
@@ -0,0 +1,449 @@
"""The data page: what the site serves, and the fields of each document."""
from __future__ import annotations
import json
import re
import urllib.request
from pathlib import Path
from model import siteinputs
from model.registry import load_platform_registry
from model.safeparse import yaml_load
from sitegen import markup, measurements as sitemeasurements
from sitegen.config import RELEASE_URL, REPO_URL, SITE_URL, _REPO_ROOT
from sitegen.render import _escape_tags, _fmt_size
def _is_manifest(item: dict) -> bool:
return item["url"].startswith("api/v1/manifests/")
def _is_target_list(item: dict) -> bool:
return item["url"].startswith("api/v1/targets/")
def _is_setup_dat(item: dict) -> bool:
return item["url"].startswith("downloads/dat/")
def _is_export_report(item: dict) -> bool:
return item["url"].startswith("api/v1/exports/")
def _served_schemas() -> list[tuple[str, str]]:
"""(file name, title) of every schema api/v1/schemas/ serves, from the folder
the export copies: the page linked 7 of 11."""
return [
(path.name, str(json.loads(path.read_text(encoding="utf-8")).get("title") or path.stem))
for path in sorted((_REPO_ROOT / "schemas").glob("*.schema.json"))
]
# A URL template written in prose (https://.../<ref>/<repo_path>): escaped,
# the autolinker made a link of it, &lt;ref> on screen and a 404 behind it.
_URL_TEMPLATE = re.compile(r"(?<!`)https?://[^\s`]*<[^\s`]*?(?=[.,;]?(?:\s|$))")
def _schema_field_rows(schema: dict, keys: tuple[str, ...]) -> list[str]:
"""One table row per field, its description read from the schema, so the
page and the published contract say the same thing. A URL template is
written as code."""
props = schema.get("properties") or {}
rows = []
for key in keys:
text = str((props.get(key) or {}).get("description") or "")
if text:
# Python before 3.12 refuses a backslash inside an f-string expression.
described = _escape_tags(_URL_TEMPLATE.sub(r"`\g<0>`", text))
rows.append(f"| `{key}` | {described} |")
return rows
def _other_fields(schema: dict, shown: tuple[str, ...]) -> list[str]:
"""The fields a short table leaves out, every one with its description."""
rest = tuple(key for key in schema.get("properties") or {} if key not in shown)
return ["| Field | Meaning |", "|-------|---------|", *_schema_field_rows(schema, rest)]
def _nested_fields(schema: dict, prefix: str = "") -> list[str]:
"""A table for every object below *schema*, at any depth, and one line
per code where a field lists its codes' meanings (enumDescriptions).
The top-level and `files` tables left 50 nested fields undescribed, all
of `omitted_files` among them: a tool could not say why a file was not
installed.
"""
lines: list[str] = []
for key, spec in (schema.get("properties") or {}).items():
path = f"{prefix}{key}"
codes = spec.get("enumDescriptions")
if codes:
lines.extend([f"Codes of `{path}`:", ""])
lines.extend(f"- `{code}`: {text}" for code, text in zip(spec["enum"], codes))
lines.append("")
for label, child, child_path in (
("Each entry of", spec.get("items"), f"{path}[]"),
("Each value of", spec.get("additionalProperties"), f"{path}{{}}"),
("Fields of", spec, path),
):
if not isinstance(child, dict) or not child.get("properties"):
continue
lines.extend([
f"{label} `{path}`:", "",
"| Field | Meaning |", "|-------|---------|",
*_schema_field_rows(child, tuple(child["properties"])), "",
])
lines.extend(_nested_fields(child, f"{child_path}."))
return lines
# The manifest fields an integrator reads first, in the order they matter.
MANIFEST_TOP_FIELDS = ("platform", "version", "base_destination", "files",
"omitted_files", "pack_files", "core_names", "system_cores")
MANIFEST_FILE_FIELDS = ("dest", "sha1", "size", "repo_path", "release_asset", "cores",
"systems", "category", "alternatives")
def _short_sha256(item: dict, catalog: str) -> str:
"""A digest cell that fits its column: 12 characters linking the catalog
that holds it, the whole value in the title. 64 characters pushed the
table to 932 px in a 720 px column."""
value = str(item["sha256"])
return f'<a href="{catalog}"><code title="{value}">{value[:12]}</code></a>'
def _platforms_without_a_list(platforms_dir: Path | None = None) -> list[str]:
"""The names of the platforms whose registry says they keep no list."""
platforms_dir = platforms_dir or siteinputs.current().platforms
names = []
for key, entry in sorted(load_platform_registry(str(platforms_dir)).items()):
if entry.get("native_list") != "none":
continue
config = platforms_dir / str(entry.get("config") or f"{key}.yml")
data = yaml_load(config.read_text(encoding="utf-8")) if config.is_file() else {}
names.append(str((data or {}).get("platform") or key))
return names
def _join_names(names: list[str]) -> str:
return names[0] if len(names) == 1 else ", ".join(names[:-1]) + f" and {names[-1]}"
def generate_data_page(exports: list[dict], measurements_sqlite: Path | None = None) -> str:
manifest_schema = json.loads(
(_REPO_ROOT / "schemas" / "install-manifest.schema.json").read_text(encoding="utf-8"))
snippet = (_REPO_ROOT / "scripts" / "check_platform_folder.py").read_text(encoding="utf-8")
manifests = [item for item in exports if _is_manifest(item)]
targets = [item for item in exports if _is_target_list(item)]
no_list = _platforms_without_a_list()
lines = [
"---",
"terms: manifest, schema, json schema, license, check a folder, "
"check bios folder script, rate limit, api",
"---",
"",
"# Data and API",
"",
"RetroBIOS publishes the same metadata used by its verifier, pack builder "
"and website as versioned static files. No account or API key is required.",
"",
" ".join([
markup.button("API catalog", "api/v1/catalog.json", primary=True),
markup.button("SQLite snapshot", "downloads/retrobios.sqlite"),
markup.button("Collection DAT", "downloads/retrobios.dat"),
]),
"",
f"**Licence:** the metadata is offered under the MIT terms of [LICENSE]({REPO_URL}/blob/main/LICENSE), "
"which cover the scripts, tooling, schemas, documentation and metadata. "
f"They never cover a BIOS or firmware file ([NOTICE]({REPO_URL}/blob/main/NOTICE)). "
"`catalog.json` and the SQLite `metadata` table carry the same `license`.",
"",
"## Stable JSON endpoints",
"",
"Start at [`api/v1/index.json`](api/v1/index.json): it names the catalog, "
"the two id indexes and the envelope schema.",
"",
"| Dataset | Endpoint | Schema | Size |",
"|---------|----------|--------|-----:|",
]
for item in exports:
if (item["media_type"] != "application/json" or _is_manifest(item)
or _is_target_list(item) or _is_export_report(item)):
continue
schema = (
f"[JSON Schema](api/v1/{item['schema']})"
if item.get("schema") else "-"
)
lines.append(
f"| {item['title']} | [`{item['url']}`]({item['url']}) | "
f"{schema} | {_fmt_size(item['bytes'])} |"
)
lines.extend([
"",
"Every envelope carries `schema_version`, `kind` and `commit`, the revision "
"of this repository the data was read at. Breaking changes use a new "
"URL prefix (`/api/v2/`), and fields may only be added compatibly within v1. "
"Each schema's `$id` is the address it is served at.",
"",
"Schemas:",
"",
*(f"- [`{name}`](api/v1/schemas/{name}): {title}" for name, title in _served_schemas()),
"",
"`database.json`, `stats.json`, `release.json` and the manifests are not "
"envelopes. Their revision is the `commit` of `catalog.json` that lists "
"their SHA256.",
"",
"One emulator profile without the whole list: "
"`api/v1/emulators/<id>.json`, the envelope of `emulators.json` holding "
"that one item, its `profile` valid against "
"[`emulator.schema.json`](api/v1/schemas/emulator.schema.json). Each "
"emulator page links its own. `api/v1/platforms/<id>.json` holds one "
"platform of `platforms.json`, its `contract` valid against "
"[`platform.schema.json`](api/v1/schemas/platform.schema.json) and its "
"`registry` the install and scraper settings beside the list. "
"`api/v1/systems/<slug>.json` holds the files of one system page by console. "
"Each platform and system page links its own.",
"",
"By id: [`systems.json`](api/v1/systems.json) gives each system id a platform "
"or a profile writes (`sony-playstation`) with its name, its manufacturer, the "
"`url` of the section holding its files, the `api` document of that section "
"and the files' SHA1. "
"[`cores.json`](api/v1/cores.json) gives each core name the buildbot or a "
"platform uses (`mednafen_psx`) the profile it designates (`beetle_psx`), "
"whose document is `api/v1/emulators/<profile>.json`. A name two profiles "
"claim (`pcsx2`) has one item per profile, and `preferred: true` marks the "
"one a platform list naming that core gets: the profile with that very id, "
"else the first id in alphabetical order.",
"",
"One hash without the whole list: `api/v1/lookup/<xx>.json`, where `<xx>` "
"is the first two characters of the hash in lowercase, holds every SHA1, "
"MD5, CRC32 and SHA256 starting with them. Each record names its `layer` "
"(the collection, a member of a collection archive, a file that left the "
"collection, a data directory, a platform's list or an emulator profile), "
"the file `name`, the `url` of the page that shows it and, "
"when one is known, the `system_name` the site gives its system. "
"[Find or check a file](files/index.md) reads it.",
"",
"`catalog.json` lists the datasets, manifests, exports and downloads. It "
"does not list these one-item documents, which hold no SHA256 of their own.",
"",
"In a browser, the SHA1 of a file the reader picks finds its records when "
"the collection holds that file. A list naming a file the collection lacks "
"is filed under its MD5 or CRC32 alone, and Web Crypto has no MD5: "
"that page computes MD5 and CRC32 in script and looks "
"up all four.",
"",
"```js",
"// The records of the file a reader picked, by its SHA1.",
"async function lookUp(file) {",
" const digest = await crypto.subtle.digest(\"SHA-1\", await file.arrayBuffer());",
" const sha1 = [...new Uint8Array(digest)]",
" .map((byte) => byte.toString(16).padStart(2, \"0\"))",
" .join(\"\");",
f" const base = \"{SITE_URL}api/v1/lookup/\";",
" const response = await fetch(`${base}${sha1.slice(0, 2)}.json`);",
" if (!response.ok) return [];",
" const shard = await response.json();",
" // layer: collection, archive-member, retired, data-directory, platform, emulator.",
" return shard.items.filter((item) => item.value === sha1);",
"}",
"```",
"",
"Two kinds of `url`:",
"",
"- In `catalog.json` and `index.json`, a `url` is relative to the document "
"holding it, as RFC 3986 resolves it.",
"- In the lookup shards, `file-locations.json` and `systems.json`, a `url` "
f"is site-absolute (`/retrobios/systems/sony/#...`). Prefix "
f"`{SITE_URL.removesuffix(urllib.parse.urlsplit(SITE_URL).path)}` for a full address.",
"",
"## Platform manifests",
"",
"A platform's list is what the setup checks. Its manifest is what the pack "
"installs: the list's files plus every file the setup's cores load. "
"`api/v1/manifests/<platform>.json` is the file `install.py` reads, byte "
"for byte, valid against "
"[`install-manifest.schema.json`](api/v1/schemas/install-manifest.schema.json). "
"[`api/v1/release.json`](api/v1/release.json) records the packs of the latest "
"release and the files each one holds.",
"",
"Manifests: " + ", ".join(
f"[{item['url'].rsplit('/', 1)[-1].removesuffix('.json')}]({item['url']})"
for item in manifests) + "." if manifests else "",
"",
"`api/v1/targets/<platform>.json` gives each hardware target of a platform "
"the cores it runs, valid against "
"[`target-manifest.schema.json`](api/v1/schemas/target-manifest.schema.json). "
"`install.py --target` reads the same file. Like the manifests, they are "
"copied byte for byte and are not envelopes.",
"",
"Target lists: " + ", ".join(
f"[{item['url'].rsplit('/', 1)[-1].removesuffix('.json')}]({item['url']})"
for item in targets) + "." if targets else "",
"",
"`api/v1/exports/<platform>.json` lists every change of a setup's "
"[updated file](exports.md), the report that page is written from, copied "
"byte for byte like the manifests.",
"",
"| Field | Meaning |",
"|-------|---------|",
*_schema_field_rows(manifest_schema, MANIFEST_TOP_FIELDS),
"",
"Each entry of `files`:",
"",
"| Field | Meaning |",
"|-------|---------|",
*_schema_field_rows(manifest_schema["$defs"]["file"], MANIFEST_FILE_FIELDS),
"",
*markup.details("note", "All fields", [
"The manifest:",
"",
*_other_fields(manifest_schema, MANIFEST_TOP_FIELDS),
"",
"Each entry of `files`:",
"",
*_other_fields(manifest_schema["$defs"]["file"], MANIFEST_FILE_FIELDS),
"",
*_nested_fields(manifest_schema),
*_nested_fields(manifest_schema["$defs"]["file"], "files[]."),
]),
"## Check a folder for one platform",
"",
"The job most tools come for: is this BIOS folder what the platform checks? "
"Read `api/v1/platforms/<id>.json` and apply the platform's own rules:",
"",
"- `verification_mode: existence`: a file at its `destination` passes.",
"- An entry with no hash in the mode's field is checked on presence too.",
"- `zipped_file` set: the md5 is that of this member inside the ZIP, never "
"the ZIP's. Member names compare casefolded. A ZIP declared once per member "
"appears once per member: Batocera lists 692 entries for 353 destinations.",
"- An md5 shorter than 32 characters (Batocera) compares by its prefix. "
"Recalbox writes several accepted md5 in one field, comma separated.",
"- `zip_digest: composite` (Recalbox): the md5 of a ZIP is that of its members "
"read in name order, never the archive's.",
"- An entry with no `destination` (EmuDeck) names no file: the system "
"passes when any file in the BIOS folder has one of its md5.",
"- `hash_rule: size_and_any_hash` (RomM) wants the size and any one hash. "
"The script below does not apply it.",
*([f"- {_join_names(no_list)} have no list of their own (`native_list: none`). "
"An empty list does not mean nothing is needed."] if no_list else []),
"",
"```python",
snippet.rstrip("\n"),
"```",
"",
"The script is [`scripts/check_platform_folder.py`]"
f"({REPO_URL}/blob/main/scripts/check_platform_folder.py). A test runs it "
"against the verifier on a sample folder, so the two give the same answer. "
"It exits 1 when a file is wrong or missing. For an unknown platform it "
"prints the known ones, and it names a folder that does not exist.",
"",
"`install.py --check` answers another question by default: whether the folder "
"holds what the pack installs, the manifest above. With `--declared-only`, or "
"from the `declared` event, `install.py --check` answers it too.",
"",
"## Bulk downloads",
"",
"| Export | Format | Size | SHA256 |",
"|--------|--------|-----:|--------|",
])
for item in exports:
if item["media_type"] == "application/json" or _is_setup_dat(item):
continue
lines.append(
f"| [{item['title']}]({item['url']}) | `{item['media_type']}` | "
f"{_fmt_size(item['bytes'])} | {_short_sha256(item, 'api/v1/catalog.json')} |"
)
lines.extend([
"",
"Each SHA256 is cut to 12 characters. Point at it for the whole value, or "
"read it in [`catalog.json`](api/v1/catalog.json).",
"",
"The DAT is Logiqx XML, the format clrmamepro and RomVault read: one game "
"per `bios/<Manufacturer>/<Console>/` folder of the collection, named "
"`Manufacturer\\Console` so the tools look in that subfolder, each file a "
"rom named by its path below that folder. It audits a copy of the "
"collection's `bios/` tree, or rebuilds that layout from a reader's own dumps.",
"",
"A setup's DAT, `downloads/dat/<platform>.dat`, describes its BIOS folder "
"once installed: one game named after the folder (`bios`, `system`), each "
"file a rom named by its place below it, as its manifest lists it. It audits "
"that folder with the same tools. Setup DATs: " + ", ".join(
f"[{item['url'].rsplit('/', 1)[-1].removesuffix('.dat')}]({item['url']})"
for item in exports if _is_setup_dat(item)) + ".",
"",
"The SQLite file contains indexed tables for content hashes, provenance "
"catalog matches, platform declarations, emulator profiles and current "
"gaps. It contains metadata only, never BIOS or firmware bytes.",
"",
"To find who accepts a hash, query `accepted_hashes` (or "
"`accepted-hashes.csv`): one lowercase row per accepted value, per "
"algorithm, for platform declarations and emulator profiles alike, "
"indexed on `(algorithm, value)`. A ROM inside a MAME or FBNeo set "
"has its own row, its `path` naming the archive and the member "
"(`nmk004.zip/nmk004.bin`). The hash columns of `platform_files` "
"and `emulator_files` keep each source's own form: a Recalbox md5 may "
"list several revisions separated by commas, and an emulator field "
"holding several accepted values is a JSON array.",
"",
"```sql",
"SELECT layer, owner, name FROM accepted_hashes",
"WHERE algorithm = 'md5' AND value = 'c87a52c277f7952b41c639fc7bf0a43b';",
"```",
"",
"The gaps dataset carries both layers behind one `layer` column: "
"`platform` rows are anomalies against a platform's own BIOS list, "
"`emulator` rows are files a profiled core loads that no platform "
"declares. The two answer different questions and are not comparable "
"totals. Each row is listed once.",
"",
"`platform-files.csv` and the gaps add what the check found: `status` "
"(`ok`, `untested`, `missing`), `category` (`bios`, `game_data`, "
"`unread`), and for a held file `collection_path` and `resolved_sha1`, "
"the collection file that answers the declaration. "
"`provenance-wanted.csv` is the Wanted list of [Dump provenance]"
"(provenance.md): each dump a catalog describes and the collection lacks.",
"",
"`platform-files.csv` and the `platform_files` table also carry the entry "
"fields a check needs:",
"",
"- `zipped_file` set: the md5 is the md5 of that member inside the ZIP.",
"- `zip_digest` is `composite` where the md5 of a ZIP covers its members.",
"- `hash_match_mandatory` and `mandatory_declared` are Recalbox's flags.",
"- `curated`, `shared_group` and `mirror_of` mark an entry the platform's "
"own file does not carry.",
"",
*(sitemeasurements.data_page_section(measurements_sqlite)
if measurements_sqlite and measurements_sqlite.is_file() else []),
"## Hosting, rate limits and caching",
"",
"- Static files on GitHub Pages, read with a plain GET. No key, no account.",
"- Any origin may read them (`Access-Control-Allow-Origin: *`), so a "
"browser tool can call them directly.",
"- Responses are cached for 10 minutes (`Cache-Control: max-age=600`). "
"Send the `ETag` back in `If-None-Match` to skip an unchanged download.",
"- GitHub may answer HTTP 429 to a client that sends too many requests, and "
"a Pages site has a soft limit of 100 GB of traffic a month ([GitHub Pages "
"limits](https://docs.github.com/en/pages/getting-started-with-github-pages/"
"github-pages-limits)). Fetch the one shard or document a question needs.",
"- The base is the project's address, "
f"`{SITE_URL}api/v1/`. Compare `commit` to know whether two downloads differ.",
"",
"## Semantics and limits",
"",
"Treat four questions separately: content identity (hashes), presence in "
"the collection, acceptance by a specific emulator, and catalog provenance. "
"One does not imply the others. In particular, presence, a matching dump "
"catalog, or emulator compatibility is not a statement about copyright, "
"ownership, or redistribution rights.",
"",
f"The data can be newer than the [latest published pack]({RELEASE_URL}). "
"A pack is published by hand, once every release check has passed.",
"",
"See the [data model](wiki/data-model.md), [verification modes]"
"(wiki/verification-modes.md), and [methodology](wiki/architecture.md) "
"before interpreting aggregate counts.",
"",
])
return "\n".join(lines)
+223
View File
@@ -0,0 +1,223 @@
"""Front matter, page levels and search weight given to every page."""
from __future__ import annotations
import functools
import re
import sys
import urllib.request
from pathlib import Path
import release_record
from model import siteinputs
from model.database import load_database
from sitegen import markup, measurements as sitemeasurements, starlight as sitestarlight
from sitegen.config import SITE_NAME, SITE_URL, _REPO_ROOT, yaml
from sitegen.descriptions import PAGE_DATA, _browser_title, _page_description, _page_title
from sitegen.diagrams import prepare_page, unresolved_images
from sitegen.render import WIKI_SRC_DIR
from sitegen.write import _undecorated, write_decorated
# Working notes kept under docs/ during development, never part of the site,
# and no generated page lives in a directory of these names.
LOCAL_NOTE_DIRS = ("plans", "specs")
# The funnel: who each page is written for, from someone who knows nothing
# (start) to someone adding to the project (contribute). The label sits above
# the title, and the search ranks the first two levels higher.
LEVELS = {
"start": "Start here",
"setup": "Setup guide",
"explore": "Details",
"reference": "Reference",
"contribute": "For contributors",
}
# How much the site search weighs the words of a page (Pagefind's
# data-pagefind-weight, 1 by default). Each value was measured on the
# queries of website/tools/search_gate.py.
# - Start here pages answer a beginner's words first.
# - A system page holds the file cards themselves: a file name finds its
# card before a guide that cites the name as an example.
# - A setup guide is found by its name (the page title weighs it).
# - A guide behind the first two levels (reference, options, contributing)
# names everything a reader types, and ranks after the page that answers.
# - A launcher, an alias or a frozen copy answers a name after the emulator.
# - A part of a split page (a console's files, 5 of 9) holds cards, each found
# by its own heading, and ranks after the page that answers the question.
SEARCH_WEIGHT = {"start": 10, "setup": 1.5, "reference": 0.5, "contribute": 0.5, "part": 0.5}
SYSTEM_PAGE_WEIGHT = 5
DEEP_GUIDE_WEIGHT = 0.5
SEARCH_DEMOTED: set[str] = set()
# A tool page a reader reaches by a task, not its name: "check my dump",
# "md5 check" found emulator pages and never the page that checks a file.
SEARCH_WEIGHT_OF_PAGE = {"files/index.md": 2}
DEMOTED_WEIGHT = 0.5
def search_weight(relative: Path, level: str) -> float | None:
"""The search weight of a page, None for the default. A part page
states its own in its front matter: search_weight(path, "part")."""
if level == "part":
return SEARCH_WEIGHT["part"]
if relative.as_posix() in SEARCH_WEIGHT_OF_PAGE:
return SEARCH_WEIGHT_OF_PAGE[relative.as_posix()]
if relative.as_posix() in SEARCH_DEMOTED:
return DEMOTED_WEIGHT
if relative.parts[0] == "systems":
return SYSTEM_PAGE_WEIGHT
if relative.parts[0] == "wiki" and level not in ("start", "setup"):
return DEEP_GUIDE_WEIGHT
return SEARCH_WEIGHT.get(level)
_REFERENCE_PAGES = {
"gaps.md", "cross-reference.md", "provenance.md", "exports.md", "data.md",
"files/index.md", "wiki/data-model.md", sitemeasurements.EXPLORER_PAGE,
}
def page_level(relative: Path) -> str:
"""The level of a generated page. A wiki page states its own."""
path = relative.as_posix()
if path in ("index.md", "which-pack.md"):
return "start"
if relative.parts[0] in ("platforms", release_record.GET_DIR):
return "setup"
if relative.parts[0] in ("systems", "emulators") or path == "explore.md":
return "explore"
if path in _REFERENCE_PAGES:
return "reference"
if path in ("contributing.md", "wanted.md"):
return "contribute"
return ""
def level_label(level: str) -> str:
"""The visible label of a level, plain text for the theme to style."""
return f'<span class="rb-level rb-level-{level}">{LEVELS[level]}</span>'
def _front_matter(markdown: str) -> dict:
"""The YAML front matter of a page, empty when it has none."""
if not markdown.startswith("---\n"):
return {}
end = markdown.find("\n---\n", 4)
if end == -1:
return {}
data = yaml.safe_load(markdown[4:end])
return data if isinstance(data, dict) else {}
@functools.cache
def _sha1_by_prefix(db_path: str) -> dict[str, str]:
return {sha1[:12]: sha1 for sha1 in load_database(db_path)["files"]}
def _cards_elsewhere(markdown: str) -> str:
"""A start line links each file to its card. A console split over part
pages keeps its cards on the parts, so a card this page does not hold
is reached by its permanent link instead."""
links = set(re.findall(r"\]\(#(sha1-[0-9a-f]{12})\)", markdown))
away = {ident for ident in links if f'id="{ident}"' not in markdown}
if not away:
return markdown
by_prefix = _sha1_by_prefix(str(siteinputs.current().db))
for ident in away:
full = by_prefix[ident.removeprefix("sha1-")]
markdown = markdown.replace(f"](#{ident})", f"]({markup.site_href(f'files/?sha1={full}')})")
return markdown
def decorate_markdown_pages(docs: Path) -> dict[str, str]:
"""Add per-page descriptions and machine-readable structured data.
Under Starlight each page is written in its final form (front matter,
site addresses, pinned heading ids) and the dates a page states are
returned by address, for the sitemap.
"""
lastmod: dict[str, str] = {}
terms = sitestarlight.glossary_terms(_REPO_ROOT / WIKI_SRC_DIR / "glossary.md")
# The console words of every system page, decorated or not: a console
# another page's words cover gets a search field of its own.
console_words: dict[str, set[str]] = {}
for path in sorted((docs / "systems").glob("*.md*")):
text = path.read_text(encoding="utf-8")
words = sitestarlight.page_console_words(_front_matter(text), text)
if words:
console_words[path.relative_to(docs).with_suffix("").as_posix()] = words
for path in sorted(docs.rglob("*.md")):
relative = path.relative_to(docs)
if any(part in LOCAL_NOTE_DIRS for part in relative.parts[:-1]):
continue
original = path.read_text(encoding="utf-8")
authored = _front_matter(original)
if "head" in authored:
# Written in its final form by an earlier pass and rewritten by
# nothing since: a second pass would find no title to read.
continue
markdown = _cards_elsewhere(prepare_page(original, relative))
for image_id in unresolved_images(markdown):
print(f" WARNING: {relative}: no diagram named {image_id!r}", file=sys.stderr)
stripped = _undecorated(markdown)
if stripped is not markdown:
markdown = stripped
elif authored:
# A wiki page states its own level: keep it, wrap the body.
markdown = markdown[markdown.find("\n---\n", 4) + 5:].lstrip("\n")
level = authored.get("level") or page_level(relative)
title = _page_title(markdown, relative)
browser_title = _browser_title(relative, title)
description = str(authored.get("description") or _page_description(markdown, relative, title))
if relative.name == "index.md":
page_path = "" if len(relative.parts) == 1 else "/".join(relative.parts[:-1]) + "/"
else:
page_path = relative.with_suffix("").as_posix() + "/"
# Encoded as mkdocs encodes the canonical link and the sitemap:
# idtech4a++ named .../idtech4a++/ here and .../idtech4a%2B%2B/ there.
canonical = urllib.parse.urljoin(SITE_URL, urllib.parse.quote(page_path))
schema_type = "WebSite" if relative.as_posix() == "index.md" else "TechArticle"
if relative.as_posix() == "data.md":
schema_type = "Dataset"
structured = {
"@context": "https://schema.org",
"@type": schema_type,
"name": title,
"description": description,
"url": canonical,
"isPartOf": {
"@type": "WebSite",
"name": SITE_NAME,
"url": SITE_URL,
},
**PAGE_DATA.get(relative.as_posix(), {}),
}
if schema_type == "WebSite":
# The home page is the site: named as the site, part of nothing.
structured["name"] = SITE_NAME
del structured["isPartOf"]
target, text = sitestarlight.render_page(
relative.as_posix(), markdown, sitestarlight.PageMeta(
level=level,
weight=search_weight(relative, level),
browser_title=browser_title,
description=description, structured=structured, terms=terms,
search=authored.get("search") != "exclude",
logo=str(authored.get("logo") or ""),
parent=authored.get("parent"),
authored=authored,
words_by_page=console_words,
),
)
write_decorated(docs / target, text)
# One file per page: a page that gained or lost its components
# changed extension, and the other one would claim its address.
stem = relative.with_suffix("").as_posix()
for suffix in (".md", ".mdx"):
if f"{stem}{suffix}" != target:
(docs / f"{stem}{suffix}").unlink(missing_ok=True)
if structured.get("dateModified"):
lastmod[sitestarlight.page_url(target)] = str(structured["dateModified"])
return lastmod
+309
View File
@@ -0,0 +1,309 @@
"""Page titles and descriptions, as search engines and link previews read them."""
from __future__ import annotations
import html
import re
from pathlib import Path
import release_record
from sitegen import measurements as sitemeasurements
from sitegen.config import SITE_NAME
def _page_title(markdown: str, path: Path) -> str:
match = re.search(r"^#\s+(.+?)\s*$", markdown, flags=re.MULTILINE)
if match:
title = re.sub(r"<[^>]+>", "", match.group(1))
return title.replace(f" - {SITE_NAME}", "").strip()
return path.stem.replace("-", " ").title()
def _browser_title(relative: Path, title: str) -> str:
"""Return a concise, unique browser/search title for a generated page."""
key = relative.as_posix()
index_titles = {
# Material appends " - RetroBIOS": the home title says what the site
# is, instead of "RetroBIOS - RetroBIOS".
"index.md": "BIOS and firmware packs for RetroArch, Batocera and more",
"platforms/index.md": "Setups",
"systems/index.md": "Systems",
"emulators/index.md": "Emulators",
"wiki/index.md": "Reference",
"explore.md": "Explore",
}
if key in index_titles:
return index_titles[key]
# A console page is filed with the parts of its manufacturer's page, and
# titled "Sega: Dreamcast". A part names its range of files.
part = key in PART_PAGES and (
not key.startswith("systems/") or ": " not in title
or re.search(r", part \d+ of \d+$", title))
if part:
return title
# The words a web search for a console or an emulator types: "dreamcast
# bios", "duckstation bios". The h1 and the sidebar keep the name.
if key.startswith("emulators/"):
has_files = PAGE_DATA.get(key, {}).get("hasPart") and key not in NOTHING_TO_FETCH
# Lexaloffle, QEMU and ScummVM name a system page too.
own = " emulator" if f"systems/{relative.name}" in PAGE_DATA else ""
return f"{title}{own} BIOS files" if has_files else f"{title} emulator"
if key.startswith("systems/"):
maker, _, console = title.partition(": ")
return f"{console} BIOS files ({maker})" if console else f"{title} BIOS files"
return title
_LINK_TEXT = r"(?:`[^`]*`|\[[^\]\[]*\]|[^\]\[])"
def _plain_markdown(text: str) -> str:
text = re.sub(r"<[^>]+>", " ", text)
# Link text may hold brackets: a code span or a No-Intro name such as
# `[BIOS] LaserActive PAC-N1 (Japan) (v1.02).bin` left the whole link,
# anchor included, in the Pioneer page's meta description.
text = re.sub(rf"!\[({_LINK_TEXT}*)\]\([^)]*\)", r"\1", text)
text = re.sub(rf"\[({_LINK_TEXT}+)\]\([^)]*\)", r"\1", text)
# Code spans keep their text whole: validate_schemas.py read
# validateschemas.py once every underscore was taken for emphasis.
pieces = re.split(r"(`[^`]*`)", text)
text = "".join(
piece.strip("`") if piece.startswith("`")
else re.sub(r"(?<!\w)_+|_+(?!\w)", "", re.sub(r"[*~]", "", piece))
for piece in pieces
)
return re.sub(r"\s+", " ", text).strip()
def _shorten(plain: str, limit: int = 157) -> str:
"""A description cut at a word, never inside one: six snippets ended
in "op..." or "Fo..."."""
if len(plain) <= limit:
return plain
cut = plain[: limit + 1].rsplit(" ", 1)[0] if " " in plain[:limit] else plain[:limit]
return cut.rstrip(" ,;:-(.") + "..."
def _page_description(markdown: str, relative: Path, title: str) -> str:
key = relative.as_posix()
specific = {
"index.md": "The BIOS files emulators need, for RetroArch, Batocera, EmuDeck and more: the folder they go in, one command that installs and checks them, and packs to download.",
"data.md": "Versioned RetroBIOS JSON API, CSV exports, SQLite snapshot, schemas, checksums and data interpretation guidance.",
"cross-reference.md": "Every emulator core each retrogaming platform runs, the systems it emulates and the upstream project it comes from.",
"gaps.md": "Current RetroBIOS verification gaps, platform-to-emulator divergences, missing files and documented source limitations.",
"exports.md": "Each platform's own BIOS list (System.dat, batocera-systems, es_bios.xml and the rest) with the hashes and files the emulator source code shows, offered to its maintainers.",
sitemeasurements.EXPLORER_PAGE: "The records of emulator cores run headless on demand, each with its claim, verdict, the BIOS it ran, method, computer and full record, filterable, and as SQLite.",
"provenance.md": "Hash-based comparison of RetroBIOS metadata with No-Intro, Redump and TOSEC catalog snapshots.",
"explore.md": "Systems, emulators and installer options to explore, with the figures of the BIOS collection.",
"which-pack.md": "Pick a device or setup and get its BIOS files: the folder they go in, one command that installs and checks them, or a ZIP pack to extract.",
"contributing.md": "Add a BIOS file the collection lacks from the browser, checked on arrival, or add a platform or an emulator profile.",
"wanted.md": "Every file the collection lacks, by system, each with its upload button to GitHub. Drop files on the page to learn if they are wanted.",
}
if key in specific:
return specific[key]
# What a search engine shows is the page's own first sentence: 707 pages
# shared five templates of level 3 words ("source-pinned", "provenance").
browser = _browser_title(relative, title)
held = re.search(r"\bThis part holds (.+?)\.(?: |$)", markdown, re.M)
if key in PART_PAGES and held:
return _shorten(f"{browser}. This part holds {_plain_markdown(held[1])}.", 155)
lead = _lead(markdown)
if key in PART_PAGES and re.search(r"\bpart \d+ of \d+", title):
# The parts of one list open on the same sentence.
first = _first_paragraph(lead) or _first_paragraph(markdown)
return _shorten(f"{title}. {first}", 155)
described = _section_description(markdown, relative, title, browser, lead)
if described is not None:
return described
first = _first_paragraph(lead, minimum=35)
questions = [_plain_markdown(re.sub(r"\s*\{[^}]*\}\s*$", "", heading))
for heading in re.findall(r"^## (.+\?)(?:[ \t]*\{[^}]*\})?[ \t]*$", markdown, re.M)]
if not first and len(questions) >= 3:
# A page of questions with no intro: its first paragraph is the
# answer to one of them ("Run the command with --dry-run").
return _shorten(f"{title}: {' '.join(questions)}", 155)
first = first or _first_paragraph(markdown, minimum=35)
if first:
return _shorten(first, 155)
return f"{title}: RetroBIOS source-traced retrogaming firmware reference."
def _section_description(markdown: str, relative: Path, title: str, browser: str,
lead: str) -> str | None:
"""The description of a download, system, emulator or platform page,
or None for a page of another section."""
key = relative.as_posix()
if key.startswith(f"{release_record.GET_DIR}/"):
size = re.search(r"^- (.+ to download\b.*?)\.?$", markdown, re.M)
if size:
return _shorten(f"{title}: the BIOS pack of this setup, {_plain_markdown(size[1])}. "
"The address stays the same and always gives the latest ZIP.", 155)
return _shorten(_first_paragraph(lead) or title, 155)
if key.startswith("systems/") and relative.stem != "index":
return _system_description(markdown, browser)
if key.startswith("emulators/") and relative.stem != "index":
return _emulator_description(markdown, key, title, _first_paragraph(lead))
if key.startswith("platforms/") and relative.stem != "index":
# The summary ends on a link to the platform's site, whose label
# alone was left: "A system for handhelds. ROCKNIX website."
summary = _first_paragraph(lead).removesuffix(f" {title} website.")
return _shorten(f"The BIOS files for {title}, the folder they go in and the "
f"command that installs them. {summary}", 155)
return None
def _lead(markdown: str) -> str:
"""The text a page opens with, before its first section, details
block or ignored section (the install box, the profile table)."""
return re.split(r"^(?:## |<details|<section)", markdown, maxsplit=1, flags=re.M)[0]
def _emulator_description(markdown: str, key: str, title: str, intro: str) -> str:
"""An emulator page by its intro sentence ("DuckStation emulates Sony
PlayStation. It picks the BIOS for the game's region: ..."), or by
its profile table when the profile names no system."""
notes = re.search(r"<summary>Technical notes</summary>\s*\n\n(.+?)(?:\n\n|$)", markdown, re.S)
if not intro and notes:
# An initial is no sentence end: hcl's read "open-source port of E."
sentence = re.split(r"(?<![\s(][A-Z]\.)(?<=\.)\s", _plain_markdown(notes[1]),
maxsplit=1)[0]
intro = f"{title}: {sentence[:1].lower()}{sentence[1:]}"
if not intro:
row = {name: _plain_markdown(value) for name, value in re.findall(
r"^\| (Type|Classification|Version) \| (.+?) \|$", markdown, re.M)}
kind = row.get("Classification") or row.get("Type") or "emulator"
# The cell goes on to say where the version is read: the intro
# keeps the version alone.
version = row.get("Version", "").split(", ")[0]
known = f", version {version}" if version and version[0].isdigit() else ""
intro = f"{title}: {kind.lower()}{known}."
elif title not in intro:
# "It reads 1 file": the profile names no system to open on.
intro = f"{title}: {intro[:1].lower()}{intro[1:]}"
if key in NOTHING_TO_FETCH:
return _shorten(f"{intro} Every file it reads comes with the app.", 155)
if PAGE_DATA.get(key, {}).get("hasPart"):
return _shorten(_files_snippet(markdown, key, title, intro), 155)
# An alias page sends the reader to the core whose files it shares.
if "uses the same firmware as" in intro:
return _shorten(intro, 155)
needs = "It needs no BIOS or firmware file."
if "\n## Data directories" in markdown:
needs = "It needs no BIOS or firmware file, only the data folders listed."
return _shorten(f"{intro} {needs}", 155)
def _files_snippet(markdown: str, key: str, title: str, intro: str) -> str:
"""The snippet of an emulator page with files to get.
A search for "gba_bios.bin" or "scph5500.bin" landed on a page described
as "It reads 4 files, none of them required": the names the reader typed
were not in the result, and fewer than 1 in 70 clicked. The longest
form that fits is kept: a snippet cut by "..." reads as unfinished.
"""
if " any region." in intro:
step = ("Download one from this page and put it in the folder it shows."
if re.search(r"^1\. Download ", _lead(markdown), re.M)
else "Where to get one and the folder it goes in.")
head = f"{intro.split(' any region.')[0]} any region."
forms = [f"{head} {step} Any file name works.", f"{head} {step}"]
return next((form for form in forms if len(form) <= 155), intro)
snippet = EMULATOR_SNIPPETS.get(key)
if not snippet or not snippet[1] or "It reads " not in intro:
return intro
system, names, required, noun = snippet
if required == 0:
need = "none required"
elif required == len(names):
need = "all required" if len(names) > 1 else "required"
else:
need = f"{required:,} required"
subject = f"{system} {noun} for {title}" if system else f"{title} {noun}"
tails = ["Where each goes, its hashes and one command that installs them."
if "Install this emulator's files" in markdown else "",
"Where each goes and its hashes.", "Where each goes."]
forms = []
for count in range(min(len(names), 4), 0, -1):
shown = (names if count == len(names)
else [*names[:count - 1], f"{len(names) - count + 1:,} more"])
head = f"{subject}: {_said_as_list(shown)}, {need}."
forms += [f"{head} {tail}" for tail in tails if tail] + [head]
return next((form for form in forms if len(form) <= 155), intro)
# Lines a page opens with that say where it sits, not what it holds.
_PLACE_LINES = ("Part of ", "This part holds ", "On a card, ")
def _first_paragraph(markdown: str, minimum: int = 1) -> str:
"""The first paragraph of prose of a page body, as plain text: no
heading, table, list, fence, admonition or HTML block, and none that
only says where the page sits."""
for paragraph in re.split(r"\n\s*\n", markdown):
stripped = paragraph.strip()
if (
not stripped
or stripped.startswith(("#", "|", "```", "???", ":::", "<", "- ", "* ", "import "))
):
continue
plain = _plain_markdown(stripped)
if plain.startswith(_PLACE_LINES):
continue
# A paragraph that ends on a colon introduces what follows: alone,
# it describes nothing ("One file needs no clone and no local setup:").
if len(plain) >= minimum and not plain.endswith(":"):
return plain
return ""
# Section headings of a system page that are not a console.
_NOT_A_CONSOLE = {"Next steps", "Files", "Other files"}
_CARD_TITLE = re.compile(r'class="rb-file-title"[^>]*><code>([^<]+)</code>')
def _system_description(markdown: str, browser: str) -> str:
"""A system page by what it holds: a manufacturer page by its consoles,
a console page by its "Start with" line, else by its first files."""
consoles = [
_plain_markdown(re.sub(r"\s*\{[^}]*\}\s*$", "", heading))
for heading in re.findall(r"^## (.+?)[ \t]*$", markdown, re.M)
]
consoles = [name for name in consoles if name and name not in _NOT_A_CONSOLE]
if len(consoles) > 1:
shown = consoles if len(consoles) <= 4 else consoles[:3] + [f"{len(consoles) - 3} more"]
return _shorten(f"{browser} for {_said_as_list(shown)}, one card per file with its "
"hashes and the emulators that read it.", 155)
start = re.search(r"^\*\*Start with\*\*(?P<line>.*)$(?P<list>(?:\n+- .*)*)", markdown, re.M)
if start:
# "Start with the files of your machine:" introduces one line per machine.
machines = [_plain_markdown(item) for item in re.findall(r"^- (.+)$", start["list"], re.M)]
text = _plain_markdown(start["line"]).lstrip(": ")
said = "; ".join(machines) if machines and text.endswith(":") else text
return _shorten(f"{browser}. Start with {said}", 155)
names = list(dict.fromkeys(html.unescape(name) for name in _CARD_TITLE.findall(markdown)))
if names:
shown = names if len(names) <= 3 else names[:3] + [f"{len(names) - 3} more"]
return _shorten(f"{browser}: {_said_as_list(shown)}, with their hashes and the "
"emulators that read them.", 155)
return _shorten(f"{browser}, one card per file with its hashes and the emulators "
"that read it.", 155)
# Structured data a page generator knows beyond its text, by page path
# relative to docs/: read by decorate_markdown_pages.
PAGE_DATA: dict[str, dict] = {}
# Emulator pages whose every file comes with the app: no "BIOS files" in
# their title, and their description says so (DaedalusX64, ZEsarUX).
NOTHING_TO_FETCH: set[str] = set()
# The first system, the file names, the count of required names and the
# word for them ("BIOS" or "files") of each emulator page, for its snippet.
EMULATOR_SNIPPETS: dict[str, tuple[str, list[str], int, str]] = {}
# Pages that hold part of a page too long for one (a console of a split
# manufacturer, a run of an emulator's cards), by path relative to docs/:
# their H1 already says what they are.
PART_PAGES: set[str] = set()
def _said_as_list(items: list[str]) -> str:
""""a, b and c"."""
return ", ".join(items[:-1]) + f" and {items[-1]}" if len(items) > 1 else "".join(items)
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+177
View File
@@ -0,0 +1,177 @@
"""The emulators index: every profile, by classification and system."""
from __future__ import annotations
from model.profiles import unique_emulator_profiles
from sitegen.emulatorcards import _named_system_link
def _content_check_ceiling(profiles: dict) -> str:
"""How far content checking can reach across every profiled entry."""
hashed = sized = neither = 0
for profile in unique_emulator_profiles(profiles).values():
for f in profile.get("files", []) or []:
if any(
f.get(k)
for k in ("md5", "sha1", "crc32", "sha256", "known_hash_adler32")
):
hashed += 1
elif any(f.get(k) for k in ("size", "min_size", "max_size")):
sized += 1
else:
neither += 1
total = hashed + sized + neither
if not total:
return ""
return (
f"Across every profiled entry, {hashed:,} of {total:,} "
f"({hashed / total * 100:.0f}%) carry a hash the code checks, "
f"{sized:,} ({sized / total * 100:.0f}%) only a size, and "
f"{neither:,} ({neither / total * 100:.0f}%) neither. That last share "
"is the ceiling of the method: where an emulator validates nothing, "
"reading its source establishes which file it loads, never whether "
"the content is the right dump. The provenance field answers that "
"other question, for the files a dump catalog indexes."
)
CLS_LABELS = {
"official_port": "Official ports",
"community_fork": "Community forks",
"pure_libretro": "Pure libretro",
"game_engine": "Game engines",
"enhanced_fork": "Enhanced forks",
"frozen_snapshot": "Frozen snapshots",
"embedded_hle": "Embedded HLE",
"launcher": "Launchers",
"unclassified": "Unclassified",
"other": "Other",
}
# The same classes said of one emulator: its page read "Classification:
# Official ports".
CLS_LABEL_ONE = {
"official_port": "Official port",
"community_fork": "Community fork",
"pure_libretro": "Pure libretro",
"game_engine": "Game engine",
"enhanced_fork": "Enhanced fork",
"frozen_snapshot": "Frozen snapshot",
"embedded_hle": "Embedded HLE",
"launcher": "Launcher",
"unclassified": "Unclassified",
"other": "Other",
}
INITIAL_DIGITS = "0 to 9"
def emulator_initial(display: str) -> str:
"""The letter an emulator is filed under, in the navigation and on the
index alike. A name that does not open on a letter goes under "0 to 9"."""
initial = display[:1].upper()
return initial if "A" <= initial <= "Z" else INITIAL_DIGITS
def generate_emulators_index(profiles: dict) -> str:
unique = {
k: v for k, v in profiles.items()
if v.get("type") != "alias" and v.get("role") != "test"
}
aliases = {k: v for k, v in profiles.items() if v.get("type") == "alias"}
by_class: dict[str, list[tuple[str, dict]]] = {}
for name in sorted(unique.keys()):
p = unique[name]
cls = p.get("core_classification", "other")
by_class.setdefault(cls, []).append((name, p))
total_files = sum(len(p.get("files", [])) for p in unique.values())
lines = [
"# Emulators",
"",
"Each page is one emulator: the files it reads, whether it starts games "
"without them, and the line of its source code that says so. The "
"kind says how a core relates to the emulator it comes from, which "
"tells how far its own files can differ.",
"",
f"**{len(unique):,}** emulator profiles, **{total_files:,}** files total, **{len(aliases):,}** aliases.",
"",
"| Kind | Count | Description |",
"|------|-------|-------------|",
]
cls_desc = {
"official_port": "The same authors keep the app and the RetroArch core",
"community_fork": "Ported to RetroArch by someone else",
"pure_libretro": "Built for RetroArch, no app of its own",
"game_engine": "Game engine reimplementation",
"enhanced_fork": "Fork with added features",
"frozen_snapshot": "Frozen at an old version",
"embedded_hle": "Needs no BIOS file: the emulator carries its own",
"launcher": "Launches an external emulator",
"other": "Unclassified",
}
cls_order = [
"official_port",
"community_fork",
"pure_libretro",
"game_engine",
"enhanced_fork",
"frozen_snapshot",
"embedded_hle",
"launcher",
"other",
]
for cls in cls_order:
entries = by_class.get(cls, [])
if not entries:
continue
label = CLS_LABELS.get(cls, cls)
desc = cls_desc.get(cls, "")
lines.append(f"| {label} | {len(entries)} | {desc} |")
lines.append("")
# One section per initial, the groups the navigation draws: its letter
# links land on the section of the same name.
by_initial: dict[str, list[tuple[str, dict]]] = {}
for name, p in unique.items():
by_initial.setdefault(emulator_initial(str(p.get("emulator", name))), []).append((name, p))
for initial in sorted(by_initial, key=lambda g: (g != INITIAL_DIGITS, g)):
lines.extend([
f"## {initial}",
"",
"| Emulator | Kind | Systems | Files |",
"|--------|------|---------|-------|",
])
entries = sorted(by_initial[initial], key=lambda e: str(e[1].get("emulator", e[0])).casefold())
for name, p in entries:
emu_name = p.get("emulator", name)
cls = p.get("core_classification", "other")
systems = list(dict.fromkeys(
_named_system_link(s, "../") for s in p.get("systems") or []))
files = p.get("files", [])
sys_str = ", ".join(systems[:3])
if len(systems) > 3:
sys_str += f" and {len(systems) - 3} more"
file_count = len(files)
file_str = f"{file_count:,}" if file_count else "-"
lines.append(f"| [{emu_name}]({name}.md) | {CLS_LABEL_ONE.get(cls, cls)} | {sys_str} | {file_str} |")
lines.append("")
if aliases:
lines.extend(["## Aliases", ""])
lines.append("| Core | Points to |")
lines.append("|------|-----------|")
for name in sorted(aliases.keys()):
parent = aliases[name].get(
"alias_of", aliases[name].get("bios_identical_to", "unknown")
)
lines.append(f"| {name} | [{parent}]({parent}.md) |")
lines.append("")
return "\n".join(lines) + "\n"
+146
View File
@@ -0,0 +1,146 @@
"""Profile and platform fields rendered as page text."""
from __future__ import annotations
import re
from collections.abc import Callable
from sitegen import markup
from sitegen.render import _escape_tags, _field_text, _render_yaml_value
from sitegen.sources import _source_ref_markdown, link_prose_citations
def search_excluded(lines: list[str]) -> list[str]:
"""Lines the site search leaves out, as a block of their own.
The browser downloads and indexes the whole search index before the
first result: hashes, link lists and install commands repeated on 600
pages made it 21 MB. Hashes are found by files/?hash=, names and prose
stay searchable.
A section, not a div: the search plugin compares elements by tag, so
the first div closed inside an excluded div (a code block's) ended the
exclusion and the rest of the block was indexed.
"""
return ["", markup.block_open("section", markup.search_exclude()), "",
*lines, "", "</section>", ""]
def _render_platform_details(profile: dict) -> list[str]:
"""The per-platform block, one level of nesting deep."""
lines: list[str] = []
platform_details = profile.get("platform_details")
if platform_details and isinstance(platform_details, dict):
body: list[str] = []
for pk, pv in platform_details.items():
if isinstance(pv, dict):
body.extend([f"- **{pk}:**", ""])
for sk, sv in pv.items():
body.append(f" - {sk}: {_detail_value(profile, sk, sv)}")
body.append("")
else:
body.append(f"- **{pk}:** {_detail_value(profile, pk, pv)}")
lines.extend(markup.details("info", "Platform details", body, opened=True))
return lines
def _detail_value(profile: dict, key: object, value: object) -> str:
"""A platform detail, its citations linked at the profile's pin."""
if key == "source_ref" and isinstance(value, (str, dict)):
return _source_ref_markdown(profile, value)
if isinstance(value, str):
return _escape_tags(link_prose_citations(profile, value))
return _plain_value(value)
def _plain_value(value: object) -> str:
"""A scalar or a list of scalars as a reader writes it, not as Python does."""
if isinstance(value, bool):
return "yes" if value else "no"
if value is None:
# A YAML null states that there is none, but Python's `None` read as a gap.
return "none"
if isinstance(value, (list, tuple)):
return ", ".join(_plain_value(item) for item in value)
return _escape_tags(str(value))
def _structured_field_text(profile: dict) -> Callable[[object, object], str]:
"""Scalars of a structured block, citations linked at the profile's pin.
The file entries and platform details linked their source_ref, and the
analysis and firmware blocks printed 186 of them as plain code.
"""
def text(key: object, value: object) -> str:
if key == "source_ref" and isinstance(value, str):
return _source_ref_markdown(profile, value)
if isinstance(value, str):
return link_prose_citations(profile, _field_text(key, value))
return _field_text(key, value)
return text
def _render_structured_blocks(profile: dict) -> list[str]:
"""Every remaining structured field, as a collapsible section."""
lines: list[str] = []
_structured_blocks = [
("analysis", "Source analysis"),
("memory_layout", "Memory layout"),
("regions", "Regions"),
("nvm_layout", "NVM layout"),
("model_kickstart_map", "Model kickstart map"),
("builtin_boot_roms", "Built-in boot ROMs"),
("common_bios_filenames", "Common BIOS filenames"),
("valid_bios_crc32", "Valid BIOS CRC32"),
("dev_flash", "dev_flash"),
("dev_flash2", "dev_flash2"),
("dev_flash3", "dev_flash3"),
("firmware_modules", "Firmware modules"),
("firmware_titles", "Firmware titles"),
("fallback_fonts", "Fallback fonts"),
("io_devices", "I/O devices"),
("partitions", "Partitions"),
("mlc_structure", "MLC structure"),
("machine_directories", "Machine directories"),
("machine_properties", "Machine properties"),
("whdload_kickstarts", "WHDLoad kickstarts"),
("bios_identical_to", "BIOS identical to"),
("pack_structure", "Pack structure"),
("firmware_version", "Firmware version"),
]
for field, label in _structured_blocks:
val = profile.get(field)
if val is None:
continue
body: list[str] = []
_render_yaml_value(body, val, indent=0,
field_text=_structured_field_text(profile))
# Closed: raw profile data, below the files (Cemu's firmware
# titles opened the page above them).
block = markup.details(
"abstract", label, [_escape_tags(line) for line in body])
# A block listing hashes is the lookup's, as a card's hash lines are:
# izapple2's ROM table put "md5" 59 times in the search, above the
# page that explains MD5 checks.
if any(re.search(r"\b[0-9a-f]{32,64}\b", line) for line in body):
block = search_excluded(block)
lines.extend(block)
return lines
def _hash_spans(value: str | list, copy: bool = False) -> str:
"""Each hash a profile accepts, in full, each with a copy button when
*copy*.
Cut to 12 characters with the rest in a title attribute, 208 hashes
that only a profile declares were out of reach of the site search: it
indexes text, and a pasted sha1 matched nothing.
"""
from core.hashing import parse_hash_list
return ", ".join(
markup.hash_value(v, copy) for v in parse_hash_list(value)
)
+968
View File
@@ -0,0 +1,968 @@
"""The gap analysis page: what each platform misses, and why."""
from __future__ import annotations
import dataclasses
import html
import re
from dataclasses import dataclass
from model.platforms import native_layer
from resolve.cores import resolve_platform_cores
from resolve.nativemode import check_label
from sitegen import markup, wanted as sitewanted
from sitegen.cards import _PROVENANCE_LABELS, _fetch_url
from sitegen.config import _date_line
from sitegen.crossref import _gap_sources
from sitegen.dataexports import build_emulator_gap_report
from sitegen.emulatorsindex import _content_check_ceiling
from sitegen.parts import _list_pages
from sitegen.render import _code, _count, _escape_tags
from sitegen.sources import _source_ref_markdown
# Contributing page
_ACCEPTED_RE = re.compile(r"\b(sha1|sha256|md5|crc32) mismatch: got \S+, accepted \[([^\]]*)\]")
def _held_accepted(discrepancy: str, db: dict | None) -> str:
"""Where the collection keeps a dump the emulator accepts, if it does.
The table printed the hash the emulator wants and stopped there, while
the collection held that exact dump for every one of the ten rows.
"""
match = _ACCEPTED_RE.search(discrepancy or "")
if not match or not db:
return ""
algo, accepted = match.group(1), match.group(2)
indexes = db.get("indexes", {})
for value in re.split(r"[\s,]+", accepted.lower()):
if algo == "sha1":
sha1 = value if value in db.get("files", {}) else None
else:
sha1 = indexes.get(f"by_{algo}", {}).get(value)
path = db.get("files", {}).get(sha1 or "", {}).get("path")
if path:
return path
return ""
_PROBLEM_HASHES = ("sha1", "md5", "sha256", "crc32")
def _declared_hashes(config: dict, detail: dict) -> dict[str, list[str]]:
"""The hashes the platform declares for a reported file, by algorithm.
The untested table said "declared hash contradicted by the local file"
and named neither: the reader could not look for the dump RetroDECK asks
for, nor report the difference.
"""
from core.hashing import parse_hash_list
system = (config.get("systems") or {}).get(detail.get("system", "")) or {}
for entry in system.get("files") or []:
if isinstance(entry, dict) and entry.get("name") == detail.get("name"):
return {
algo: parse_hash_list(entry.get(algo))
for algo in _PROBLEM_HASHES if parse_hash_list(entry.get(algo))
}
return {}
def _declared_destination(config: dict, detail: dict) -> str:
"""Where the platform's list puts a reported file, its name when the
entry names no folder."""
system = (config.get("systems") or {}).get(detail.get("system", "")) or {}
for entry in system.get("files") or []:
if isinstance(entry, dict) and entry.get("name") == detail.get("name"):
return str(entry.get("destination") or detail.get("name", ""))
return str(detail.get("name", ""))
def short_hash(value: str) -> str:
"""A hash in a table cell: its first 12 characters, the whole value in
the title. Full MD5 and SHA1 values pushed the gaps tables past the
column on every screen."""
value = str(value)
if len(value) <= 12:
return _code(value)
return f'<code title="{html.escape(value)}">{html.escape(value[:12])}</code>'
def _hash_cell(hashes: dict[str, list[str]]) -> str:
return "<br>".join(
f"{algo} " + ", ".join(short_hash(v) for v in values) for algo, values in hashes.items()
)
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()
}
def _reason_cell(text: str) -> str:
"""A reason in a gaps table, in the class that keeps its column readable."""
return f'<span class="rb-reason">{text}</span>' if text else "-"
def _copy_cell(path: str, algos: list[str], db: dict | None) -> str:
"""The file a path holds, with its hashes in the algorithms declared."""
if not path:
return "-"
record: dict = next(
(rec | {"sha1": sha1} for sha1, rec in (db or {}).get("files", {}).items()
if rec.get("path") == path),
{},
)
hashes = {algo: [str(record[algo]).lower()] for algo in algos if record.get(algo)}
shown = f"[{_code(path)}]({_fetch_url(path)})"
return f"{shown}<br>{_hash_cell(hashes)}" if hashes else shown
def _render_problem_files(
platform_problems: list, settled: list | None = None, db: dict | None = None,
missing_total: int | None = None,
) -> list[str]:
"""Files a platform declares that its own check then rejects.
Split out of generate_gap_analysis, which reached complexity 56. This
section is the one that stands alone: it reads platform_problems and
nothing else, where the sections around it share gap_report and the
resolved core list.
"""
lines: list[str] = []
# ---- Section 2: Problem files ----
missing_files: dict[str, dict] = {}
untested_files: dict[str, dict] = {}
mismatch_files: dict[str, dict] = {}
for p in platform_problems:
fname = p["name"]
if p["status"] == "missing":
entry = missing_files.setdefault(fname, {
"name": fname, "required": p["required"],
"platforms": [], "reason": p["reason"], "categories": set(),
"where": {},
})
entry["platforms"].append(p["platform"])
# The platform's entry for the file, and the folder it expects.
entry["where"].setdefault(
(p["platform"], p.get("platform_key", ""), p.get("system", "")), set(),
).add(p.get("destination") or fname)
entry["categories"].add(p.get("category", "bios"))
if p["required"]:
entry["required"] = True
elif p["status"] == "untested":
# Keyed by what is declared and what is held: two platforms
# asking two dumps under one name are two rows.
declared = p.get("declared") or {}
key = f"{fname}\0{sorted(declared.items())}\0{p.get('path', '')}"
entry = untested_files.setdefault(key, {
"name": fname, "required": p["required"],
"platforms": [], "reason": p["reason"],
"declared": declared, "path": p.get("path", ""),
})
entry["platforms"].append(p["platform"])
if p.get("discrepancy"):
entry = mismatch_files.setdefault(fname, {
"name": fname, "platforms": [],
"discrepancy": p["discrepancy"],
})
entry["platforms"].append(p["platform"])
total_problems = len(missing_files) + len(untested_files) + len(mismatch_files)
# One row per name: the page opened on "48 are missing", counted by
# destination, above a heading that said "10 files". Both are said.
names = _count(len(missing_files), "name")
missing_said = (f"{missing_total:,} missing under {names}"
if missing_total is not None else f"{len(missing_files)} missing")
if total_problems > 0:
lines.extend([
"## Problem files",
"",
f"{missing_said}, {len(untested_files)} untested, "
f"{len(mismatch_files)} discrepancy.",
"",
])
if missing_files:
lines.extend([
f'### Missing <span class="rb-badge rb-badge-danger">'
f"{_count(len(missing_files), 'name')}</span>",
"",
"Required is the platform's own flag. Category says what the "
"platform's emulators do with the file: `bios` is firmware they "
"load, `game_data` comes from a copy of the game, `unread` is "
"opened by none of them. Only a missing `bios` entry stops a "
"console from starting. A name a list declares in several "
"folders is one row. Each platform links to its entry, which "
"names the cores examined, and is followed by where its list "
"puts the file.",
"",
"| File | Category | Required | Platforms |",
"|------|----------|----------|-----------|",
])
for fname in sorted(missing_files):
f = missing_files[fname]
req = "yes" if f["required"] else "no"
plats = "; ".join(
(f"[{display}](platforms/{key}.md#{system.replace(' ', '-')})"
if key and system else display)
+ " " + ", ".join(_code(dest) for dest in sorted(dests))
for (display, key, system), dests in sorted(f["where"].items())
)
cats = f["categories"]
category = "bios" if "bios" in cats else ", ".join(sorted(cats))
lines.append(f"| `{fname}` | {category} | {req} | {plats} |")
lines.append("")
if untested_files:
lines.extend([
f'### Untested <span class="rb-badge rb-badge-warning">'
f"{_count(len(untested_files), 'file')}</span>",
"",
"Present, but not the expected hash. Declared is what the platform "
"asks for, the collection copy is what the path holds.",
"",
"| File | Platforms | Reason | Declared | Collection copy |",
"|------|----------|--------|----------|-----------------|",
])
for key in sorted(untested_files):
f = untested_files[key]
plats = ", ".join(sorted(set(f["platforms"])))
declared = f["declared"]
lines.append(
f"| {_code(f['name'])} | {plats} | {_reason_cell(f['reason'])} "
f"| {_hash_cell(declared) or '-'} "
f"| {_copy_cell(f['path'], list(declared) or ['md5'], db)} |"
)
lines.append("")
if mismatch_files:
lines.extend([
f'### Discrepancy <span class="rb-badge rb-badge-warning">'
f"{_count(len(mismatch_files), 'file')}</span>",
"",
"The platform's own check passes, but the emulator's size or "
"hash check fails. Each row names the check that fails.",
"",
"| File | Platforms | Discrepancy | Accepted dump in the collection |",
"|------|----------|-------------|-------------------|",
])
for fname in sorted(mismatch_files):
f = mismatch_files[fname]
plats = ", ".join(sorted(set(f["platforms"])))
held = _held_accepted(f["discrepancy"], db)
cell = f"[{_code(held)}]({_fetch_url(held)})" if held else "-"
lines.append(f"| `{fname}` | {plats} | {_reason_cell(f['discrepancy'])} | {cell} |")
lines.append("")
if settled:
lines.extend([
"### Other revisions of a held destination",
"",
"A platform can declare one path twice with different hashes. The "
"path holds the file one declaration accepts, so it is counted once, "
"as held. The other declaration cannot be met at the same time.",
"",
"| File | Platform | Status | Path held for system |",
"|------|----------|--------|--------------|",
])
lines.extend(
f"| {_code(p['name'])} | {_escape_tags(p['platform'])} | {p['status']} "
f"| {_code(p['held_by'])} |"
for p in sorted(settled, key=lambda row: (row["name"], row["platform"]))
)
lines.append("")
return lines
def _platform_lists_sentence(
total: int, verified: int, untested: int, missing: int,
not_firmware: dict[str, int] | None = None,
) -> str:
"""The platforms' own lists in one sentence, every count said.
Four tiles opened the page: "Verified (100%)" for 5,437 of 5,438 and
"Missing 0", above a table of red cells, on the page about what is
missing. The gaps are in the files the emulators load, and the sentence
says so. The missing count then read as missing firmware, while every
entry behind it was game data or a file no emulator opens: the split by
category is said with it.
"""
def _is(count: int) -> str:
return "is" if count == 1 else "are"
not_firmware = {k: v for k, v in (not_firmware or {}).items() if v}
parts = [f"{verified:,} {_is(verified)} held and pass the platform's own check"]
if untested:
parts.append(f"{untested:,} {_is(untested)} held but not verified "
"(listed under Untested below)")
parts.append(f"{missing:,} {_is(missing)} missing")
listed = ", ".join(parts[:-1]) + f" and {parts[-1]}"
split = ""
if missing and not_firmware:
labels = {"game_data": "game data",
"unread": "opened by none of the platform's emulators"}
firmware = missing - sum(not_firmware.values())
others = [
f"{count:,} {'is' if count == 1 else 'are'} {labels.get(category, category)}"
for category, count in sorted(not_firmware.items())
]
others_text = others[0] if len(others) == 1 else ", ".join(others[:-1]) + f" and {others[-1]}"
head = (f"None of the missing is firmware: {others_text}" if not firmware
else f"Of the missing, {firmware:,} {'is' if firmware == 1 else 'are'} "
f"firmware, {others_text}")
split = f" {head}. Only missing firmware stops a console from starting."
return (
f"Of the {total:,} files on the platforms' own BIOS lists, {listed}.{split} "
"The files the emulators load beyond those lists are counted per "
"platform in the table below."
)
def _missing_required_firmware(cov: dict) -> int:
"""Entries of a platform's list that are missing, required and firmware.
Only those stop a console from starting. Game data and files no core
opens are counted apart, and red on every short row carried no signal.
"""
return len({
(d.get("system", ""), d.get("name", "")) for d in cov.get("details") or []
if d.get("status") == "missing" and d.get("required", True)
and d.get("category", "bios") == "bios" and not d.get("settled_by")
})
def _ratio_cell(done: int, total: int, alarm: int = 0) -> str:
"""A held-over-needed cell: the numbers, a bar, and a badge only when
required firmware is missing."""
if not total:
return "-"
share = done / total * 100
cell = (f'<span class="rb-bar" style="--v:{share:.1f}%" aria-hidden="true"><span></span></span>'
f"{done:,}/{total:,}")
if alarm:
cell += f' <span class="rb-badge rb-badge-danger">{alarm:,} required missing</span>'
return cell
# GitHub's upload page for a folder of bios/: a browser upload by someone
# without write access lands on a fork and opens a pull request.
UPLOAD_URL = f"{sitewanted.UPLOAD_ROOT}bios"
# Rows of Files to source on one page: 601 on one page made a phone page
# 274,509 px long.
FILES_TO_SOURCE_PART = 100
def reading_platforms(emu_name: str, profile: dict, name: str,
configs: dict[str, dict]) -> set[str]:
"""Of the platforms running an emulator (name -> config), those whose
build of it reads the entry: BlastEm's cdbios.bin is read by the
standalone build only, and RetroBat hands that build other names."""
from resolve.standalone import platform_layouts, standalone_set
from resolve.validation import filter_files_by_mode, unread_on
return {
platform for platform, config in configs.items()
if any(f.get("name") == name and not unread_on(f, platform)
for view, standalone in platform_layouts(emu_name, profile, standalone_set(config))
for f in filter_files_by_mode(view.get("files") or [], standalone))
}
@dataclass
class _VerifyTally:
"""Verify results aggregated across all platforms."""
verified: int = 0
untested: int = 0
missing: int = 0
files: int = 0
not_firmware: dict[str, int] = dataclasses.field(default_factory=dict)
problems: list[dict] = dataclasses.field(default_factory=list)
settled: list[dict] = dataclasses.field(default_factory=list)
def _by_platform_name(coverages: dict) -> list[tuple[str, dict]]:
"""The coverages in the order of their display names."""
return sorted(coverages.items(), key=lambda x: x[1]["platform"])
def _problem_record(pname: str, cov: dict, d: dict) -> dict:
"""A detail of a platform's verify result that is not ok, as the
problem tables read it."""
return {
"platform": cov["platform"],
"platform_key": pname,
"name": d["name"],
"status": d["status"],
"required": d.get("required", True),
"category": d.get("category", "bios"),
"reason": d.get("reason", ""),
"discrepancy": d.get("discrepancy", ""),
"system": d.get("system", ""),
"declared": _declared_hashes(cov.get("config") or {}, d),
"destination": _declared_destination(cov.get("config") or {}, d),
"path": d.get("path") or "",
}
def _verify_tally(coverages: dict) -> _VerifyTally:
"""Section 1: aggregate verify results across all platforms."""
tally = _VerifyTally()
for pname, cov in _by_platform_name(coverages):
tally.verified += cov["verified"]
tally.untested += cov["untested"]
tally.missing += cov["missing"]
tally.files += cov["total"]
for category, count in (cov.get("missing_not_firmware") or {}).items():
tally.not_firmware[category] = tally.not_firmware.get(category, 0) + count
for d in cov["details"]:
if d.get("settled_by") and d["status"] != "ok":
# Its path holds another declaration's file: the headline,
# counted by destination, rightly leaves it out, and listing
# it under the same word made the page contradict itself.
tally.settled.append({
"platform": cov["platform"], "name": d["name"],
"status": d["status"], "held_by": d["settled_by"],
})
continue
if d["status"] != "ok" or d.get("discrepancy"):
tally.problems.append(_problem_record(pname, cov, d))
return tally
def _pack_content_rows(coverages: dict) -> list[str]:
"""One row a platform: its list and its emulators' files, held over needed."""
rows = []
for pname, cov in _by_platform_name(coverages):
display = cov["platform"]
core_total = (
cov["core_present"] + cov["core_missing"] + cov["core_unsourceable"]
)
rows.append(
f"| [{display}](platforms/{pname}.md) "
f"| {_ratio_cell(cov['present'], cov['total'], _missing_required_firmware(cov))} "
f"| {_ratio_cell(cov['core_present'], core_total)} "
f"| {check_label(cov['mode'], cov['config'].get('hash_rule'))} |"
)
return rows
def _corroboration_rows(coverages: dict) -> list[str]:
"""One row a platform: how much of its list the emulator code confirms."""
rows = []
for pname, cov in _by_platform_name(coverages):
gt = cov["ground_truth"]
if not gt.get("applicable", True):
prof_cell = gt_cell = "-"
elif gt["total"]:
prof_pct = f"{gt.get('with_profile', 0) / gt['total'] * 100:.0f}%"
prof_cell = f"{gt.get('with_profile', 0):,} ({prof_pct})"
gt_pct = f"{gt['with_validation'] / gt['total'] * 100:.0f}%"
gt_cell = f"{gt['with_validation']:,} ({gt_pct})"
else:
prof_cell = gt_cell = "0"
rows.append(
f"| [{cov['platform']}](platforms/{pname}.md) "
f"| {gt['total']:,} | {prof_cell} | {gt_cell} |"
)
return rows
def _divergence_rows(coverages: dict, registry: dict | None, profiles: dict, db: dict) -> list[str]:
"""Section 1b: platform lists vs emulator source, one row a platform."""
from resolve.truth import diff_platform_truth, generate_platform_truth
div_rows = []
for pname, cov in _by_platform_name(coverages):
truth_data = generate_platform_truth(
pname, cov["config"], (registry or {}).get(pname, {}), profiles, db
)
s = diff_platform_truth(truth_data, native_layer(cov["config"]))["summary"]
if s["systems_compared"] == 0:
div_rows.append(
f"| [{cov['platform']}](platforms/{pname}.md) | - | - | - | - |"
)
else:
div_rows.append(
f"| [{cov['platform']}](platforms/{pname}.md) "
f"| {s['total_missing']} "
f"| {s['total_extra_phantom'] + s['total_extra_unprofiled']} "
f"| {s['total_hash_mismatch']} "
f"| {s['total_required_mismatch']} |"
)
return div_rows
def _emulator_platforms(profiles: dict, coverages: dict) -> dict[str, set[str]]:
"""Each emulator with the platforms that run it."""
emu_to_platforms: dict[str, set[str]] = {}
unique_profiles = {
k: v
for k, v in profiles.items()
if v.get("type") != "alias" and v.get("role") != "test"
}
for pname in coverages:
config = coverages[pname]["config"]
matched = resolve_platform_cores(config, unique_profiles)
for emu_name in matched:
emu_to_platforms.setdefault(emu_name, set()).add(pname)
return emu_to_platforms
@dataclass
class _MissingFiles:
"""The files to find, one row each, and the entries they come from."""
rows: list[dict] = dataclasses.field(default_factory=list)
entries: int = 0
bundled: set[tuple[str, str]] = dataclasses.field(default_factory=set)
def _missing_files(emulator_gaps: list[tuple[str, dict]]) -> _MissingFiles:
"""One row per file to find: a name two emulators share is one file
only when both declare the same hash. Keyed by name alone, Fallout
2's master.dat vanished behind Fallout 1's, and the three Sonic
decompilations' Data.rsdk showed as one."""
found = _MissingFiles()
by_identity: dict[tuple[str, str], dict] = {}
for emu_name, data in emulator_gaps:
for g in data["gap_details"]:
if g["source"] != "missing":
continue
if g.get("bundled"):
# It arrives with the emulator's own package, which is
# why the collection documents it and does not hold it:
# asking readers to source it sent them after a file
# every install already has.
found.bundled.add((data["emulator"], g["name"]))
continue
found.entries += 1
key = (g["name"], g.get("identity") or f"emulator:{emu_name}")
row = by_identity.get(key)
if row is None:
row = by_identity[key] = {
"name": g["name"],
"path": g.get("path") or g["name"],
"identity": g.get("identity", ""),
"emulators": [data["emulator"]],
"emu_keys": [emu_name],
"required": g["required"],
"source_ref": g["source_ref"],
}
found.rows.append(row)
elif emu_name not in row["emu_keys"]:
row["emulators"].append(data["emulator"])
row["emu_keys"].append(emu_name)
row["required"] = row["required"] or g["required"]
return found
@dataclass(frozen=True)
class SourceListing:
"""Where the list of files to source goes. With ``moved``, the list goes
to pages of its own, keyed by stem: on the page it made 662 KB of HTML.
``placer`` gives each file to source the folder its upload goes to, the
one validate_pr asks for. Without it the link opens bios/."""
moved: dict[str, str] | None = None
placer: sitewanted.Placer | None = None
def _source_row(m: dict, profiles: dict, coverages: dict,
emu_to_platforms: dict[str, set[str]], placer: sitewanted.Placer | None) -> str:
"""The row of one file to source."""
plats = sorted(set().union(
*(reading_platforms(key, profiles[key], m["name"], {
p: coverages[p]["config"] for p in emu_to_platforms.get(key, set())
}) for key in m["emu_keys"])
))
plat_badges = (
" ".join(
f'<span class="rb-badge rb-badge-info">{p}</span>'
for p in plats
)
if plats
else "-"
)
req = "yes" if m["required"] else "no"
algorithm, _, value = m["identity"].partition(":")
expected = f"{algorithm} {short_hash(value)}" if value else "-"
destination = _code(m["path"]) if m["path"] != m["name"] else "-"
emulators = ", ".join(
f"[{_escape_tags(display)}](emulators/{key}.md)"
for display, key in zip(m["emulators"], m["emu_keys"])
)
owner = profiles[m["emu_keys"][0]]
declared = sitewanted.gap_entries(owner, m["name"], m["identity"], False)
folder = placer.folder(declared[0]) if placer and declared else ""
upload = sitewanted.upload_href(sitewanted.UPLOAD_ROOT, folder)
return (
f"| `{m['name']}` [Have it? Upload]({upload}) | {destination} | {expected} "
f"| {emulators} | {req} | {plat_badges} | "
f"{_source_ref_markdown(owner, m['source_ref'])} |"
)
def _source_counted(missing: _MissingFiles) -> str:
"""How many files there are to source, and the entries they come from."""
req_src = [m for m in missing.rows if m["required"]]
return (
f"{_count(len(missing.rows), 'file')}, {len(req_src)} required."
+ (
f" They come from {_count(missing.entries, 'entry', 'entries')}: a file "
"declared with the same hash at several places is listed once."
if missing.entries != len(missing.rows) else ""
)
)
def _source_table(counted: str, rows: list[str], moved: dict[str, str] | None) -> list[str]:
"""The table of files to source, on the page or on pages of its own."""
head = [
"| File | Destination | Expected | Emulator | Required | Affects platforms | Source ref |",
"|------|-------------|----------|----------|----------|------------------|-----------|",
]
if moved is None:
return [*head, *rows, ""]
where = _list_pages(
"gaps-files-to-source", "Files to source",
f"{counted} Each is a file an emulator loads that no platform lists and "
"the collection does not hold. Part of "
"[What the packs do not hold](gaps.md#files-to-source).",
head, [rows[i:i + FILES_TO_SOURCE_PART] for i in range(
0, len(rows), FILES_TO_SOURCE_PART)], moved, budget=1,
parent=("What the packs do not hold", "/gaps/"),
)
return [f"Listed on {where}.", ""]
def _bundled_note(bundled_rows: set[tuple[str, str]]) -> list[str]:
"""The files that arrive with their emulator, counted, not listed."""
if not bundled_rows:
return []
emulators = sorted({emulator for emulator, _name in bundled_rows})
return [
f"{len(bundled_rows)} further files arrive with their emulator's own "
f"package ({_escape_tags(', '.join(emulators))}): documented in the profile, not "
"collected, and not listed here.",
"",
]
def _undeclared_gaps(report_all: dict) -> tuple[dict[str, int], int, list[tuple[str, dict]]]:
"""The files emulators load that no platform lists: counts by source,
the total, and the emulators that have any."""
src_totals: dict[str, int] = {
"bios": 0, "data": 0, "large_file": 0, "bundled": 0, "missing": 0,
}
total_undeclared = 0
emulator_gaps = []
for emu_name, data in sorted(report_all.items()):
if data["gaps"] == 0:
continue
total_undeclared += data["gaps"]
for key, count in _gap_sources(data).items():
src_totals[key] += count
emulator_gaps.append((emu_name, data))
return src_totals, total_undeclared, emulator_gaps
def _complement_rows(emulator_gaps: list[tuple[str, dict]]) -> list[str]:
"""One row an emulator: its undeclared files by source."""
rows = []
for emu_name, data in sorted(emulator_gaps, key=lambda x: -x[1]["gaps"]):
display = data["emulator"]
sources = _gap_sources(data)
to_source = sources["missing"]
missing_str = (
f'<span class="rb-badge rb-badge-danger">{to_source}</span>'
if to_source > 0
else '<span class="rb-badge rb-badge-success">0</span>'
)
rows.append(
f"| [{display}](emulators/{emu_name}.md) "
f"| {data['gaps']} "
f"| {sources['bios']} "
f"| {sources['data']} "
f"| {sources['large_file']} "
f"| {sources['bundled']} "
f"| {missing_str} |"
)
return rows
def _complement_intro(src_totals: dict[str, int], total_undeclared: int,
emulator_gaps: list[tuple[str, dict]]) -> list[str]:
"""Section 3 up to its per-emulator table: what the emulators load
that no platform lists, and where those files come from."""
total_available = (
src_totals["bios"] + src_totals["data"] + src_totals["large_file"]
)
pct_available = (
f"{total_available / total_undeclared * 100:.0f}%"
if total_undeclared
else "0%"
)
return [
"## Files emulators load that no platform lists { #core-complement }",
"",
f"Files loaded by emulators but not declared by any platform. "
f"{total_undeclared:,} files across {_count(len(emulator_gaps), 'emulator')}, "
f"{total_available:,} available ({pct_available}), "
f"{src_totals['bundled']:,} installed with their emulator, "
f"{src_totals['missing']:,} to source.",
"",
"This counts every profiled emulator, including those no platform "
"ships yet, so it reaches past what the first table above counts: "
"it covers only the emulators each platform actually ships. "
"Whatever is not in the collection is an acquisition target, named "
"per emulator below.",
"",
"### Where the files come from",
"",
"| Source | Count | Description |",
"|--------|------:|-------------|",
f"| bios/ | {src_totals['bios']} | In repository (database.json) |",
f"| data/ | {src_totals['data']} | Data directories (buildbot, GitHub) |",
f"| release | {src_totals['large_file']} "
"| GitHub release assets (large files) |",
f"| bundled | {src_totals['bundled']} "
"| Installed with the emulator's own package, not collected |",
f"| missing | {src_totals['missing']} | Not available, needs sourcing |",
"",
"### Per emulator",
"",
"| Emulator | Undeclared | bios | data | release | Bundled | Missing |",
"|----------|----------:|-----:|-----:|--------:|--------:|--------:|",
*_complement_rows(emulator_gaps),
"",
]
def _not_collected_section(report_all: dict, profiles: dict, catalogued: dict | None) -> list[str]:
"""Section 4: files the collection does not hold yet (unsourceable)."""
all_unsourceable: list[dict] = [
{
"name": u["name"],
"emulator": data["emulator"],
"emu_key": emu_name,
"reason": u["reason"],
"source_ref": u.get("source_ref", ""),
}
for emu_name, data in sorted(report_all.items())
for u in data.get("unsourceable", [])
]
if not all_unsourceable:
return []
listed = _catalogued_needs(catalogued)
# The old heading's address still leads here.
lines = [
'<span id="acknowledged-gaps"></span>',
"",
"## 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.",
"",
"| File | Emulator | Reason | Source ref | Listed in |",
"|------|----------|--------|-----------|-----------|",
]
for u in sorted(all_unsourceable, key=lambda x: x["name"]):
where = listed.get((u["emu_key"], str(u["name"]).casefold()), [])
lines.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 '-'} |"
)
lines.append("")
return lines
_PACK_CONTENTS_NOTE = (
"Each fraction is what the pack has over what is needed, counting "
"required and optional files alike since both ship. The first column "
"is the BIOS list the platform publishes, counted by destination: a "
"path the list declares twice is one file to place. A red badge marks "
"a list that is short of required firmware. The second counts files its "
"emulators load that this list never mentions, found by reading their "
"source code, and it is often several times larger. What is short "
"is named in the sections below. That second "
"number is a floor, not a ceiling: an emulator that accepts any file "
"handed to it names none in its code, so nothing there can be counted. "
"Checked by is the test the platform runs on its own, replicated here "
"from its source code "
"([how each one works](wiki/verification-modes.md))."
)
_CORROBORATION_NOTE = (
"Both columns count the files on the platform's own BIOS list, the "
"same number as the first column of the table above. Documented in a "
"profile means an emulator profile, written from source, describes the "
"file. Content the code checks is stricter: the emulator verifies a "
"size or hash for it, and this tool repeats that check. The gap "
"between the two is "
"not a defect, it is what the emulator code does: many emulators load "
"a file without ever checking its content, and no amount of profiling "
"can invent a check the code does not perform. A dash means no "
"profiled emulator applies to the platform, whose own source is then "
"the only authority."
)
def _divergence_section(div_rows: list[str]) -> list[str]:
"""The platform lists vs emulator source table, with its legend."""
return [
"## Platform lists vs emulator source",
"",
"Platform file lists are scraped as-is from each upstream project. "
"Emulator profiles are read from source code. The two do not always "
"agree, and this table counts the differences. Packs follow the "
"platform contract, and these numbers show where that contract diverges "
"from what the code loads.",
"",
"| Platform | Missing from list | Not read by profiles | Hash conflict | Required status |",
"|----------|------------------:|--------:|--------------:|----------------:|",
*div_rows,
"",
"- **Missing from list**: a profiled emulator loads the file, the platform list does not mention it",
"- **Not read by profiles**: on the platform list, loaded by no emulator profiled so far (a profile may still be incomplete)",
"- **Hash conflict**: the platform list and the emulator source expect different hashes",
"- **Required status**: required/optional differs between list and code",
"",
"A dash means no profiled emulator overlaps the platform's systems, "
"so there is nothing to compare: the platform's own source is the "
"only authority for its files.",
"",
"The same comparison feeds the [updated platform files](exports.md): "
"each platform's own file, patched with these differences and kept "
"in its native format (System.dat, es_bios.xml, batocera-systems, ...).",
"",
]
def generate_gap_analysis(
profiles: dict,
coverages: dict,
db: dict,
data_names: set[str] | None = None,
registry: dict | None = None,
gap_report: dict | None = None,
listing: SourceListing | None = None,
catalogued: dict | None = None,
) -> str:
"""Generate a unified gap analysis page.
``listing`` says where the files to source go (SourceListing).
``catalogued`` is a provenance report built with the profiles' needs:
a file the collection does not hold yet names the catalog or romset
that lists it.
Combines verification results (from coverages/verify.py) with source
provenance (from cross_reference) into a single truth dashboard.
Sections:
1. Verification status, aggregated across all platforms
2. Problem files: missing, untested, hash mismatch
3. Core complement: emulator files not declared by any platform
"""
listing = listing or SourceListing()
tally = _verify_tally(coverages)
lines = [
"# What the packs do not hold",
"",
"What each pack still cannot give, and why. Most gaps are not "
"firmware: a platform's list can also name game files, such as "
"Diablo's `diabdat.mpq`, which comes from an owned copy of the game, or files "
"no emulator of that platform opens. Those are counted apart. A missing "
"firmware file means a console that does not start, and each one is "
"named below with the platforms that list it.",
"",
"Each file here is a request: for a file under \"Files to source\", "
"[adding it](contributing.md) fills the gap for "
"every platform at once. Have some of these? [Drop them on the wanted "
"page](wanted.md): it says which ones are wanted and where each goes.",
"",
" ".join([
markup.button("Download gaps CSV", "downloads/gaps.csv"),
markup.button("Open gaps API", "api/v1/gaps.json"),
markup.button("All data exports", "data.md"),
]),
"",
_platform_lists_sentence(
tally.files, tally.verified, tally.untested, tally.missing,
tally.not_firmware,
),
"",
]
# ---- Verification per platform ----
lines.extend([
"## What each pack contains",
"",
"| Platform | On its BIOS list (destinations) | Files its emulators load | Checked by |",
"|----------|-----------------:|-------------------------:|------------|",
*_pack_content_rows(coverages),
"",
_PACK_CONTENTS_NOTE,
"",
"## How much of each list the emulator code confirms { #corroboration-against-emulator-source }",
"",
"| Platform | On its BIOS list | Documented in a profile | Content the code checks |",
"|----------|-----------------:|------------------------:|------------------------:|",
*_corroboration_rows(coverages),
"",
_CORROBORATION_NOTE,
"",
_content_check_ceiling(profiles),
"",
])
lines.extend(_divergence_section(_divergence_rows(coverages, registry, profiles, db)))
lines.extend(_render_problem_files(tally.problems, tally.settled, db, tally.missing))
# ---- Section 3: Core complement (cross-reference provenance) ----
if gap_report is None:
gap_report = build_emulator_gap_report(profiles, coverages, db, data_names)
report_all = gap_report
src_totals, total_undeclared, emulator_gaps = _undeclared_gaps(report_all)
if total_undeclared > 0:
lines.extend(_complement_intro(src_totals, total_undeclared, emulator_gaps))
# List truly missing files with platform impact
emu_to_platforms = _emulator_platforms(profiles, coverages)
missing = _missing_files(emulator_gaps)
if missing.rows:
counted = _source_counted(missing)
rows = [
_source_row(m, profiles, coverages, emu_to_platforms, listing.placer)
for m in sorted(missing.rows, key=lambda x: (not x["required"], x["name"]))
]
lines.extend(["### Files to source", "", counted,
"[The wanted page](wanted.md) lists them, each with its upload button.", ""])
lines.extend(_source_table(counted, rows, listing.moved))
lines.extend(_bundled_note(missing.bundled))
lines.extend(_not_collected_section(report_all, profiles, catalogued))
lines.extend(["", _date_line()])
return "\n".join(lines) + "\n"
+152
View File
@@ -0,0 +1,152 @@
"""The download pages of each setup, and their index."""
from __future__ import annotations
import json
import re
import release_record
from model import siteinputs
from model.guides import DEVICE_GROUPS, GROUP_TILES, GUIDES, HANDHELD_GUIDE
from model.platforms import load_platform_config
from model.registry import load_platform_registry
from sitegen import handheld as sitehandheld, markup
from sitegen.config import RELEASE_URL, REPO_URL, _REPO_ROOT
from sitegen.descriptions import PAGE_DATA
from sitegen.guidepage import (
NO_ZIP_FAQ,
_folder_words,
_setup_relative,
_setup_routes,
get_page_title,
no_zip_line,
)
from sitegen.home import _next_block
from sitegen.install import has_release_pack
from sitegen.parts import _parent_front_matter
from sitegen.readme import asset_links
from sitegen.render import _fmt_size
from sitegen.versions import release_line, version_line
def _unzip_into(platform_name: str, display: str, extract_to: str | None, parts: int) -> list[str]:
"""Where the ZIP is unzipped, on the get/ page. A folder the registry
writes relative to the setup's own (`system/`, `bios/`) is named as the
setup's, with the way to find it."""
what = "them all" if parts > 1 else "it"
if not _setup_relative(extract_to):
return [f"- Unzip {what} into {_folder_words(display, extract_to)}.", ""]
lead = GUIDES[platform_name].lead if platform_name in GUIDES else ""
return [
f"- Unzip {what} into {_folder_words(display, extract_to)}. "
f"[Where is it?](../platforms/{platform_name}.md#where-the-files-go)",
"",
*([lead, ""] if lead else []),
]
def generate_get_page(platform_name: str) -> str:
"""get/<platform>/: the address a link outside the site can keep.
Every release deletes the previous tag, and with it each asset URL: six
of the eight links a wiki had to our packs went dead. This page lists
the files of the pack the current release holds, read from release.json,
or the command when no release publishes one. The release process
never touches it: committing release.json rebuilds it."""
config = load_platform_config(platform_name, str(siteinputs.current().platforms))
display = config.get("platform", platform_name)
record = release_record.load_advertised()
pack = release_record.pack_for(platform_name, record)
released = has_release_pack(platform_name)
title = get_page_title(platform_name, display)
# The page changes with the release it lists: its tag is its date, the
# one the sitemap gives (vYYYY.MM.DD).
tag_date = re.fullmatch(r"v(\d{4})\.(\d{2})\.(\d{2})", str(record.get("tag", "")))
if released and pack and tag_date:
PAGE_DATA[f"{release_record.GET_DIR}/{platform_name}.md"] = {"dateModified": "-".join(tag_date.groups())}
if released and pack and pack.get("assets"):
description = (f"The BIOS pack for {display}: {_fmt_size(pack['download_size'])} to "
"download. The address stays the same and always gives the latest ZIP.")
else:
description = f"The BIOS files for {display}: one command installs and checks them."
lines = [
"---", "search: exclude", f"description: {json.dumps(description)}",
*_parent_front_matter((display, f"/platforms/{platform_name}/")), "---", "",
f"# {title}", "",
]
if released and pack and pack.get("assets"):
parts = len(pack["assets"])
release = release_line(platform_name, record)
extract_to = (load_platform_registry(str(siteinputs.current().platforms)).get(platform_name) or {}).get("extract_to")
lines += [
"This address stays the same. It always gives the latest ZIP.",
"",
asset_links(platform_name, record, REPO_URL, f"Download {display} Pack",
button=lambda text, url: markup.button(text, url, primary=True)),
"",
f"- {_fmt_size(pack['download_size'])} to download, "
f"{_fmt_size(pack['extracted_size'])} once unzipped.",
*(["- Both parts are needed." if parts == 2 else f"- All {parts} parts are needed."]
if parts > 1 else []),
*_unzip_into(platform_name, display, extract_to, parts),
*(line for text in release for line in (text, "")),
version_line(platform_name, record, named=len(release) > 1),
"",
]
elif released and record.get("tag"):
lines += [
f"No {display} ZIP yet. The next release has one. "
"The command installs every file and checks it.",
"",
*_setup_routes(platform_name, display),
]
elif released:
lines += [
"This address stays the same. It always gives the latest ZIP.",
"",
markup.button(f"Download {display} Pack", RELEASE_URL, primary=True),
"",
]
else:
lines += [
no_zip_line(display),
"",
*_setup_routes(platform_name, display),
f"[Why no ZIP?](../{NO_ZIP_FAQ})",
"",
]
lines += sitehandheld.platform_block(platform_name, _REPO_ROOT)
lines += _next_block([
f"[{display}](../platforms/{platform_name}.md#install): the folder, "
"and how to run the command on the device",
"[All installer options](../wiki/installer.md)",
])
return "\n".join(lines)
def generate_get_index() -> str:
"""get/: the permanent page of every setup, grouped as the home tiles
are. A link trimmed to /get/ answered 404."""
registry = load_platform_registry(str(siteinputs.current().platforms))
lines = [
"---", "search: exclude",
'description: "The BIOS files of every setup, one page each. Each address stays the same."',
"---", "",
"# BIOS files by setup", "",
"One page per setup. Its address stays the same, so it is the one to share.", "",
]
for group, (label, _description) in DEVICE_GROUPS.items():
names = [name for name, entry in registry.items() if entry.get("device_group") == group]
if not names:
continue
lines += [f"## {label}", ""]
for name in names:
display = load_platform_config(name, str(siteinputs.current().platforms)).get("platform", name)
lines.append(f"- [{get_page_title(name, display)}]({name}.md)")
# The handheld app sits with the group whose tile leads to the
# handheld guide.
if any(HANDHELD_GUIDE and tile.link == HANDHELD_GUIDE.path
for tile in GROUP_TILES.get(group, ())):
lines.append(f"- [{sitehandheld.GROUP_TITLE}]({sitehandheld.GROUP_PAGE}.md)")
lines.append("")
return "\n".join(lines)
+544
View File
@@ -0,0 +1,544 @@
"""The setup guide atop each platform page: download, install and the handheld guide."""
from __future__ import annotations
import html
import json
import release_record
from model import siteinputs
from model.collection import _profiles_on_disk
from model.guides import (
GUIDES,
Guide,
HandheldGuide,
HandheldSystem,
TERMINALS,
detected_systems as _detected_systems,
)
from model.platforms import load_platform_config
from model.registry import load_platform_registry
from resolve.nativemode import digest_algorithm
from sitegen import handheld as sitehandheld, markup
from sitegen.config import _REPO_ROOT
from sitegen.guides import platform_args, terminal_tabs
from sitegen.home import _next_block
from sitegen.install import _installer, has_release_pack
from sitegen.readme import download_links, extract_notes
from sitegen.render import _fmt_size
from sitegen.versions import release_line, setup_version, version_line
# Why a setup has no ZIP, answered once on the FAQ.
NO_ZIP_FAQ = "wiki/faq.md#why-is-there-no-zip-for-my-setup"
def no_zip_line(display: str) -> str:
"""The one line a setup without a release pack shows where the ZIP would be."""
return f"No ZIP for {display}. The command installs every file and checks it."
def get_page_link(platform_name: str, prefix: str = "") -> str:
"""The platform's permanent download page, as a site link."""
return f"{prefix}{release_record.GET_DIR}/{platform_name}.md"
def get_page_title(platform_name: str, display: str) -> str:
"""What a get/ page holds, by its name: the ZIP of a setup a release
publishes one for, the files of any other. "Download KNULLI" read as
the system's own download. A setup that is also an emulator (BizHawk)
names it last: "BizHawk BIOS files" is the title of its emulator page.
A profile listing no file (the RetroArch frontend) titles its page
"... emulator", which no setup title repeats."""
kind = "BIOS pack" if has_release_pack(platform_name) else "BIOS files"
if (_profiles_on_disk().get(platform_name) or {}).get("files"):
return f"{kind} for {display}"
return f"{display} {kind}"
def _setup_relative(extract_to: str | None) -> bool:
"""Whether the registry writes the folder relative to the setup's own
(`system/`, `Firmware/`), not as a path the device reads."""
if not extract_to:
return False
return not extract_to.startswith(("/", "~", "<"))
def _folder_words(display: str, extract_to: str | None) -> str:
"""The folder a pack or a copy goes into, in words: the device's path,
or a folder of the setup named as the setup's."""
if not extract_to:
return "the BIOS folder"
if _setup_relative(extract_to):
return f"{display}'s `{extract_to.rstrip('/')}` folder"
return f"`{extract_to}`"
def _pack_buttons(platform_name: str, label: str = "Pack", prefix: str = "../",
display: str | None = None) -> str:
"""The way to the platform's ZIP from its setup page: a button to its
get/ page, the release it comes from, and the setup version its list
was read at. "Does this pack fit my version?" is the first question a
frontend user asks. A setup with no release pack gets the line that
says so, and why."""
if not has_release_pack(platform_name):
display = display or load_platform_config(platform_name, str(siteinputs.current().platforms)).get(
"platform", platform_name)
return f"{no_zip_line(display)} [Why no ZIP?]({prefix}{NO_ZIP_FAQ})"
record = release_record.load_advertised()
buttons = download_links(
platform_name,
record,
label,
button=lambda text, url: markup.button(text, url, primary=True),
page=get_page_link(platform_name, prefix),
)
released = release_line(platform_name, record)
return "\n\n".join([buttons, *released,
version_line(platform_name, record, named=len(released) > 1,
prefix=prefix)])
def _check_sentence(display: str, mode: str, config: dict, no_list: bool) -> str:
"""What the frontend itself checks, from the mode its code uses."""
if no_list:
return (f"{display} has no BIOS list, so it checks nothing itself. Each "
"emulator looks for its own files when a game starts.")
if config.get("hash_rule") == "size_and_any_hash":
return f"{display} also checks each file's size and contents."
if digest_algorithm(mode):
return f"{display} also checks each file's contents."
return f"{display} checks names only. `--check` also checks contents."
def _folder_rows(rows: tuple[tuple[str, str], ...], indent: str = "") -> list[str]:
return [
f"{indent}| Where | BIOS folder |",
f"{indent}|-------|-------------|",
*(f"{indent}| {label} | {path} |" for label, path in rows),
]
# The second most asked question about BIOS files (14 % of the community
# sample): the file is there and the setup still reports it missing.
# `--check` lists every file whose hash is wrong by name (install.py, the
# "wrong hash" lines of check_lines).
MISSING_IN_PLACE = "Reported missing anyway? `--check` names a wrong file."
# Under every command of a setup page: the safety list is the one the home
# page shows in full, so the setup page links it.
SAFE_LINK = "[Is it safe?](../index.md#is-it-safe)"
def first_screen_words() -> list[str]:
"""What a beginner sees when the command runs, the screen's own words
read from install.py: the one-liner opens the full screen, and the page
showed a line menu (Enter, i, c, q) nobody saw, whose keys had changed
since."""
installer = _installer()
# The screen it opens first: the setup found, or the list when none
# is. Install comes on the next one, Choose systems beside it and named
# above on the page.
# Nothing found, the folder comes before Install: which-pack left it
# out.
return [f"It asks **{installer.TUI_FOUND_TITLE}** (or **{installer.TUI_CHOOSE_TITLE}** "
f"and **{installer.TUI_FOLDER_TITLE}**), then offers **{installer.TUI_INSTALL_ROW}**."]
# The demo files the site serves (docs_assets/demo/, scripts/make_demo.py):
# the GIF is the README's, the tape and demo.json are inputs.
DEMO_ASSETS = tuple(f"{stem}.{ext}" for stem in ("install", "install-handheld")
for ext in ("webm", "mp4", "png"))
def check_pass_line() -> str:
"""The pass line of "How to check": the words `--check` prints only when
no file is missing or wrong (install.py EVERYTHING_IN_PLACE), read from
the installer. Typed here, it kept "All files up to date." after the
installer said "Everything is in place."."""
return f"Good result: `{_installer().EVERYTHING_IN_PLACE}`"
# Under "From your computer": a device with no network installs from the ZIP
# (`--from-pack`). The id is the one wiki/installer.md gives its section.
OFFLINE_LINE = ("No internet on the device? "
"[Install from the ZIP](../wiki/installer.md#without-a-network-offline-install).")
def _network_share(name: str, guide: Guide) -> str:
"""The network folder a computer fills, for a setup that runs on its own
device and has no ZIP: the command runs on the computer and writes
there. Empty when the page cites no such folder."""
if guide.run != ("device",) or _computer_first(name, guide):
return ""
for label, path in guide.folders:
if label.startswith("From Windows") and path.startswith("`\\\\"):
return path.strip("`").rstrip("\\")
return ""
def _share_tabs(name: str, share: str) -> tuple[dict[str, str], dict[str, str]]:
"""The command per computer for a network folder (\\\\RECALBOX\\share\\bios),
and how a Mac or a Linux desktop opens that folder first. Only Windows
had a line: a Mac user fell back to SSH or to taking the card out.
macOS mounts smb://recalbox/share at /Volumes/share. A Linux desktop
mounts it where its file manager chooses, so that tab names the folder.
"""
host, _, rest = share.lstrip("\\").partition("\\")
volume, _, below = rest.partition("\\")
url = f"smb://{host.lower()}/{volume}"
tail = "/" + below.replace("\\", "/") if below else ""
args = {
"windows": f"--platform {name} --dest {share}",
"macos": f"--platform {name} --dest /Volumes/{volume}{tail}",
"linux": f"--platform {name} --dest /path/to/{volume}{tail}",
}
how = {
"macos": (f"In Finder, Go > Connect to Server: `{url}`. Then paste the line in "
"**Terminal**."),
"linux": (f"Open `{url}` in the file manager. Paste the line in a terminal, "
f"with the folder it opened for `/path/to/{volume}`."),
}
return args, how
def _offline_line(name: str) -> list[str]:
"""The offline line, on a setup whose ZIP a release publishes: the
installer reads that ZIP with no network (`--from-pack`)."""
pack = release_record.pack_for(name, release_record.load_advertised())
return [OFFLINE_LINE, ""] if pack and pack.get("assets") else []
# The route of a setup with no ZIP when the device has no network: the
# command writes to any folder named after --dest (wiki/installer.md), so a
# computer fills the device's card. The FAQ answers it with an example.
CARD_ROUTE_FAQ = "wiki/faq.md#fill-an-sd-card-from-a-computer"
def _card_route(name: str, display: str, guide: Guide) -> list[str]:
"""The route with no network on the device, for a setup whose ZIP no
release publishes: the command run on a computer, into the card. A
setup with a ZIP has the offline line, a card setup's command already
runs on the computer. The folder named after --dest is the one the
command fills on the device (the registry's extract_to): AmberELEC's is
`/storage/roms/`, which holds `bios/` and `neogeo/`. How a computer
sees it is the reader's to name: no guide cites it."""
if guide.on_card or _offline_line(name):
return []
extract_to = (load_platform_registry(str(siteinputs.current().platforms)).get(name) or {}).get("extract_to")
leaf = (extract_to or "bios").rstrip("/").rsplit("/", 1)[-1].lstrip("~") or "bios"
tabs = guide.card_run or ("windows", "macos", "linux")
args = {key: f"--platform {name} --dest "
+ (f"E:\\path\\to\\{leaf}" if key == "windows" else f"/path/to/{leaf}")
for key in tabs}
if guide.run != ("device",):
lead = ("No network here? Run the command on a computer that has one, with a USB "
f"drive's folder after `--dest`. Then copy it into {_folder_words(display, extract_to)}.")
return [lead, "", *terminal_tabs(tabs, args, steps=False)]
# A folder on the card's Linux partition: Windows and macOS show the
# small boot partition alone, and no folder there fits --dest.
put = ("Put the device's card in a computer." if "windows" in tabs
else "Only a Linux computer opens the card.")
lead = (f"No network? {put} After `--dest`, "
f"name the folder the device calls `{extract_to}`.")
return [lead, "", *terminal_tabs(tabs, args, steps=False),
f"[More on SD cards](../{CARD_ROUTE_FAQ})", ""]
def _get_page_line(name: str, display: str) -> list[str]:
"""The setup's get/ page, under the command of a setup with no ZIP: the
address a guide writer keeps. A setup with a ZIP links it by its button."""
if has_release_pack(name):
return []
return [f"Link to share: [{get_page_title(name, display)}](../{get_page_link(name)})", ""]
def _setup_routes(name: str, display: str, page_link: bool = False) -> list[str]:
"""The ways to run the command for a setup no ZIP serves first, written
once for its setup page and its get/ page: the network folder from a
computer, the card from a computer when the device has no network, and
the device's own terminal. *page_link* adds the get/ page, on the setup
page only."""
guide = GUIDES[name]
share = _network_share(name, guide)
card = _card_route(name, display, guide)
shared = _get_page_line(name, display) if page_link else []
if share or (card and guide.run == ("device",)):
computer = ["## From a computer { #from-your-computer }", ""]
if share:
args, how = _share_tabs(name, share)
# The setup page stays in its word budget: its Mac and Linux
# lines are on the get/ page, the one the command is shared from.
tabs = ("windows",) if page_link else ("windows", "macos", "linux")
computer += [
"Needs the device on the same network.",
"",
*terminal_tabs(tabs, args, how=how),
*([f"[Mac or Linux](../{get_page_link(name)}#from-your-computer)", ""]
if page_link else []),
SAFE_LINK,
"",
]
return [*computer, *card,
*_guide_install(name, guide, "## On the device { #install }"), *shared]
return [*_guide_install(name, guide, "## Install"), *shared, *card]
# Shown in the "On the device" tab of a guide that has no `terminal:` of its own.
DEVICE_TERMINAL_FALLBACK = "Or fill the folder from a computer, with the ZIP."
def _computer_first(name: str, guide: Guide) -> bool:
"""A system that runs only on its own device, with a ZIP to download: a
beginner fills its folder from a computer more easily than from a
terminal on the TV. Without a ZIP the command is the only route."""
pack = release_record.pack_for(name, release_record.load_advertised())
return guide.run == ("device",) and bool(pack and pack.get("assets"))
def _ships_neogeo(name: str) -> bool:
"""Whether the setup's files hold `neogeo.zip`, the archive a reader most
often unzips by mistake: arcade BIOS sets are read zipped."""
manifest = _REPO_ROOT / "install" / f"{name}.json"
if not manifest.is_file():
return False
files = json.loads(manifest.read_text(encoding="utf-8")).get("files", [])
return any(f.get("dest", "").rsplit("/", 1)[-1] == "neogeo.zip" for f in files)
def _guide_download(name: str, display: str, guide: Guide, extract_to: str | None,
heading: str) -> list[str]:
"""The pack: its buttons, its size, and where it is unzipped."""
lines = [heading, ""]
record = release_record.load_advertised()
pack = release_record.pack_for(name, record)
network = any(label.startswith("From ") for label, _path in guide.folders)
if pack and pack.get("assets"):
parts = len(pack["assets"])
bullets = [
f"{_fmt_size(pack['download_size'])} to download, "
f"{_fmt_size(pack['extracted_size'])} once unzipped."
]
if parts > 1:
bullets.append("Both parts are needed." if parts == 2 else f"All {parts} parts are needed.")
if _computer_first(name, guide) and network:
target = "the network folder above"
else:
target = f"`{extract_to}`" if extract_to else "the BIOS folder"
bullets.append(f"Unzip {'them all' if parts > 1 else 'it'} into {target}."
+ (" Files like `neogeo.zip` stay zipped." if _ships_neogeo(name) else ""))
if guide.download_hint and not _computer_first(name, guide):
bullets.append(guide.download_hint)
lines += [
_pack_buttons(name, f"Download {display} Pack"),
"",
*(f"- {b}" for b in bullets),
"",
]
elif not has_release_pack(name):
lines += [_pack_buttons(name, display=display), ""]
elif record.get("tag"):
made_from = setup_version(name)
lines += [
f"No {display} ZIP yet. The command installs the same files"
+ (f", made for {made_from}." if made_from else "."),
"",
]
else:
lines += [_pack_buttons(name, f"Download {display} Pack"), ""]
return [*lines, *only_some_consoles(name, "../")]
def only_some_consoles(name: str, prefix: str = "") -> list[str]:
"""The way to a smaller download, in the words Get the files uses."""
return [
f"Only some consoles? [Pick them]({prefix}which-pack.md?platform={name}"
f"#only-some-consoles), or the command's **{_installer().TUI_SYSTEMS_ROW}**.",
"",
]
def _guide_install(name: str, guide: Guide, heading: str) -> list[str]:
"""The command, in a tab per place it runs, and whether it is safe."""
lines = [
heading,
"",
"It finds the folder and checks each file.",
"",
]
if guide.on_card:
lines += [
"Put the SD card in a computer. On Windows, note its letter, like "
"**E:**. Put the card's path after `--dest`.",
"",
]
device = guide.terminal or f"{TERMINALS['device'][1]} {DEVICE_TERMINAL_FALLBACK}"
return [
*lines,
*terminal_tabs(guide.run, platform_args(name, guide), how={"device": device}),
SAFE_LINK,
"",
]
def devices_meta(devices: tuple[str, ...]) -> str:
"""The device names a reader types, as the `devices` search field of the
page: an attribute on an empty element, commas out (the search engine
splits its keys on commas), so no excerpt shows them."""
names = " ".join(name.replace(",", " ") for name in devices)
return f'<span data-pagefind-meta="devices:{html.escape(names, quote=True)}"></span>'
# Devices named in a row of the handheld guide. The rest stay in the
# page's search field and on the list the row links.
HANDHELD_ROW_DEVICES = 6
# Where a handheld row with no cited folder sends the reader: the setting
# that shows RetroArch's BIOS folder, the words of the RetroArch page.
RETROARCH_FOLDER_SETTING = ("In RetroArch, open **Settings > Directory > System/BIOS**. "
"It shows the folder.")
# After a folder on a part of the card only Linux reads.
LINUX_ONLY_HINT = ("Copy from a Linux computer, or check the folder in RetroArch's "
"**Settings > Directory > System/BIOS**.")
def _handheld_row(system: HandheldSystem) -> str:
shown = ", ".join(system.devices[:HANDHELD_ROW_DEVICES])
more = len(system.devices) - HANDHELD_ROW_DEVICES
devices = (f"{shown}{f' and {more} more' if more > 0 else ''} "
f"([list]({system.devices_source}))" if system.devices else "")
if not system.folder:
folder = RETROARCH_FOLDER_SETTING
else:
folder = f"{system.folder} ([source]({system.folder_source}))"
if system.linux_only:
folder += f". {LINUX_ONLY_HINT}"
return f"| {handheld_name(system)} | {devices} | {folder} |"
def handheld_name(system: HandheldSystem) -> str:
"""A system's cell: its name, and for one that stopped, that it did and
what replaced it, with the project's own page saying so."""
return (f"{system.name}, {system.ended} ([source]({system.ended_source}))"
if system.ended else system.name)
def generate_handheld_guide(guide: HandheldGuide) -> str:
"""The guide for the handheld systems that run a setup (ArkOS, muOS,
Onion... run RetroArch): one row per system the installer detects, the
folder seen on the card from a computer and the devices, each cited from
the system's own pages, then that setup's ZIP and the command for a card.
A handheld owner starts from the device name. The systems were named
only in a closed note, with a path seen from inside the device."""
uses = GUIDES[guide.uses]
display = load_platform_config(guide.uses, str(siteinputs.current().platforms)).get("platform", guide.uses)
args = {"windows": f"--platform {guide.uses} --dest E:\\BIOS",
"macos": f"--platform {guide.uses} --dest /path/to/card/BIOS",
"linux": f"--platform {guide.uses} --dest /path/to/card/BIOS"}
return "\n".join([
f"# {guide.title}",
"",
guide.summary,
"",
devices_meta(guide.devices),
"",
"[Download](#download)",
"",
"## Where the files go { #where-the-files-go }",
"",
"Put the SD card in a computer. Find the system below.",
"",
"| System | Devices | BIOS folder on the card |",
"|--------|---------|-------------------------|",
*(_handheld_row(system) for system in guide.systems),
"",
*_guide_download(guide.uses, display, uses, None, "## Download { #download }"),
*_offline_line(guide.uses),
f"On {sitehandheld.joined(sitehandheld.group_systems(), 'or')}: "
f"[{sitehandheld.GROUP_TITLE}]"
f"(../get/{sitehandheld.GROUP_PAGE}.md).",
"",
"## Fill the card from a computer { #install }",
"",
"On Windows, note the card's letter, like **E:**. Put its BIOS folder after "
"`--dest`, written as in the table.",
"",
*terminal_tabs(("windows", "macos", "linux"), args),
SAFE_LINK,
"",
*_next_block([
f"[{display}]({guide.uses}.md): every folder and every file",
"[When a game does not start](../wiki/troubleshooting.md)",
]),
]) + "\n"
def _platform_guide(name: str, display: str, cov: dict, registry: dict, no_list: bool) -> list[str]:
"""The guide part of a platform page: folder, command, pack, check, next.
A system that runs only on its own device puts the computer route
(download, unzip into the network folder) before the command."""
guide = GUIDES[name]
entry = registry.get(name, {})
extract_to = entry.get("extract_to")
# An app's page opens on the command: one line to paste is the shortest
# way to a working setup, and the folder table is what a manual copy needs.
lines = ["## Where the files go", ""]
if guide.lead:
lines += [guide.lead, ""]
lines += _folder_rows(guide.folders)
if extract_to and has_release_pack(name):
lines.append(f"| Unzip the pack into | `{extract_to}` |")
lines.append("")
for note in guide.notes:
lines += [note, ""]
lines += [line for note in extract_notes(str(siteinputs.current().platforms), released_only=True)
if f"The {display} pack " in note
for line in (note, "")]
if guide.more_folders:
detected = _detected_systems(registry, name) if guide.more_folders_detected else []
lines += markup.details("note", guide.more_folders_title, [
*_folder_rows(guide.more_folders),
*(f"| {system} | `{folder}` |" for system, folder in detected),
"",
*([guide.more_folders_note, ""] if guide.more_folders_note else []),
])
if guide.on_card:
lines += ["<!-- image: minui-card -->", ""]
if _computer_first(name, guide):
# The ZIP copied over the network needs the folder table above it.
lines += [
*_guide_download(name, display, guide, extract_to,
"## From a computer { #download }"),
*_offline_line(name),
*_guide_install(name, guide, "## On the device { #install }"),
]
else:
where = lines
lines = [
*_setup_routes(name, display, page_link=True),
*_guide_download(name, display, guide, extract_to, "## Download"),
*_offline_line(name),
*where,
]
check_args = {key: f"{args} --check" for key, args in platform_args(name, guide).items()}
lines += [
"## How to check",
"",
"Add `--check` to the command. It changes nothing.",
"",
*terminal_tabs(guide.run, check_args, steps=False),
check_pass_line(),
"",
_check_sentence(display, cov["mode"], cov["config"], no_list),
"",
MISSING_IN_PLACE,
"",
*([guide.finish, ""] if guide.finish else []),
*_next_block([
"[First install, step by step](../wiki/first-install.md)",
"[When a game does not start](../wiki/troubleshooting.md)",
]),
]
return lines
+250
View File
@@ -0,0 +1,250 @@
"""The home and explore pages: the setup picker and the collection in figures."""
from __future__ import annotations
import html
from model.composition import compute_composition
from model.guides import DEVICE_GROUPS, GROUP_TILES, GUIDES, Guide, TRUST_ITEMS, setup_count
from model.platforms import load_platform_config
from model.profiles import unique_emulator_profiles
from model.registry import load_platform_registry
from sitegen import markup
from sitegen.readme import demo_description, demo_facts
from sitegen.render import _fmt_size
# Home page
def _stat(value: str, label: str) -> list[str]:
return [
markup.block_open("div", 'class="rb-stat"'),
# One line, a space between: the page text read "168/168Coverage".
f'<span class="rb-stat-value">{value}</span> <span class="rb-stat-label">{label}</span>',
"</div>",
"",
]
def _group_members(coverages: dict, registry: dict, group: str) -> list[str]:
"""Registered platforms of a device group, by display name."""
return sorted(
(name for name in coverages if registry.get(name, {}).get("device_group") == group),
key=lambda name: coverages[name]["platform"].casefold(),
)
def _next_block(links: list[str]) -> list[str]:
"""Where to go from here, at the end of a page: a plain heading and a
list. A tinted callout with a side stripe said the same as the pager."""
return ["## Next steps", "", *(f"- {link}" for link in links), ""]
def _tiles(registry: dict, members: list[str], display: dict[str, str], prefix: str = "",
group: str = "", eager: int = 0) -> list[str]:
"""The setup tiles of one device group: logo, name and the hardware it
runs on, then the group's other tiles: a kind of device that runs one of
the setups (Android handhelds, Linux handhelds)."""
return markup.platform_tiles([
*((display[name], f"{prefix}platforms/{name}.md",
str(registry.get(name, {}).get("logo") or ""),
GUIDES[name].runs_on or _runs_on(registry.get(name, {}), GUIDES[name]))
for name in members),
*((tile.name, f"{prefix}{tile.link}", tile.logo, tile.text)
for tile in GROUP_TILES.get(group, ())),
], eager=eager)
def setup_picker(registry: dict, display: dict[str, str], prefix: str = "") -> list[str]:
"""Every setup as a tile, under the device group it belongs to. The
setups alone in their group share one row: "MiSTer FPGA" above
"MiSTer FPGA" said nothing. Only the first row of logos loads with the
page: the 19 logos were most of the bytes of the home page."""
lines: list[str] = []
alone: list[str] = []
for group, (label, _description) in DEVICE_GROUPS.items():
members = _group_keys(registry, group, display)
if len(members) == 1 and not GROUP_TILES.get(group):
alone += members
elif members:
eager = 0 if lines else markup.FIRST_ROW_TILES
lines += [f"**{label}**", "",
*_tiles(registry, members, display, prefix, group, eager)]
if alone:
eager = 0 if lines else markup.FIRST_ROW_TILES
lines += ["**Other setups**", "", *_tiles(registry, alone, display, prefix, eager=eager)]
return lines
def generate_home(
db: dict,
coverages: dict,
profiles: dict,
registry: dict | None = None,
platforms_dir: str = "platforms",
) -> str:
"""The page someone lands on knowing nothing: what a BIOS file is,
whether they need one, and the three steps to get the right ones.
The figures about the collection, the cards to the deeper pages and the
call for help sat below the steps and doubled the page: they are on the
Explore index, one tab further. No date and no "next" box: the hero
buttons say where to go."""
registry = registry or load_platform_registry(platforms_dir)
display = {key: load_platform_config(key, platforms_dir).get("platform", key)
for key in registry}
named = [n for n in ("RetroArch", "Batocera", "EmuDeck") if n in display.values()]
others = setup_count() - len(named)
works_with = ", ".join(named) + (f" and {others} more" if others else "")
lines = [
"# BIOS files for emulators",
"",
"Some consoles need a small program to start their games. It is called "
"the **BIOS**. The emulator needs a copy of it. RetroBIOS puts the right copy "
"in the right folder.",
"",
markup.button("Get the files", "which-pack.md", primary=True) + " "
+ markup.button("What is a BIOS?", "wiki/what-are-bios-files.md"),
"",
f"Free. No account. Works with {works_with}.",
"",
"- BIOS missing, even with the file there? "
"[When a game does not start](wiki/troubleshooting.md)",
"- Have a file? [Check it](files/index.md)",
"",
"## Is it needed? { #do-i-need-it }",
"",
"- **Yes**, if the emulator says a BIOS is missing.",
"- **Yes** for PlayStation 2 and Neo Geo.",
"- **Better with it** for Dreamcast: some games need it.",
"- **Usually not** for NES, Super Nintendo, Mega Drive and Game Boy.",
"",
"Details: [Every console, one by one](systems/index.md)",
"",
"## Three steps",
"",
*markup.steps([
"**Pick the device.** Its page gives one line to copy.",
"**Paste it, press Enter.** Some setups have a ZIP.",
"**Start a game.**",
]),
*install_demo(),
"## Pick the device { #pick-your-device }",
"",
*setup_picker(registry, display),
"## Is it safe?",
"",
*(f"- {item}" for item in TRUST_ITEMS),
"",
"[How the command is checked](wiki/faq.md#is-piping-the-installer-into-a-shell-safe). "
"Details: [Is it legal?](wiki/legal.md)",
"",
]
return "\n".join(lines) + "\n"
def generate_explore_index(db: dict, coverages: dict, profiles: dict) -> str:
"""The Explore tab opens here: where to look for one console, one
emulator or one installer option, and the figures of the collection."""
total_files = db.get("total_files", 0)
total_size = db.get("total_size", 0)
emulator_count = len(unique_emulator_profiles(profiles))
lines = [
"# Explore",
"",
"One console, one emulator, or one installer option: each has its page, "
"with the files it needs and the code that reads them.",
"",
*markup.card_grid([
("Systems", ["What each console and computer needs, file by file.", "",
"[Browse the systems](systems/index.md)"]),
("Emulators", ["What each emulator reads, with the source code that reads it.", "",
"[Browse the emulators](emulators/index.md)"]),
("Installer options", [
"Fewer files, one region, another folder, a check without download.", "",
"[All installer options](wiki/installer.md)"]),
("How files are checked", [
"Each setup checks its files its own way: by name, by MD5 or by SHA1.", "",
"[How each platform checks files](wiki/verification-modes.md)"]),
("Data and API", ["Every file and hash as JSON, CSV and SQLite.", "",
"[Data and API](data.md)"]),
]),
"## The collection",
"",
markup.block_open("div", 'class="rb-stats"'),
"",
*_stat(f"{total_files:,}", COLLECTION_FILES_LABEL),
*_stat(str(setup_count()), "Setups supported"),
*_stat(str(emulator_count), "Emulators documented"),
*_stat(_fmt_size(total_size), "Size of the collection"),
"</div>",
"",
composition_sentence(db),
"",
"## Help the project",
"",
"A file sent in, an emulator profile or a correction fills a gap for "
"every setup at once. For contributors: [How to contribute](contributing.md).",
"",
]
return "\n".join(lines) + "\n"
# The home tile counts the whole collection. Labelled "Files" above a table
# of pack buttons, it read as what one pack contains.
COLLECTION_FILES_LABEL = "Files collected"
def composition_sentence(db: dict) -> str:
comp = compute_composition(db)
return (
f"The collection holds {comp['systems']['files']:,} console and "
f"computer system files, {comp['arcade']['files']:,} arcade ROM sets "
f"(`Arcade/`), and {comp['game_data']['files']:,} game and engine "
"data files (`Game Engines/`, `RPG Maker/`, `ScummVM/` and the game "
"publishers' trees). No pack holds "
"them all: each carries what its platform's emulators load."
)
def install_demo(variant: str = "default", name: str = "") -> list[str]:
"""An installer demo (default, or handheld): a video that loads once it
is on screen, its description for screen readers. *name* tells two
demos of one page apart (the tab each sits in)."""
facts = demo_facts(variant)
text = html.escape(demo_description(facts), quote=True)
own = f' variant="{variant}" name="{name}"' if name else ""
return [f'<InstallDemo description="{text}" width="{facts["width"]}" '
f'height="{facts["height"]}"{own} />', ""]
# Navigation
_OS_NAMES = {"windows": "Windows", "darwin": "macOS", "linux": "Linux"}
def _runs_on(entry: dict, guide: Guide) -> str:
"""Where a setup runs, read from the systems the installer detects it on."""
if guide.on_card:
return "SD card, filled from a computer"
if "server" in guide.run:
return "A server"
if "device" in guide.run:
return "Its own system"
systems = {rule.get("os") for rule in (entry.get("install") or {}).get("detect") or []}
names = [label for key, label in _OS_NAMES.items() if key in systems]
if "steamdeck" in guide.run:
names.append("Steam Deck")
if "android" in guide.run:
names.append("Android")
return ", ".join(names)
def _group_keys(registry: dict, group: str, display: dict[str, str]) -> list[str]:
return sorted(
(k for k in registry if registry[k].get("device_group") == group),
key=lambda k: display[k].casefold(),
)
+544
View File
@@ -0,0 +1,544 @@
"""Install blocks and commands for an emulator, a platform or a console."""
from __future__ import annotations
import functools
import html
import json
import re
import shlex
import types
from collections import Counter
from model import siteinputs
from model.guides import GUIDES, TERMINALS, install_command
from model.platforms import load_platform_config
from model.registry import list_release_pack_platforms
from resolve.layout import runs_standalone
from sitegen import markup
from sitegen.config import _REPO_ROOT
from sitegen.fields import search_excluded
from sitegen.guides import fence, platform_args, terminal_tabs
from sitegen.render import _code, _escape_tags
from sitegen.sources import _source_ref_markdown
def has_release_pack(platform_name: str) -> bool:
"""Whether a release publishes a ZIP for the platform (`release_pack`)."""
return platform_name in _release_pack_platforms()
def _release_pack_platforms() -> frozenset[str]:
return _release_packs_in(str(siteinputs.current().platforms))
@functools.cache
def _release_packs_in(platforms_dir: str) -> frozenset[str]:
return frozenset(list_release_pack_platforms(platforms_dir))
_platform_names: dict[str, str] = {}
def _platform_display(name: str) -> str:
"""A setup's name as its platform file writes it: Batocera, not batocera."""
display = _platform_names.get(name)
if display is None:
try:
config = load_platform_config(name, str(siteinputs.current().platforms))
except FileNotFoundError:
config = {}
display = _platform_names[name] = str(config.get("platform") or name)
return display
def comes_with_app(f: dict) -> bool:
"""The emulator installs the file in the build the entry describes.
The rule verify and the pack read (``installed_with_emulator``). An entry
narrowed by ``mode`` is that build's alone: the other build reads its
own entry, or nothing.
"""
from resolve.validation import installed_with_emulator
return installed_with_emulator(f)
def install_commands(args: str = "", indent: str = "",
oses: tuple[str, ...] | None = None) -> list[str]:
"""The same install for each place a user runs it: one generator for the
download page and the platform, system and emulator pages, so none of
them loses the Android or Windows form.
``oses`` names the terminals (keys of TERMINALS) the command runs in,
written as the synced OS tabs: MAME4droid runs on Android only, and its
page offered a PowerShell command. None keeps the three blocks.
"""
if oses is not None:
return terminal_tabs(oses, dict.fromkeys(oses, args), indent)
lines = []
for label, shell in (
("Linux, macOS, Steam Deck:", "sh"),
("Windows (PowerShell):", "powershell"),
("Android (Termux, the command installs Python and asks for storage access):", "sh"),
):
lines += [f"{indent}{label}", "", *fence(shell, install_command(shell, args), indent), ""]
return lines
@functools.cache
def _installer() -> types.ModuleType:
"""install.py, read as a module: the names `--emulator` accepts are its
own (`emulator_names`)."""
import importlib.util
spec = importlib.util.spec_from_file_location("install", _REPO_ROOT / "install.py")
if spec is None or spec.loader is None:
raise ImportError(f"cannot load {_REPO_ROOT / 'install.py'}")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
@functools.cache
def _published_emulator_names() -> dict[str, dict[str, str]]:
"""Per published manifest, every name `--emulator` accepts there and the
profile it stands for, as `install.py --list-emulators` prints them."""
installer = _installer()
names: dict[str, dict[str, str]] = {}
for path in sorted((_REPO_ROOT / "install").glob("*.json")):
manifest = json.loads(path.read_text(encoding="utf-8"))
names[path.stem] = installer.emulator_names(
manifest, manifest.get("files") or [], manifest.get("omitted_files") or [])
return names
# Where a setup's command runs, in the order the tabs show them.
_COMMAND_TERMINALS = ("windows", "macos", "linux", "steamdeck", "android", "device")
# The terminals an app's data_root key covers: the Deck runs the Linux build.
_DATA_ROOT_TERMINALS = {
"windows": ("windows",), "macos": ("macos",), "linux": ("linux", "steamdeck"),
"android": ("android",), "ios": (),
}
def emulator_install_route(name: str, profile: dict) -> tuple[str, list[str], tuple[str, ...]]:
"""The name `--emulator` takes for this profile, the setups the command
fills, and the terminals it runs in, or ("", [], ()) when none works.
A name works where a published manifest maps it to this profile: 215
pages printed a command every manifest refused. A setup counts when the
installer finds it without `--dest`. A standalone app is reached only
through a setup that launches it as an app (its standalone_cores), on
the systems both run on: RetroArch's list names AetherSX2, and the
command filled RetroArch's system folder, which the app never reads.
"""
if profile.get("type") in ("alias", "launcher") or profile.get("role") == "test":
return "", [], ()
if not [f for f in profile.get("files") or [] if isinstance(f, dict) and not comes_with_app(f)]:
return "", [], ()
standalone = profile.get("type") == "standalone"
accepted: dict[str, set[str]] = {}
for platform, names in _published_emulator_names().items():
if platform not in GUIDES:
continue
if standalone and not runs_standalone(name, profile, _standalone_cores(platform)):
continue
if any("--dest" in args for args in platform_args(platform, GUIDES[platform]).values()):
continue
own = {n for n, target in names.items() if target == name}
if own:
accepted[platform] = own
if not accepted:
return "", [], ()
# The profile's own name where a setup takes it, else the alias most
# setups take: the one command must work on every setup it names.
candidates = set().union(*accepted.values())
command = min(candidates, key=lambda n: (
-sum(n in own for own in accepted.values()), n != name, n))
order = list(GUIDES)
setups = sorted((p for p, own in accepted.items() if command in own), key=order.index)
terminals = {key for setup in setups for key in GUIDES[setup].run}
if isinstance(profile.get("data_root"), dict):
# Only the systems the program is built for (Cemu has no Android
# build). A device setup runs it itself: its terminal stays.
terminals &= {"device", *(t for key in profile["data_root"]
for t in _DATA_ROOT_TERMINALS.get(key, ()))}
oses = tuple(key for key in _COMMAND_TERMINALS if key in terminals)
if not oses:
return "", [], ()
return command, setups, oses
def _standalone_cores(platform: str) -> frozenset[str]:
"""The emulators a setup launches as apps, by its platform file."""
return _standalone_cores_in(str(siteinputs.current().platforms), platform)
@functools.cache
def _standalone_cores_in(platforms_dir: str, platform: str) -> frozenset[str]:
config = load_platform_config(platform, platforms_dir)
return frozenset(str(c) for c in config.get("standalone_cores") or [])
def _said_or(names: list[str]) -> str:
return names[0] if len(names) == 1 else ", ".join(names[:-1]) + f" or {names[-1]}"
def _install_block(name: str, profile: dict) -> list[str]:
"""One command that installs this emulator's files where it reads them.
The installer finds the setup and its BIOS folder, then keeps what this
emulator reads there: its own files and the setup's files of the
systems it runs. Written only where a published manifest takes the
name, in the terminals of the setups that run it. `--emulator` turns off
the pass that fills a lone app's folders (install.py, `narrowing` in
main), so an app on its own is named with the setup that serves it.
"""
command, setups, oses = emulator_install_route(name, profile)
if not command:
return []
emu = str(profile.get("emulator") or name)
shown = [_platform_display(setup) for setup in setups]
if profile.get("type") == "standalone":
lead = (f"With {_said_or(shown)}: the installer finds {_said_or(shown)} and its "
f"BIOS folder, then downloads only the files {emu} reads there and checks "
"each one.")
else:
lead = ("The installer finds the setup and its BIOS folder, then downloads "
"only the files this emulator reads there and checks each one.")
if profile.get("type") == "standalone + libretro":
# The command fills a setup, never the app's own folder.
where = (_said_or(shown) if len(shown) <= 3
else f"{shown[0]}, {shown[1]} or another setup")
lead = f"For {emu} inside {where}. {lead}"
return search_excluded(markup.details("tip", "Install this emulator's files", [
lead,
"",
*install_commands(f"--emulator {command}", oses=oses),
]))
# Entries whose folder the app opens is not data_root joined to their
# standalone_path (or path): the pack builder still places them by that
# field, so the joined path names a place the app never reads. Their page
# gives the data folder alone. A row names the profile, the entries (a name,
# a path prefix ending in "/", or "*" for every file) and, when the rule
# holds on some systems only, the data_root keys it covers.
FOLDER_ONLY: tuple[tuple[str, tuple[str, ...], tuple[str, ...], str], ...] = (
("amiberry", ("*",), (),
"the app reads every ROM, Kickstarts included, under ROMs/ of its folder"),
("fsuae", ("fsuae/Kickstarts/",), (),
"the app reads Kickstarts from ROMs/Kickstart/ of its folder"),
("citra", ("Citra/sysdata/",), (),
"the app reads its keys and shared fonts from sysdata/ of its folder"),
("ymir", ("*",), (),
"the app reads its IPL, cartridge and CD-block ROMs from roms/ipl/, roms/cart/ and roms/cdb/"),
("mame", ("*",), (),
"the app reads every set under roms/ of its working directory"),
("eka2l1", ("data/",), ("ios",),
"on iOS the data folder is the data-storage folder itself, so data/ would be one level too deep"),
("aethersx2", ("resources/", "eeprom.dat", "flash.dat"), (),
"resources sit beside the program, and eeprom.dat and flash.dat in the working directory"),
("cemu", ("resources/sharedFonts/",), (),
"the shared fonts are read from the program's data path"),
("cxbx-reloaded", ("hlsl/",), (),
"the shaders are read from beside the program"),
("ppsspp-1.5.4", ("ppsspp-1.5.4/assets/",), (),
"the assets tree is read from beside the program"),
("yaps2", ("resources/",), (),
"resources are read from beside the program"),
("hatari", ("tos.img", "tos.sym"), (),
"the TOS image is read from the install data directory"),
("armsx2", ("proverb.zip",), ("android",),
"the Android app keeps the arcade boot programs in its internal storage"),
("armsx2", ("eeprom.dat", "flash.dat"), (),
"eeprom.dat and flash.dat are read from the working directory"),
("kenji-nx", ("drivers/",), (),
"a driver archive is unpacked under drivers/, a layout not confirmed in the source"),
)
def folder_only_matches(pattern: str, entry: dict) -> bool:
"""Whether a FOLDER_ONLY pattern names this entry."""
if pattern == "*":
return True
if pattern.endswith("/"):
return any(str(entry.get(key) or "").startswith(pattern)
for key in ("path", "standalone_path"))
return entry.get("name") == pattern
def _folder_only(name: str, entry: dict) -> set[str]:
"""The data_root keys on which this entry's joined path is not the app's
folder: every key ({"*"}), some, or none."""
keys: set[str] = set()
for profile, patterns, only, _reason in FOLDER_ONLY:
if profile == name and any(folder_only_matches(p, entry) for p in patterns):
keys |= set(only) or {"*"}
return keys
def standalone_place(name: str, profile: dict, entry: dict, key: str = "") -> str:
"""Where under the data folder the app reads this entry, or "".
Only what the app opens there: a lone app's ``standalone_path`` or
``path``, a dual profile's ``standalone_path`` or the ``path`` of an
entry its standalone build alone reads. Nothing for an entry found by
name, one the app ships, one the libretro core alone reads, or one
FOLDER_ONLY lists (on ``key``, or on any key when ``key`` is empty).
"""
if not isinstance(entry, dict) or not profile.get("data_root"):
return ""
mode = entry.get("mode")
if mode == "libretro" or comes_with_app(entry):
return ""
excluded = _folder_only(name, entry)
if "*" in excluded or (key in excluded if key else excluded):
return ""
if profile.get("type") == "standalone" or mode == "standalone":
return str(entry.get("standalone_path") or entry.get("path") or "")
return str(entry.get("standalone_path") or "")
_OS_LABELS = {"windows": "Windows", "macos": "macOS", "linux": "Linux",
"android": "Android", "ios": "iOS"}
def _under_root(root: str, folder: str) -> str:
"""``root`` with ``folder`` below it, as code: each alternative of
"$XDG_CONFIG_HOME/x, else ~/.config/x", and a root written in words
("the folder picked in the setup wizard") kept as words."""
folder = folder.strip("/")
shown = []
for alternative in root.split(", else "):
alternative = alternative.strip()
if " " in alternative and "/" not in alternative and not alternative.startswith("<"):
shown.append(f"{_code(folder + '/')} in {_escape_tags(alternative)}"
if folder else _escape_tags(alternative))
continue
joined = alternative.rstrip("/") + (f"/{folder}" if folder else "") + "/"
shown.append(_code(joined))
return ", else ".join(shown)
def _data_root_folder(name: str, profile: dict, key: str, entries: list[dict]) -> str:
"""The one folder under the root that every entry the app reads sits
in, or "": VICE places 3 of its 322 files in DRIVES/, and naming that
folder would send the other 319 there."""
folders = set()
for f in entries:
mode = f.get("mode")
if mode == "libretro" or comes_with_app(f):
continue
place = standalone_place(name, profile, f, key)
if not place:
return ""
folders.add(place.rpartition("/")[0])
return folders.pop() if len(folders) == 1 else ""
def data_folder_block(name: str, profile: dict, entries: list[dict] | None = None) -> list[str]:
"""The app's data folder, one tab per system it runs on, each with the
code that names it and its note: 61 profiles cite it and no page showed
it. ``entries`` are the files the folder is for: when they all sit in
one folder below the root, the tab names that folder."""
roots = profile.get("data_root") or {}
if not isinstance(roots, dict) or not roots:
return []
if entries is None:
entries = [f for f in profile.get("files") or [] if isinstance(f, dict)]
items = []
for key in ("windows", "macos", "linux", "android", "ios"):
root = roots.get(key)
if not isinstance(root, dict) or not root.get("path"):
continue
path = str(root["path"])
line = _under_root(path, _data_root_folder(name, profile, key, entries))
if key == "android" and path.startswith("Android/data/"):
line += ", on the internal storage."
body = [line]
note = " ".join(str(root.get("note") or "").split()).rstrip(".")
if note:
# "the folder" reads as a sentence, "portable.ini" keeps its case.
first = note.split(" ", 1)[0]
if first.isalpha() and first.islower():
note = note[:1].upper() + note[1:]
body += ["", _escape_tags(note) + "."]
body += ["", f"Source: {_source_ref_markdown(profile, str(root['source_ref']))}"]
items.append((_OS_LABELS[key], body))
if len(items) == 1:
label, body = items[0]
return [f"On {label}: {body[0]}", *body[1:], ""]
return markup.tabs(items)
def data_root_words(text: str, href: str = "#data-folder") -> str:
"""Prose that names the field data_root, linked to the folder it holds:
ten pages told readers "given in data_root"."""
return re.sub(r"\bdata_root\b", f"[the data folder]({href})", text)
def _platform_install_block(name: str, display: str, on_card: bool = False) -> list[str]:
"""The platform's pack, installed file by file: what the ZIP holds, with
resume, verification and only what is missing.
``on_card``: the files go on the frontend's SD card, installed from the
computer it is mounted on, whose root is named.
"""
if on_card:
return markup.details("tip", "Install with one command", [
f"With the {display} SD card mounted, the installer downloads the files "
"of the pack that are missing or differ from it into `Bios/<TAG>/` on "
"the card, checks each one, and resumes where it stopped. `--dest` "
"names the card's root.",
"",
"Linux, macOS:",
"",
*fence("sh", install_command("sh", f"--platform {name} --dest /path/to/card")),
"",
"Windows (PowerShell, E: being the card):",
"",
*fence("powershell", install_command("powershell", f"--platform {name} --dest E:\\")),
], opened=True)
return markup.details("tip", "Install with one command", [
f"The installer downloads the files of the {display} pack that are "
"missing or differ from it, checks each one, and resumes where it "
"stopped. Add `--system` with the ids of the systems overview below "
"to install fewer systems.",
"",
*install_commands(f"--platform {name}"),
], opened=True)
def _ps_quote(value: str) -> str:
"""A PowerShell argument: bare when plain, single-quoted otherwise."""
return value if re.fullmatch(r"[\w.+-]+", value) else "'" + value.replace("'", "''") + "'"
# The OS tabs of a system's install box: labels the site's other command
# tabs use, so the reader's choice carries from page to page.
INSTALL_PICKER_OSES = ("windows", "macos", "linux", "steamdeck")
def _install_args(platform: str, system: str, shell: str) -> str:
quoted = _ps_quote(system) if shell == "powershell" else shlex.quote(system)
return f"--platform {platform} --system {quoted}"
def _default_setup(declared: list[tuple[str, str]]) -> tuple[str, str]:
"""The setup an install box shows before the reader picks one.
The first in alphabetical order was AmberELEC on 17 system pages, a
handheld system under a Windows tab. The box shows the setup whose
command runs under the most of its tabs (the guide's `run`), then on the
most systems overall, then one the release publishes a ZIP for.
"""
def reach(pair: tuple[str, str]) -> tuple[int, int, bool]:
runs = GUIDES[pair[0]].run if pair[0] in GUIDES else ()
return (len(set(runs) & set(INSTALL_PICKER_OSES)), len(runs), has_release_pack(pair[0]))
return max(declared, key=reach)
def _install_picker(declared: list[tuple[str, str]]) -> list[str]:
"""One command, for the setup the reader picks, under the OS tabs.
Every setup's command for a console was written out, twice: 12 long
lines for the PSP, about 360 page elements once highlighted. The
picker shows one and the script (site.ts) rewrites it for the setup
chosen, remembered from page to page. Without the script the picker
stays hidden and the plain list of every command shows, open.
"""
def attribute(text: str) -> str:
# Quotes kept as written: a system id quoted for the shell ('Neo Geo').
return html.escape(text, quote=False).replace('"', "&quot;")
names = Counter(platform for platform, _system in declared)
lead = _default_setup(declared)
options = "".join(
f'<option value="{attribute(platform)}"'
+ (" selected" if (platform, system) == lead else "")
+ f' data-sh="{attribute(_install_args(platform, system, "sh"))}" '
f'data-ps="{attribute(_install_args(platform, system, "powershell"))}">'
+ html.escape(_platform_display(platform) + (f" ({system})" if names[platform] > 1 else ""),
quote=False)
+ "</option>"
for platform, system in declared)
args = {key: _install_args(*lead, TERMINALS[key][2]) for key in INSTALL_PICKER_OSES}
return [
"Each platform names the system its own way.",
"",
'<div class="rb-install" data-rb-install="" hidden>',
"",
f'<label class="rb-install-setup">Setup <select>{options}</select></label>',
"",
*terminal_tabs(INSTALL_PICKER_OSES, args, steps=False),
"",
"</div>",
"",
# Each command as inline code, no highlighting: the list is the
# fallback and the reference, and highlighted it was most of the
# box's elements.
'<details class="rb-install-all" open>',
"<summary>Every setup's command</summary>",
"",
*_command_list("Terminal (Linux, macOS, Steam Deck):", declared, "sh"),
*_command_list("PowerShell (Windows):", declared, "powershell"),
"</details>",
]
def _command_list(label: str, declared: list[tuple[str, str]], shell: str) -> list[str]:
"""Every setup's command for one shell, a line each, with a copy button.
Inline HTML code, so no break element is added at each slash. A break
point follows the URL's scheme: the Markdown around the code made the
bare URL a link inside the command, and a scheme with nothing after it
is no link. The break adds no character to a copy."""
def command(platform: str, system: str) -> str:
text = html.escape(install_command(shell, _install_args(platform, system, shell)), quote=False)
return text.replace("://", "://<wbr>")
# One HTML line: the glossary leaves HTML alone, and it marked a word
# inside a command.
names = Counter(platform for platform, _system in declared)
items = "".join(
f"<li>{html.escape(_platform_display(platform), quote=False)}"
+ (f" ({html.escape(system, quote=False)})" if names[platform] > 1 else "")
+ f': <code data-copy="">{command(platform, system)}</code></li>'
for platform, system in declared)
return [label, "", f"<ul>{items}</ul>", ""]
def _console_install_block(console: str, declared: list[tuple[str, str]]) -> list[str]:
"""Each platform's command for one console, by the system id it gives it,
for a terminal and for PowerShell, each under its setup's name: RetroBat
had two lines and nothing said which was for the Neo Geo."""
if not declared:
return []
sh = [line for platform, system in declared for line in (
f"# {_platform_display(platform)}",
install_command("sh", f"--platform {platform} --system {shlex.quote(system)}"))]
ps = [line for platform, system in declared for line in (
f"# {_platform_display(platform)}",
install_command("powershell", f"--platform {platform} --system {_ps_quote(system)}"))]
# The name last: "Install the Atari System 1 files" read as a count. A
# label naming files already reads "Install these files": "Install
# the files of Other arcade files".
summary = ("Install these files" if console.casefold().endswith(" files")
else f"Install the files of {console}")
if markup.starlight() and len(declared) > 1:
return search_excluded(markup.details("tip", summary, _install_picker(declared)))
return search_excluded(markup.details("tip", summary, [
"Each platform names the system its own way.",
"",
"Linux, macOS, Steam Deck:",
"",
*fence("sh", "\n".join(sh)),
"",
"Windows (PowerShell):",
"",
*fence("powershell", "\n".join(ps)),
]))
+594
View File
@@ -0,0 +1,594 @@
"""The file lookup: records of every copy, data member and retired file, in shards."""
from __future__ import annotations
import json
import re
import sys
import urllib.request
import zipfile
from pathlib import Path
from model import siteinputs
from model.collection import _slug
from model.systemnames import system_name
from packs.crossref import FileConsumers
from sitegen.cards import _PROVENANCE_LABELS, _emulator_card_anchor, emulator_file_anchors
from sitegen.config import SITE_URL, _REPO_ROOT
from sitegen.render import _code, _slugify_anchor, card_page, emulator_card_page
from sitegen.write import write_if_changed
HASH_ALGORITHMS = ("sha1", "sha256", "md5", "crc32")
def _hash_values(value: object) -> list[str]:
"""Every accepted value of one hash field, lowercase.
A field holds one value, a list of accepted revisions, or (Recalbox) a
comma-joined string: an exact lookup missed all but the first form.
"""
if value is None:
return []
items = value if isinstance(value, (list, tuple)) else str(value).split(",")
return sorted({str(item).strip().lower() for item in items if str(item).strip()})
def _site_path(markdown_target: str) -> str:
"""A page link as generators write it (systems/sony.md#psx) as a
site-absolute path (/retrobios/systems/sony/#psx), which resolves the same
from any document that holds it."""
page, _, anchor = markdown_target.partition("#")
base = urllib.parse.urlsplit(SITE_URL).path
page = page.removesuffix(".md")
page = "" if page == "index" else page.removesuffix("/index") + "/"
return f"{base}{page}" + (f"#{anchor}" if anchor else "")
# System pages
def generate_files_page() -> str:
"""Find a file by any of its hashes: files/?hash=<value>.
site.js reads the one shard of api/v1/lookup/ the value names and lists
every page that cites it. files/?sha1=<sha1> is the card's permanent
address and opens the card directly.
"""
return "\n".join([
"---",
"terms: check my dump, md5 check, verify bios file, check hash, "
"is my bios correct, is my bios right",
"---",
"",
"# Find or check a file",
"",
"Check a BIOS dump: paste its hash or choose the file.",
"",
"A hash is a fingerprint of a file's contents ([Glossary](../wiki/glossary.md)). "
"Tools such as clrmamepro and RomVault print one, and so do emulator logs "
"and the BIOS lists of setups.",
"",
"Paste it below, alone or in the line md5sum or certutil prints. The page "
"shows the file in the collection that has it, the setups that list it and "
"the emulators that check for it.",
"",
'<form class="rb-file-lookup" action="./" method="get">',
'<label for="rb-hash">SHA1, MD5, CRC32 or SHA256</label> ',
# No pattern: the line md5sum or certutil prints is taken whole, and
# the page reads the hash out of it.
'<input id="rb-hash" name="hash" size="66" autocomplete="off" spellcheck="false" '
'required> ',
'<button type="submit">Find</button>',
"</form>",
"",
'<p id="rb-file-lookup-status" role="status"></p>',
"",
"To try it, paste `0555c6fae8906f3f09baf5988f00e55f88e9f30b`, the SHA1 of "
"`scph5501.bin`, the PlayStation BIOS v3.0. "
"To look a file up by its name, use the search at the top of the page.",
"",
"Have a file the collection lacks? [See if it is wanted](../wanted.md).",
"",
"## Permanent links",
"",
"A file's card lives on its manufacturer's page, and a file refiled "
"between manufacturers moves with it. `files/?sha1=<sha1>` is the address "
"that does not move: it opens the card wherever it is now. The link icon "
"beside each card's name is that address. A file that left the "
"collection keeps it: the page says when, and opens the card of the "
"file in its place.",
"",
"## The index behind it",
"",
"The lookup reads one file of [`api/v1/lookup/`](../data.md), named by the "
"first two characters of the hash: one of 256, never the whole index. "
"[`api/v1/file-locations.json`](../api/v1/file-locations.json) lists every "
"card by SHA1 in one file.",
"",
])
def data_directory_members(install_dir: Path = _REPO_ROOT / "install") -> dict[str, dict[str, dict]]:
"""Each data directory's files with their sha1 and size, as the install
manifests record them for the installer to check."""
members: dict[str, dict[str, dict]] = {}
for path in sorted(install_dir.glob("*.json")):
manifest = json.loads(path.read_text(encoding="utf-8"))
for tree in manifest.get("data_directories") or []:
members.setdefault(str(tree.get("ref", "")), {}).update(tree.get("files") or {})
return members
def data_directory_revisions(data_dir: Path = _REPO_ROOT / "data") -> dict[str, dict]:
"""The revision each data directory was fetched at, as refresh_data_dirs records it."""
path = data_dir / ".versions.json"
if not path.is_file():
return {}
return json.loads(path.read_text(encoding="utf-8"))
_GIT_COMMIT = re.compile(r"[0-9a-f]{40}")
_GITHUB_REPO = re.compile(r"https://github\.com/([^/]+/[^/]+)/")
def data_directory_origin(entry: dict, fetched: dict) -> list[str]:
"""Where a data directory is fetched from, and the commit the packs hold.
The URL is written with the `{version}` refresh_data_dirs substitutes:
printed raw it led to a 404. A zip source records the server's ETag,
which names no revision anyone can fetch, so only a git commit is shown.
"""
lines = []
url = str(entry.get("source_url") or "")
if url:
url = url.replace("{version}", str(entry.get("version", "master")))
lines.append(f"Fetched from <{url}>")
sha = str(fetched.get("sha", "")).strip('"')
if _GIT_COMMIT.fullmatch(sha):
repo = _GITHUB_REPO.match(url)
commit = f"[{_code(sha[:12])}](https://github.com/{repo.group(1)}/commit/{sha})" \
if repo else _code(sha)
branch = str(fetched.get("version", ""))
lines.append(f"Revision: {commit}" + (
f", the head of `{branch}` when fetched" if branch and branch != sha else ""))
return lines
def page_data_directories(name: str, profiles: dict) -> list[dict]:
"""The data directories an emulator page lists.
Its own, then those of the aliases that point at it: an alias has no
page, and the 90 FreeIntv overlays its profile declares were linked to
emulators/freeintv_ts_overlay/, a page that does not exist.
"""
trees = [t for t in profiles[name].get("data_directories") or [] if isinstance(t, dict)]
refs = {str(t.get("ref", "")) for t in trees}
for alias in sorted(profiles):
profile = profiles[alias]
if profile.get("type") != "alias" or profile.get("alias_of") != name:
continue
for tree in profile.get("data_directories") or []:
ref = str(tree.get("ref", ""))
if isinstance(tree, dict) and ref not in refs:
refs.add(ref)
trees.append(tree)
return trees
def _data_member_owners(profiles: dict) -> dict[str, str]:
"""The emulator page that lists each data directory, the first by name.
Only a profile that has a page can own one.
"""
owners: dict[str, str] = {}
for name in sorted(profiles):
if profiles[name].get("type") == "alias" or profiles[name].get("role") == "test":
continue
for tree in page_data_directories(name, profiles):
owners.setdefault(str(tree.get("ref", "")), name)
return owners
def file_location_items(
db: dict, profiles: dict | None = None, members: dict | None = None
) -> list[dict]:
"""Each held file's card, keyed by its sha1.
A card lives on its manufacturer's page, and a file refiled between
manufacturers (mt32_control.rom, Commodore to Roland) moved its link
with it. files/?sha1= reads this list and goes to the card wherever it
is now: the address cited depends on the content only. The url is
site-absolute (/retrobios/systems/...): written from the site root, it
resolved against the document holding it to a page that does not exist.
"""
items = []
for sha1, entry in sorted(db.get("files", {}).items()):
parts = entry.get("path", "").split("/")
if len(parts) < 3 or parts[0] != "bios":
continue
page = card_page(entry.get("path", ""), sha1)
items.append({"sha1": sha1, "url": _site_path(f"systems/{page}.md#sha1-{sha1[:12]}")})
# A data directory's files are listed on the page of an emulator reading
# the tree: 2,534 hashes the packs ship were found nowhere on the site.
owners = _data_member_owners(profiles or {})
known = {item["sha1"] for item in items}
for ref, files in sorted((members or {}).items()):
if ref not in owners:
continue
# A large tree is listed on pages of its own (data_tree_pages).
page_of = {member: stem for stem, names in data_tree_pages(ref, files)
for member in names}
for member, info in sorted(files.items()):
sha1 = str(info.get("sha1", ""))
if sha1 and sha1 not in known:
known.add(sha1)
page = page_of.get(member, owners[ref])
items.append({"sha1": sha1,
"url": _site_path(f"emulators/{page}.md#sha1-{sha1[:12]}")})
return sorted(items, key=lambda item: item["sha1"])
LOOKUP_PREFIX = 2 # hex characters naming a lookup shard: 256 files
def _lookup_system_name(sys_id: str) -> str | None:
"""The system's name as every page prints it, None for an id the site
cannot name. The Find a file page reads it, and never builds one."""
try:
return system_name(sys_id)
except KeyError:
return None
def _console_system_names(profiles: dict, coverages: dict) -> dict[tuple[str, str], str]:
"""(manufacturer slug, console folder) -> the name of the system whose
own section that folder is: a collection file is named after the console
it is filed under. A folder no id owns, or that two names own, is left out.
"""
from model.systemnames import _own_section
from sitegen.render import system_ids
found: dict[tuple[str, str], set[str]] = {}
for sys_id in system_ids(profiles, [c["config"] for c in coverages.values()]):
own = _own_section(sys_id)
if own is not None:
found.setdefault((_slug(own[0]), own[1]), set()).add(system_name(sys_id))
return {key: next(iter(names)) for key, names in found.items() if len(names) == 1}
def _data_member_digests(
members: dict, data_registry: dict | None = None, root: Path = _REPO_ROOT,
) -> dict[str, dict[str, str]]:
"""sha1 -> every hash the lookup takes, for each data directory member
whose copy in the tree's local cache has the sha1 the manifest records.
The manifests carry sha1 alone: the MD5 of Dolphin's ApprovedInis.json
found nothing although the pack ships it."""
from model.registry import load_data_dir_registry
from core.hashing import compute_hashes
if data_registry is None:
data_registry = load_data_dir_registry(str(siteinputs.current().platforms))
found: dict[str, dict[str, str]] = {}
for ref, tree in sorted(members.items()):
cache = (data_registry.get(ref) or {}).get("local_cache")
if not cache:
continue
for member, info in sorted(tree.items()):
sha1 = str(info.get("sha1", ""))
path = root / cache / member
if not sha1 or sha1 in found or not path.is_file():
continue
digests = compute_hashes(path, frozenset(HASH_ALGORITHMS))
if digests.get("sha1") == sha1:
found[sha1] = {algo: digests[algo].lower() for algo in HASH_ALGORITHMS}
return found
def retired_records(retired: dict[str, dict], files: dict, locations: list[dict]) -> list[dict]:
"""A record for each hash of a file that left the collection.
Its address (files/?sha1=, #sha1-<12>) was published and answered that
no file the site knows has the hash, inviting a contribution of a file
the collection held. The record says when it left, and leads to the
card of the file holding its place, followed to the one held today.
"""
cards = {item["sha1"]: item["url"] for item in locations}
records: list[dict] = []
for sha1, record in sorted(retired.items()):
if sha1 in files:
continue
successor, seen = record.get("successor"), {sha1}
while successor and successor not in files and successor not in seen:
seen.add(successor)
successor = (retired.get(successor) or {}).get("successor")
url = cards.get(successor) if successor in files else None
extra: dict[str, object] = {"left": str(record["left"])}
if url:
extra["successor"] = successor
else:
# The page its card was on: the reader lands among its neighbours.
url = _site_path(f"systems/{card_page(str(record.get('path', '')), sha1)}.md")
for algorithm in HASH_ALGORITHMS:
value = sha1 if algorithm == "sha1" else record.get(algorithm)
records.extend({"value": one, "algorithm": algorithm, "layer": "retired",
"name": str(record.get("name", "")), "sha1": sha1,
"url": url, **extra} for one in _hash_values(value))
return records
def _archive_member_records(entry: dict, sha1: str, url: str,
root: Path = _REPO_ROOT) -> list[dict]:
"""The CRC32 of each member of a collection archive, read from its
central directory.
A pasted CRC of a ROM the collection holds only inside a set (logica2.u2
in a500.zip, 8484f426) found nothing: 26,014 of 33,403 members were in
no record. The record leads to the archive's card and names it.
"""
path = root / str(entry.get("path", ""))
if path.suffix.lower() != ".zip" or not path.is_file():
return []
try:
with zipfile.ZipFile(path) as archive:
members = [(info.filename, info.CRC) for info in archive.infolist()
if not info.is_dir()]
except (OSError, zipfile.BadZipFile) as exc:
print(f" WARNING: {path}: members unreadable ({exc})", file=sys.stderr)
return []
return [{"value": f"{crc:08x}", "algorithm": "crc32", "layer": "archive-member",
"name": member.rsplit("/", 1)[-1], "archive": str(entry.get("name", "")),
"sha1": sha1, "url": url}
for member, crc in members]
def _collection_lookup_records(
files: dict, named: dict, locations: list[dict], members: dict,
) -> list[dict]:
"""The collection's own files and the data directory members, each
value leading to the file's card."""
member_names = {
str(info.get("sha1", "")): member.rsplit("/", 1)[-1]
for tree in members.values() for member, info in sorted(tree.items())
}
member_digests = _data_member_digests(members)
records: list[dict] = []
for item in locations:
sha1 = item["sha1"]
entry = files.get(sha1)
if entry is None:
# A data directory member: the manifests record its sha1, the
# tree on disk the other three.
digests = member_digests.get(sha1) or {"sha1": sha1}
records.extend({"value": digests[algorithm], "algorithm": algorithm,
"layer": "data-directory", "name": member_names.get(sha1, ""),
"sha1": sha1, "url": item["url"]}
for algorithm in HASH_ALGORITHMS if algorithm in digests)
continue
parts = str(entry.get("path", "")).split("/")
held_by = named.get((_slug(parts[1]), parts[2])) if len(parts) > 3 else None
for algorithm in HASH_ALGORITHMS:
records.extend({
"value": value, "algorithm": algorithm, "layer": "collection",
"name": str(entry.get("name", "")), "sha1": sha1, "url": item["url"],
**({"system_name": held_by} if held_by else {}),
} for value in _hash_values(entry.get(algorithm)))
records += _archive_member_records(entry, sha1, item["url"])
return records
def _platform_lookup_records(coverages: dict, consumers: FileConsumers | None) -> list[dict]:
"""A platform's declared values, each leading to the system section of
its page."""
records: list[dict] = []
for key, coverage in sorted(coverages.items()):
for system_id, system in sorted((coverage["config"].get("systems") or {}).items()):
url = _site_path(f"platforms/{key}.md#{system_id.replace(' ', '-')}")
system_label = _lookup_system_name(system_id)
for entry in system.get("files") or []:
# A hash of a ROM inside the archive (zipped_file) designates
# no collection file by itself: the archive holding it is the one.
archive = (consumers.sha1_of(entry)
if consumers is not None and entry.get("zipped_file") else None)
for algorithm in HASH_ALGORITHMS:
records.extend({
"value": value, "algorithm": algorithm, "layer": "platform",
"owner": key, "name": str(entry.get("name", "")), "url": url,
**({"system_name": system_label} if system_label else {}),
**({"sha1": archive} if archive else {}),
} for value in _hash_values(entry.get(algorithm)))
return records
def _emulator_lookup_records(profiles: dict) -> list[dict]:
"""A profile's declared values, each leading to the entry's card."""
records: list[dict] = []
for key, profile in sorted(profiles.items()):
if profile.get("type") == "alias" or profile.get("role") == "test":
continue
entries = profile.get("files") or []
own_systems = [str(s) for s in profile.get("systems") or []]
for entry, anchor in zip(entries, emulator_file_anchors(entries)):
url = _site_path(f"emulators/{emulator_card_page(key, anchor)}.md#{anchor}")
sys_id = str(entry.get("system") or "") or (
own_systems[0] if len(own_systems) == 1 else "")
entry_label = _lookup_system_name(sys_id) if sys_id else None
holders = [(str(entry.get("name", "")), entry)] + [
(str(member["name"]), member) for member in entry.get("contents") or []
if isinstance(member, dict) and member.get("name")
]
for name, holder in holders:
for algorithm in HASH_ALGORITHMS:
records.extend({
"value": value, "algorithm": algorithm, "layer": "emulator",
"owner": key, "name": name, "url": url,
**({"system_name": entry_label} if entry_label else {}),
} for value in _hash_values(holder.get(algorithm)))
return records
def file_lookup_records(
db: dict,
coverages: dict,
profiles: dict,
locations: list[dict],
members: dict | None = None,
consumers: FileConsumers | None = None,
retired: dict | None = None,
wanted: list[dict] | None = None,
) -> list[dict]:
"""Every hash the site knows, one record per value, for files/?hash=.
The collection's own files lead to their card, a platform's declared
value to the system section of its page, a profile's to the entry's
card, a wanted dump (``wanted``, the provenance-wanted.csv rows) to
its catalog on the provenance page. The site search indexed these values as text, 4 MB of the 21 MB
it made every visitor download: the lookup reads one shard instead.
"""
files = db.get("files", {})
named = _console_system_names(profiles, coverages)
records = _collection_lookup_records(files, named, locations, members or {})
records += _platform_lookup_records(coverages, consumers)
records += _emulator_lookup_records(profiles)
records += retired_records(retired or {}, files, locations)
records += wanted_records(wanted or [])
records += _held_under_every_hash(records, files, db.get("indexes") or {})
for record in records:
if record["layer"] in ("platform", "emulator"):
record.setdefault("declared", record["algorithm"])
if consumers is not None:
records += _read_by_name(records, files, consumers)
unique = {json.dumps(r, sort_keys=True): r for r in records}
return sorted(unique.values(), key=lambda r: (
r["value"], r["layer"], r.get("owner", ""), r["name"], r["url"]))
def wanted_records(rows: list[dict]) -> list[dict]:
"""A record under each hash of a dump a catalog lists and the collection
lacks, from the rows of provenance-wanted.csv. A pasted hash of a
wanted dump (Redump's ps2-dvd-212k.bin) answered that nothing the site
knows has it, and never said the dump is wanted."""
records = []
for row in rows:
label = _PROVENANCE_LABELS.get(row["catalog"], row["catalog"])
url = _site_path(f"provenance.md#{_slugify_anchor(label)}")
for algorithm in ("sha1", "md5", "crc32"):
value = str(row.get(algorithm) or "").lower()
if value:
records.append({"value": value, "algorithm": algorithm, "layer": "wanted",
"owner": label, "name": row["name"], "url": url})
return records
def _read_by_name(records: list[dict], files: dict, consumers: FileConsumers) -> list[dict]:
"""The emulators the file's card names that no declared hash reached.
The card counts every profile entry resolving to the file, by name
included: scph5501.bin named 11 emulators on its card and 9 in the
lookup, PCSX-ReARMed and PCSX1 reading it by name. Each is written under
every hash of the file, `declared` saying no hash was.
"""
reached = {(r["sha1"], r["owner"]) for r in records
if r["layer"] == "emulator" and r.get("sha1")}
added: list[dict] = []
for sha1, emulators in sorted(consumers.emulators.items()):
entry = files.get(sha1)
if entry is None:
continue
for emulator in sorted(emulators):
if (sha1, emulator) in reached:
continue
index = consumers.emulator_entries.get(sha1, {}).get(emulator)
entries = consumers.emulator_files.get(emulator) or []
if index is None or index >= len(entries):
continue
anchor = _emulator_card_anchor(emulator, entries, index)
url = _site_path(f"emulators/{emulator_card_page(emulator, anchor)}.md#{anchor}")
name = str(entries[index].get("name", ""))
for algorithm in HASH_ALGORITHMS:
added.extend({
"value": value, "algorithm": algorithm, "layer": "emulator",
"owner": emulator, "name": name, "url": url, "sha1": sha1,
"declared": "name",
} for value in _hash_values(entry.get(algorithm)))
return added
def _collection_sha1(files: dict, indexes: dict, algorithm: str, value: str) -> str | None:
"""The collection file a declared value designates, None when none does."""
if algorithm == "sha1":
return value if value in files else None
found = indexes.get(f"by_{algorithm}", {}).get(value)
if isinstance(found, list):
found = found[0] if len(found) == 1 else None
return found if found in files else None
def _held_under_every_hash(records: list[dict], files: dict, indexes: dict) -> list[dict]:
"""A platform or emulator record whose value designates a collection
file, written under the file's other hashes too.
Batocera lists scph5501.bin by md5: pasted by its sha1, the file showed
no setup at all. Each record now carries the file's sha1, and
``declared`` names the hash its owner wrote when the record is a copy.
"""
copies: list[dict] = []
for record in records:
if record["layer"] not in ("platform", "emulator"):
continue
sha1 = record.get("sha1") or _collection_sha1(
files, indexes, record["algorithm"], record["value"])
if sha1 not in files:
continue
record["sha1"] = sha1
for algorithm in HASH_ALGORITHMS:
copies.extend({**record, "value": value, "algorithm": algorithm,
"declared": record["algorithm"]}
for value in _hash_values(files[sha1].get(algorithm))
if value != record["value"])
return copies
def write_lookup_shards(
api: Path, records: list[dict], generated_at: str, commit: str = "",
) -> int:
"""One envelope per leading pair of hex characters, as the lookup asks.
A value that is not hexadecimal (a typo in a profile) has no shard the
lookup would read, and is left out. Returns the number of shards.
"""
shards: dict[str, list[dict]] = {}
for record in records:
if re.fullmatch(r"[0-9a-f]{8,}", record["value"]):
shards.setdefault(record["value"][:LOOKUP_PREFIX], []).append(record)
folder = api / "lookup"
folder.mkdir(parents=True, exist_ok=True)
for prefix, items in sorted(shards.items()):
write_if_changed(str(folder / f"{prefix}.json"), json.dumps({
"schema_version": 1,
"generated_at": generated_at,
**({"commit": commit} if commit else {}),
"kind": "file-lookup",
"count": len(items),
"items": items,
}, ensure_ascii=False, separators=(",", ":"), sort_keys=True) + "\n")
return len(shards)
# A data directory listing more files than this goes to pages of its own,
# this many files each: Dolphin's Sys tree put 2,164 rows and 16,900
# elements on the Dolphin page, read on a phone.
DATA_TREE_ROWS = 400
DATA_TREE_ROWS_PER_PAGE = 1_000
def data_tree_pages(ref: str, members: dict[str, dict]) -> list[tuple[str, list[str]]]:
"""The pages under emulators/ listing a large data directory, with the
members each holds in name order, or none when the tree is listed on
the pages of the emulators reading it."""
if len(members) <= DATA_TREE_ROWS:
return []
names = sorted(members)
stem = f"data-{_slugify_anchor(ref)}"
return [(stem + (f"-{n}" if n > 1 else ""), names[start:start + DATA_TREE_ROWS_PER_PAGE])
for n, start in enumerate(range(0, len(names), DATA_TREE_ROWS_PER_PAGE), 1)]
+247
View File
@@ -0,0 +1,247 @@
"""The site navigation, from the wiki tabs and the generated sections."""
from __future__ import annotations
import re
from collections.abc import Iterator
from pathlib import Path
from model.collection import _slug
from model.composition import GAME_DATA_TOPS
from model.guides import DEVICE_GROUPS, GROUP_TILES, HANDHELD_GUIDE
from model.profiles import unique_emulator_profiles
from sitegen import measurements as sitemeasurements, starlight as sitestarlight
from sitegen.config import _REPO_ROOT
from sitegen.decorate import _front_matter
from sitegen.emulatorsindex import INITIAL_DIGITS, emulator_initial
from sitegen.render import WIKI_SRC_DIR
def nav_emulators(profiles: dict) -> dict[str, dict]:
"""The emulators listed in the navigation, by key.
A profile that emulates no system and reads no file (the libretro sample
and test cores, games with nothing to load) answers no question about
BIOS files. Its page stays, reachable from the overview table and the
search, and the navigation is left to the cores people look up.
"""
return {
key: profile for key, profile in unique_emulator_profiles(profiles).items()
if profile.get("systems") or profile.get("files")
}
def _emulator_nav(profiles: dict) -> list:
"""Emulators by initial (A, B, C), one level deep. A name that does not
open on a letter goes under "0 to 9". The route middleware draws every
initial but the open one as a single link, so a page carries the links
of one initial only."""
groups: dict[str, list[tuple[str, str]]] = {}
for key, profile in nav_emulators(profiles).items():
display = str(profile.get("emulator", key))
groups.setdefault(emulator_initial(display), []).append((display, f"emulators/{key}.md"))
nav: list = ["emulators/index.md"]
for label in sorted(groups, key=lambda g: (g != INITIAL_DIGITS, g)):
items = sorted(groups[label], key=lambda e: e[0].casefold())
nav.append({label: [{display: path} for display, path in items]})
return nav
def _system_nav(manufacturers: dict) -> list:
"""Manufacturer pages, the machines apart from the arcade boards and the
game and engine trees: an arcade page's crumb read "Consoles and
computers"."""
machines: list[dict] = []
arcade: list[dict] = []
games: list[dict] = []
for mfr in sorted(manufacturers, key=str.casefold):
entry = {mfr: f"systems/{_slug(mfr)}.md"}
if mfr in GAME_DATA_TOPS:
games.append(entry)
else:
(arcade if mfr == "Arcade" else machines).append(entry)
nav: list = ["systems/index.md", {"Consoles and computers": machines}]
if arcade:
nav.append({"Arcade": arcade})
if games:
nav.append({"Game engines and PC games": games})
return nav
def _platform_nav(coverages: dict, registry: dict) -> list:
"""Platforms by the kind of device they run on, as on the device picker."""
nav: list = ["platforms/index.md"]
for group, (label, _description) in DEVICE_GROUPS.items():
members = [
{coverages[name]["platform"]: f"platforms/{name}.md"}
for name in sorted(coverages, key=lambda n: coverages[n]["platform"].casefold())
if registry.get(name, {}).get("device_group") == group
]
# The handheld guide sits with the group whose tile leads to it.
members += [{HANDHELD_GUIDE.title: HANDHELD_GUIDE.path}
for tile in GROUP_TILES.get(group, ())
if HANDHELD_GUIDE and tile.link == HANDHELD_GUIDE.path]
if members:
nav.append({label: members})
return nav
# The tabs in reading order, by the level their pages declare.
TABS = {
"start": "Start here",
"setup": "Setups",
"explore": "Explore",
"reference": "Reference",
"contribute": "Contribute",
}
class NavError(ValueError):
"""A wiki page does not say where it goes in the navigation."""
def _h1(markdown: str) -> str:
match = re.search(r"^# (.+?)(?:\s*\{[^}]*\})?\s*$", markdown, re.M)
return match.group(1).strip() if match else ""
NavPlace = tuple[int, object, str]
def wiki_nav(wiki_dir: Path | None = None) -> dict[str, list[NavPlace]]:
"""Wiki pages by tab, each at the place its front matter gives.
A page states `level:` (its tab), `order:` (its place in the tab, the
smallest first) and, when the navigation names it otherwise than its
first heading, `nav_title:`. `group:` files it under a labelled group
of its tab. `nav: false` keeps a page out on purpose. A page that says
neither raises, naming what to add.
"""
wiki_dir = Path(wiki_dir) if wiki_dir else _REPO_ROOT / WIKI_SRC_DIR
tabs: dict[str, list[NavPlace]] = {level: [] for level in TABS}
for page in sorted(wiki_dir.glob("*.md")):
where = f"{WIKI_SRC_DIR}/{page.name}"
text = page.read_text(encoding="utf-8")
meta = _front_matter(text)
level = meta.get("level")
if level not in TABS:
raise NavError(
f"{where}: front matter needs `level:`, one of {', '.join(TABS)}, "
f"to place the page in a tab (found {level!r})"
)
if meta.get("nav") is False:
continue
order = meta.get("order")
if not isinstance(order, int) or isinstance(order, bool):
raise NavError(
f"{where}: front matter needs `order:`, a whole number giving its "
f"place in the {TABS[level]} tab, smallest first (found {order!r}), "
"or `nav: false` to keep it out of the navigation"
)
path = f"{WIKI_SRC_DIR}/{page.name}"
if page.name == "index.md":
tabs[level].append((order, path, ""))
continue
title = meta.get("nav_title") or _h1(text)
if not title:
raise NavError(f"{where}: no `# ` heading and no `nav_title:` to name it")
group = meta.get("group") or ""
if not isinstance(group, str):
raise NavError(f"{where}: `group:` names a group of the {TABS[level]} tab (found {group!r})")
tabs[level].append((order, {str(title): path}, group))
return tabs
def _overview_anchors(nav: list, docs: Path) -> dict[str, set[str]]:
"""The heading ids of each overview page the navigation names, where a
group of the sidebar finds its own section."""
def overviews(value: object) -> Iterator[str]:
if isinstance(value, str):
yield value
elif isinstance(value, list):
for entry in value:
yield from overviews(entry)
elif isinstance(value, dict):
for child in value.values():
if isinstance(child, list):
yield from overviews(child)
anchors: dict[str, set[str]] = {}
for rel in overviews(nav):
stem = rel.rsplit(".", 1)[0]
page = next((docs / f"{stem}{suffix}" for suffix in (".md", ".mdx")
if (docs / f"{stem}{suffix}").is_file()), None)
if page:
anchors[rel] = sitestarlight.heading_ids(page.read_text(encoding="utf-8"))
return anchors
def _nav_target(entry: str | dict) -> str:
return entry if isinstance(entry, str) else str(next(iter(entry.values())))
def generate_nav(
coverages: dict,
manufacturers: dict,
profiles: dict,
registry: dict | None = None,
wiki_dir: Path | None = None,
) -> list:
"""The navigation, five tabs in reading order.
Start here is for someone who knows nothing yet, Setups for someone
who knows their device, Explore for one system or emulator, Reference for
checking the work, Contribute for adding to it. Each tab opens on its
index page.
The generated pages hold the places below. A wiki page takes its own
place from its front matter (wiki_nav), so a new page needs no edit here.
A group of a tab sits at the place of its first page, its pages in their
own order.
"""
generated: dict[str, list[tuple]] = {
"start": [(0, "index.md"), (20, {"Get the files": "which-pack.md"})],
"setup": [(10 * i, item)
for i, item in enumerate(_platform_nav(coverages, registry or {}))],
"explore": [
(0, "explore.md"),
(10, {"Systems": _system_nav(manufacturers)}),
(20, {"Emulators": _emulator_nav(profiles)}),
],
"reference": [
# Find a file first: the one tool a reader comes to with a file in hand.
(5, {"Find or check a file": "files/index.md"}, "Checking files"),
(20, {"What the packs do not hold": "gaps.md"}, "Checking files"),
(30, {"Cores by platform": "cross-reference.md"}, "Checking files"),
(40, {"Dump provenance": "provenance.md"}, "Checking files"),
(60, {"Data and API": "data.md"}, "Data"),
(64, {"Data model": "wiki/data-model.md"}, "Data"),
(68, {"Updated platform files": "exports.md"}, "Data"),
(69, {"Measurements": sitemeasurements.EXPLORER_PAGE}, "Data"),
],
"contribute": [(0, "contributing.md"), (5, {"Wanted": "wanted.md"})],
}
wiki = wiki_nav(wiki_dir)
nav = []
for level, label in TABS.items():
places = [(place[0], place[1], place[2] if len(place) > 2 else "")
for place in generated[level]]
entries = sorted(places + wiki[level], key=lambda item: item[0])
for (first, a, _), (second, b, _) in zip(entries, entries[1:]):
if first == second:
raise NavError(
f"{label} tab: {_nav_target(a)} and {_nav_target(b)} both take "
f"order {first}; give one of them a free number"
)
items: list = []
groups: dict[str, list] = {}
for _order, entry, group in entries:
if not group:
items.append(entry)
elif group in groups:
groups[group].append(entry)
else:
groups[group] = [entry]
items.append({group: groups[group]})
nav.append({label: items})
return nav
+137
View File
@@ -0,0 +1,137 @@
"""Page budgets, and the long lists cut into parts of their own."""
from __future__ import annotations
import json
from collections.abc import Callable
from pathlib import Path
from core.paths import REPO_ROOT
from sitegen import starlight as sitestarlight
from sitegen.config import _date_line
from sitegen.decorate import _front_matter
# A platform's file lists are split by the share of a page they render to,
# in thousandths: their elements against validate_site's MAX_PAGE_ELEMENTS,
# their bytes against the 600,000 of test_site_built_gate, whichever is
# larger. Measured in Markdown characters, the lists split anew whenever
# their markup changed: rows written as tables moved 38 more systems to
# pages of their own.
PAGE_ELEMENTS = 10_000
PAGE_BYTES = 600_000
# A system whose list passes this share gets a page of its own.
PLATFORM_SECTION_BUDGET = 400
# A system's own page in runs of at most this share.
PLATFORM_PART_BUDGET = 700
# The share of a platform page's file lists, past which the largest
# systems move to pages of their own.
PLATFORM_REFERENCE_BUDGET = 600
# Every part page the site has published, with the page it belongs to:
# platforms/batocera-atari-st.md -> platforms/batocera.md#atari-st,
# gaps-files-to-source-7.md -> gaps.md. When a budget or a list changes, a
# part can fold back or the list shrink, and its address then redirects to
# that page instead of ending on the 404 page.
PUBLISHED_PARTS_FILE = (REPO_ROOT
/ "website" / "src" / "data" / "published-parts.json")
def _published_parts() -> dict[str, str]:
if not PUBLISHED_PARTS_FILE.is_file():
return {}
return json.loads(PUBLISHED_PARTS_FILE.read_text(encoding="utf-8"))
def _parent_page(link: str) -> str:
"""The page a `parent:` link names (/platforms/batocera/), under docs/."""
path, _, fragment = link.partition("#")
# Written with the site's base (/retrobios/emulators/x/) or without it.
path = path.removeprefix(sitestarlight.BASE.rstrip("/"))
stem = path.strip("/") or "index"
return f"{stem}.md" + (f"#{fragment}" if fragment else "")
def record_parts(docs: Path, present: set[str], published: dict[str, str]) -> dict[str, str]:
"""``published`` with every page of this run that names its parent.
Only platform parts were recorded: gaps-files-to-source-7 or
mame-files-10, gone once their list shrank, ended on the 404 page. A
part already recorded keeps its target, which may name a section.
"""
found = dict(published)
for rel in sorted(present):
page = docs / rel
if not page.is_file():
page = page.with_suffix(".mdx")
try:
parent = _front_matter(page.read_text(encoding="utf-8")).get("parent")
except OSError:
continue
if isinstance(parent, dict) and parent.get("link") and rel not in found:
found[rel] = _parent_page(str(parent["link"]))
return dict(sorted(found.items()))
# A list moved off a reference page (gaps, provenance) is cut in parts of
# at most this much Markdown: about 450 KB of HTML each.
LIST_PART_BUDGET = 300_000
def _characters(lines: list[str]) -> int:
return sum(len(line) + 1 for line in lines)
def _blocks_in_runs(blocks: list[list[str]], budget: int,
weigh: Callable[[list[str]], float] = _characters) -> list[list[str]]:
"""Blocks (table rows, folded lists) in runs of at most ``budget``, by
default in characters, a block never cut."""
runs: list[list[str]] = [[]]
size: float = 0
for block in blocks:
weight = weigh(block)
if runs[-1] and size + weight > budget:
runs.append([])
size = 0
runs[-1].extend(block)
size += weight
return runs
def _parent_front_matter(parent: tuple[str, str] | None) -> list[str]:
"""The `parent:` front matter of a part page: the page it belongs to,
by label and site path, which the breadcrumb and sidebar read."""
if parent is None:
return []
label, link = parent
return ["parent:", f" label: {json.dumps(label)}", f" link: {json.dumps(link)}"]
def _list_pages(
stem: str, title: str, intro: str, head: list[str], blocks: list[list[str]],
moved: dict[str, str], budget: int = LIST_PART_BUDGET,
parent: tuple[str, str] | None = None,
) -> str:
"""Pages of their own for a long list: ``head`` (a table header, say)
opens each part, ``blocks`` are cut between parts. Returns where the list
went, as the page it left says it. ``parent`` (label, site path) is the
page the parts belong to, for the breadcrumb."""
runs = _blocks_in_runs(blocks, budget)
stems = [stem + (f"-{n}" if n > 1 else "") for n in range(1, len(runs) + 1)]
for n, (here, run) in enumerate(zip(stems, runs), 1):
part = f" (part {n} of {len(runs)})" if len(runs) > 1 else ""
# The page description is the opening of the intro: parts sharing
# one read as duplicates to search and to validate_site.
opening = f"Part {n} of {len(runs)}. {intro}" if len(runs) > 1 else intro
moved[here] = "\n".join([
"---", "level: reference", *_parent_front_matter(parent), "---", "",
f"# {title}{part}", "", opening, "",
*([", ".join(f"[part {i}]({other}.md)" if other != here else f"part {i}"
for i, other in enumerate(stems, 1)), ""] if len(runs) > 1 else []),
*head, *run, "", _date_line(),
]) + "\n"
if len(stems) == 1:
return f"[a page of their own]({stems[0]}.md)"
return "pages of their own: " + ", ".join(
f"[part {i}]({other}.md)" for i, other in enumerate(stems, 1))
+217
View File
@@ -0,0 +1,217 @@
"""Which system page each system id leads to, read from the collection's folders."""
from __future__ import annotations
from dataclasses import dataclass
from model.collection import _copy_places, _slug
from resolve.localfile import resolution_is_hash_exact, resolve_local_file
from resolve.ownership import BUCKET_FOLDERS, names_manufacturer
def _copies_by_path(db: dict) -> dict[str, set[tuple[str, str, str]]]:
"""The copy places of each content, keyed by the path the database keeps."""
files = db.get("files", {})
return {
str(files[sha1].get("path", "")): where
for sha1, where in _copy_places(db).items()
}
def _system_folder(
files: list[dict],
db: dict,
name_consoles: dict[str, set[tuple[str, str]]],
sys_id: str = "",
copies: dict[str, set[tuple[str, str, str]]] | None = None,
) -> tuple[str, str] | None:
"""The bios/<manufacturer>/<console> folder a system's files live in.
A content votes for every folder holding a copy under the name the system
declares, not only the one deduplication kept: disksys.rom is kept as
Arcade/FBNeo/fdsbios.nes and filed again under Nintendo/Famicom Disk
System. A copy filed under another name, outside the manufacturer the id
names, is another machine's file and votes only when no copy carries the
declared name. An id that names its manufacturer (nintendo-fds) keeps the
votes cast inside that manufacturer when there are any, and a maker's
folder outranks the folders that file copies by emulator.
"""
if copies is None:
copies = _copies_by_path(db)
votes: dict[tuple[str, str], int] = {}
for fe in files:
local, status = resolve_local_file(fe, db)
if not local or not resolution_is_hash_exact(status):
continue
held = copies.get(local, set())
if not held:
parts = local.split("/")
if len(parts) >= 4 and parts[0] == "bios":
held = {(parts[1], parts[2], parts[-1])}
declared = str(fe.get("name", "")).casefold()
named = {
(m, c) for m, c, base in held
if base.casefold() == declared or names_manufacturer(sys_id, m)
}
for place in named or {(m, c) for m, c, _ in held}:
votes[place] = votes.get(place, 0) + 1
if votes:
own = [place for place in votes if names_manufacturer(sys_id, place[0])]
makers = [place for place in votes if place[0] not in BUCKET_FOLDERS]
candidates = own or makers or list(votes)
return max(sorted(candidates), key=lambda place: votes[place])
for fe in files:
places = name_consoles.get(fe.get("name", ""), set())
if len(places) == 1:
return next(iter(places))
return None
def _folders_by_name(manufacturers: dict) -> dict[str, set[tuple[str, str]]]:
"""Normalized system name -> the console folders that spell it.
nintendo-nes, nes and the NES folder normalize alike, as do
sega-mastersystem and Sega/Master System.
"""
from model.systems import _norm_system_id
index: dict[str, set[tuple[str, str]]] = {}
for mfr, consoles in manufacturers.items():
for console in consoles:
spelled = console.lower().replace(" ", "-")
for key in {
_norm_system_id(f"{_slug(mfr)}-{spelled}"), _norm_system_id(spelled)
}:
index.setdefault(key, set()).add((mfr, console))
return index
def _folder_named(sys_id: str, by_name: dict[str, set[tuple[str, str]]]) -> tuple[str, str] | None:
from model.systems import _norm_system_id
places = by_name.get(_norm_system_id(sys_id), set())
return next(iter(places)) if len(places) == 1 else None
def _console_norm_index(manufacturers: dict) -> dict[str, tuple[str, str]]:
"""Normalized console name index for fuzzy matching."""
console_norm: dict[str, tuple[str, str]] = {}
for mfr, consoles in manufacturers.items():
slug = mfr.lower().replace(" ", "-")
mfr_norm = mfr.lower().replace(" ", "-")
for console in consoles:
norm = console.lower().replace(" ", "-")
entry = (slug, console)
console_norm[norm] = entry
console_norm[f"{mfr_norm}-{norm}"] = entry
# Short aliases: strip common manufacturer prefix words
for prefix in (
f"{mfr_norm}-",
"nintendo-",
"sega-",
"sony-",
"snk-",
"nec-",
):
key = f"{prefix}{norm}"
console_norm[key] = entry
return console_norm
def _fuzzy_place(sys_id: str, console_norm: dict[str, tuple[str, str]]) -> tuple[str, str] | None:
"""Strategy 3: fuzzy match system_id against console directory names."""
if sys_id in console_norm:
return console_norm[sys_id]
# Try partial match: "nintendo-wii" matches "Wii" under "Nintendo"
parts = sys_id.split("-")
for i in range(len(parts)):
suffix = "-".join(parts[i:])
if suffix in console_norm:
return console_norm[suffix]
return None
@dataclass(frozen=True)
class _FolderIndex:
"""What a system is placed in a console folder by."""
db: dict
name_consoles: dict[str, set[tuple[str, str]]]
folders_by_name: dict[str, set[tuple[str, str]]]
copies: dict[str, set[tuple[str, str, str]]]
def place(self, sys_id: str, files: list) -> tuple[str, str] | None:
"""Strategy 1: the one console folder the id spells (nintendo-nes,
NES). A copy of the disk system BIOS in the NES list does not
move the NES to the folder that copy sits in.
Strategy 2: the folder holding the files the system declares,
found by content, and most votes win. A bare name stands in only
where the collection files it in a single console."""
place = _folder_named(sys_id, self.folders_by_name) or _system_folder(
files, self.db, self.name_consoles, sys_id, self.copies
)
if place is None:
return None
mfr, console = place
return (mfr.lower().replace(" ", "-"), console)
def _profile_system_pages(
profiles: dict, pages: dict[str, tuple[str, str]], index: _FolderIndex,
console_norm: dict[str, tuple[str, str]],
) -> None:
"""Systems only emulator profiles name (sega-naomi, commodore-pet): placed
by the files the profile files under them, as a platform's are. A
profile of one system files all of its entries there."""
for profile in profiles.values():
systems = [str(sid) for sid in profile.get("systems") or []]
for sys_id in systems:
if sys_id in pages:
continue
files = [
entry for entry in profile.get("files") or []
if isinstance(entry, dict)
and (entry.get("system") == sys_id or len(systems) == 1)
]
place = index.place(sys_id, files)
if place is not None:
pages[sys_id] = place
elif sys_id in console_norm:
pages[sys_id] = console_norm[sys_id]
def _system_pages_from_data(
manufacturers: dict,
coverages: dict,
db: dict,
profiles: dict | None = None,
) -> dict[str, tuple[str, str]]:
"""The system_id -> (manufacturer_slug, console_name) table.
Uses platform file paths to trace system_id -> bios directory -> manufacturer page.
"""
# Every console folder a filename sits in. A name in one folder only can
# place a system, while a name in several says nothing (MiSTer's boot.rom lives
# under a dozen consoles, and the last one written used to win).
name_consoles: dict[str, set[tuple[str, str]]] = {}
for mfr, consoles in manufacturers.items():
for console, entries in consoles.items():
for entry in entries:
name_consoles.setdefault(entry["name"], set()).add((mfr, console))
console_norm = _console_norm_index(manufacturers)
# Map system_id -> (manufacturer, console) via platform file entries
index = _FolderIndex(db, name_consoles, _folders_by_name(manufacturers), _copies_by_path(db))
pages: dict[str, tuple[str, str]] = {}
for cov in coverages.values():
config = cov["config"]
for sys_id, system in config.get("systems", {}).items():
if sys_id in pages:
continue
place = index.place(sys_id, system.get("files", [])) or _fuzzy_place(sys_id, console_norm)
if place is not None:
pages[sys_id] = place
_profile_system_pages(profiles or {}, pages, index, console_norm)
return pages
+678
View File
@@ -0,0 +1,678 @@
"""A platform's file reference: each system's rows, roles and checks."""
from __future__ import annotations
import functools
import html
import json
import re
import urllib.request
from model import siteinputs
from model.collection import _profiles_in, _profiles_on_disk
from model.profiles import upstream_profile_index
from model.systemnames import system_name
from sitegen import entries as siteentries, markup
from sitegen.cards import SHORT_HASH
from sitegen.config import REPO_URL, _REPO_ROOT, _date_line
from sitegen.fields import _hash_spans, search_excluded
from sitegen.parts import (
PAGE_BYTES,
PAGE_ELEMENTS,
PLATFORM_PART_BUDGET,
PLATFORM_REFERENCE_BUDGET,
PLATFORM_SECTION_BUDGET,
_blocks_in_runs,
_characters,
_parent_front_matter,
)
from sitegen.render import (
_code,
_count,
_emulator_link,
_escape_tags,
_fmt_size,
card_page,
console_href,
)
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))
@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 _system_heading_link(sys_id: str, prefix: str = "") -> str:
"""A system's name, linked to its own console section when it has one.
The id stays beside it in small text: it is what the platform's list
writes. A system with no section of its own is named, never sent to the
page a storage folder chose.
"""
return f"{_system_named_link(sys_id, prefix)} <small>{_escape_tags(sys_id)}</small>"
def _system_named_link(sys_id: str, prefix: str = "") -> str:
"""A system's name, linked to the section system_section gives."""
from sitegen.render import system_section
name = _escape_tags(system_name(sys_id))
section = system_section(sys_id)
if section is not None:
slug, console = section
name = f"[{name}]({console_href(slug, console, prefix)})"
return name
def _emulator_named_link(key: str, prefix: str = "") -> str:
"""An emulator by the name its page carries, linked to that page. A
profile with no page (an alias, a test) is named only."""
profile = _profiles_on_disk().get(key, {})
label = _escape_tags(str(profile.get("emulator") or key))
if profile.get("type") == "alias" or profile.get("role") == "test":
return label
return f"[{label}]({prefix}emulators/{key}.md)"
def _served_line(f: dict, declared_sha1: str = "") -> str:
"""Which collection file answers the entry, from the resolver's result.
"OK" with no path gave an expert nothing to check: Batocera's
scph1001.bin is served by bios/Sony/PlayStation/scph1001_v20.bin.
The copy's sha1 is named only when it is not one the row already
declares (Recalbox joins several with commas).
"""
path = str(f.get("path") or "")
if f.get("status") == "missing":
return "Not held"
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, "")
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":
return f"{label}: {_code(path)}"
# The card of that copy: every hash, provenance and the download.
page = urllib.parse.quote(card_page(path, sha1))
link = f"{label}: [{_code(path)}](../systems/{page}.md#sha1-{sha1[:12]})"
declared = {value.strip().lower() for value in declared_sha1.split(",")}
return link if sha1 in declared else f"{link} (sha1 `{sha1[:8]}`)"
def _launcher_refs(config: dict) -> dict[str, list[str]]:
"""Entry name, casefolded -> each launcher record that opens it, rendered."""
from resolve.launchers import _names as launcher_names
from resolve.launchers import bound_launchers
from sitegen.sources import launcher_ref_markdown, list_source
# Every scraper reads its launchers in the repository and at the revision
# of the list it scrapes, so `source` pins each source_ref. A record a
# config file does not prove opens nothing: it is listed apart.
source = list_source(str(config.get("source") or ""))
found: dict[str, list[str]] = {}
for record in bound_launchers(config):
if not isinstance(record, dict) or not record.get("source_ref"):
continue
text = (f"{_escape_tags(str(record.get('emulator', '')))} at "
f"{launcher_ref_markdown(source, str(record['source_ref']))}")
for name in launcher_names(record):
names = found.setdefault(name.rsplit("/", 1)[-1].casefold(), [])
if text not in names:
names.append(text)
return found
UNPROVEN_TITLE = "Launcher records a config does not prove"
def _launcher_unproven_section(config: dict) -> list[str]:
"""The platform's launcher records resting on a config the code does not prove.
A config file is proof only when the code installing it and the code
reading it are shown: these records place no file.
"""
from resolve.launchers import launcher_unproven
from sitegen.sources import launcher_ref_markdown, list_source
rows = launcher_unproven({str(config.get("_key") or ""): config})
if not rows:
return []
source = list_source(str(config.get("source") or ""))
body = [
f"- {_escape_tags(row['emulator'])}, `{_escape_tags(row['passes_to'] or row['kind'])}` "
f"at {launcher_ref_markdown(source, row['source_ref'])}: "
f"{_escape_tags('; '.join(row['missing']))}"
for row in rows
]
return ["", *markup.details("note", f"{UNPROVEN_TITLE} ({len(rows)})", body)]
# The hash a row shows first, when the list does not say which it checks.
_ROW_HASHES = ("sha1", "md5", "sha256", "crc32")
# An untested entry whose reason is a hash the bytes do not match.
_OTHER_HASH = re.compile(r"hash|mismatch|expected|must match", re.IGNORECASE)
# A list this long gets a filter box above it, as a table of RECORD_ROWS
# rows does (website/src/plugins/rehype-stack-tables.mjs).
FILTER_ROWS = 20
def _status_chip(f: dict) -> str:
"""The row's status as a chip, its word and its colour saying the same. A
declared hash the held copy does not have is "Other hash": the two differ,
which says nothing of whose is right (a platform may pin its own bundle)."""
status = f.get("status")
if status == "ok":
word, tone = "OK", "success"
elif status == "missing":
word, tone = "Missing", "danger"
elif status == "untested":
word = "Other hash" if _OTHER_HASH.search(str(f.get("reason") or "")) else "Untested"
tone = "warning"
else:
word, tone = str(status), "muted"
return f'<span class="rb-badge rb-badge-{tone}">{html.escape(word)}</span>'
def _copy_hash(algorithm: str, value: str | list) -> str:
"""A declared hash cut to SHORT_HASH characters on a button that copies
it whole. A list of accepted values (Recalbox) copies its first. Outside
a form a button submits nothing, so it carries no type."""
from core.hashing import parse_hash_list
values = parse_hash_list(value)
if not values:
return ""
first = html.escape(values[0])
more = f" +{len(values) - 1}" if len(values) > 1 else ""
return (f'<button class="rb-copy" data-copy="{first}" '
f'aria-label="Copy {algorithm.upper()} {first[:SHORT_HASH]}{more}">'
f'{first[:SHORT_HASH]}{more}</button>')
# Characters Markdown or MDX would read inside the raw HTML of a row: an
# MDX page parses the text of its HTML as Markdown, a .md page does not.
_INERT = str.maketrans({"*": "&#42;", "_": "&#95;", "`": "&#96;", "[": "&#91;", "]": "&#93;"})
_INLINE_MD = re.compile(
r"\[(?P<label>(?:`[^`]*`|[^\]`])+)\]\((?P<url>[^)\s]+)\)"
r"|`(?P<code>[^`]+)`"
r"|\*\*(?P<bold>[^*]+)\*\*"
)
def _text_html(text: str) -> str:
"""Plain text as HTML that neither Markdown nor MDX rewrites."""
return html.escape(html.unescape(text), quote=False).translate(_INERT)
def _inline_html(markdown: str) -> str:
"""The inline Markdown of a row's evidence (links, code, bold) as HTML.
Code spans become plain text and a linked path loses its code element:
one per reference and per reader was the bulk of the elements of a
platform page, and the words say the same without them.
"""
out: list[str] = []
position = 0
for match in _INLINE_MD.finditer(markdown):
out.append(_text_html(markdown[position:match.start()]))
if match["url"]:
out.append(f'<a href="{html.escape(match["url"])}">'
f'{_text_html(match["label"].replace("`", ""))}</a>')
elif match["code"]:
out.append(_text_html(match["code"]))
else:
out.append(f"<strong>{_text_html(match['bold'])}</strong>")
position = match.end()
out.append(_text_html(markdown[position:]))
return "".join(out)
def _row_path(fname: str, cfg_entry: dict) -> str:
"""Where the file goes, when its name alone does not say: three GameCube
IPL.bin differ only by GC/USA, GC/EUR and GC/JAP. A destination that is
the name says nothing, and one that ends with it shows its folder."""
destination = str(cfg_entry.get("destination") or "")
if destination.endswith("/" + fname):
return destination[:len(destination) - len(fname)]
return "" if destination == fname else destination
def _platform_file_row(f: dict, cfg_entry: dict, hash_type: str = "",
launched: list[str] | None = None) -> str:
"""One file of a platform's list as one row, written as HTML.
The row is a details element whose summary holds the name, the folder
when there is one and the status, followed by the short hash on its copy
button: a button cannot sit in a summary, which is itself a control.
The details hold every hash the platform declares, the size, the copy
that serves it and its readers, across the width of the list.
"""
fname = f["name"]
hashes = {
"sha1": cfg_entry.get("sha1", f.get("sha1", "")),
"md5": cfg_entry.get("md5", f.get("expected_md5", "")),
# The crc32 is what System.dat and clrmamepro print. RetroDECK
# declares sha256 too (dsifirmware.bin).
"crc32": str(cfg_entry.get("crc32") or ""),
"sha256": str(cfg_entry.get("sha256") or ""),
}
size = cfg_entry.get("size", f.get("size", 0))
shown = next((alg for alg in (hash_type, *_ROW_HASHES) if alg in hashes and hashes[alg]), "")
facts: list[str] = []
# One code element per value: Recalbox lists accepted md5s joined by
# commas, and each is a value a reader compares a dump with.
facts.extend(f"{alg.upper()}: {_hash_spans(hashes[alg])}"
for alg in ("sha1", "md5", "crc32", "sha256") if hashes[alg])
# The size closes the hash lines: a line of its own was one more
# element per row.
if size and facts:
facts[-1] += f" ({_fmt_size(size)})"
elif size:
facts.append(f"Size: {_fmt_size(size)}")
if f.get("status") == "untested" and f.get("reason"):
facts.append(_text_html(f"Not confirmed: {f['reason']}"))
# Not every entry is firmware: the platform may list a game's data or a
# file no core it runs opens.
kind = {"game_data": "Game data, not firmware",
"unread": "No core the platform runs opens it"}.get(f.get("category", ""))
if kind:
facts.append(kind)
served = _served_line(f, str(hashes["sha1"] or ""))
if served:
facts.append(_inline_html(served))
if f.get("category_evidence"):
facts.append(_inline_html(_category_evidence_md(f["category_evidence"], launched)))
path = _row_path(fname, cfg_entry)
# Spaces between name, path and status: the summary lays them out as
# columns, and the page text read "SVI603.ROMbios/Machines/...OK".
summary = " ".join([_text_html(fname), *([f"<code>{_text_html(path)}</code>"] if path else []),
_status_chip(f)])
copy = _copy_hash(shown, hashes[shown]) if shown else ""
return (f'<details class="rb-file"><summary>{summary}</summary>'
f'{"<br>".join(facts)}</details>{copy}')
def _platform_file_list(rows: list[str], has_path: bool, anchor: str) -> list[str]:
"""A system's rows as one HTML block, with a filter box when long.
The list drops its path column when no row has one, so a blank cell
never reads as missing data.
"""
lines: list[str] = []
if len(rows) >= FILTER_ROWS:
lines += [siteentries.filter_box(f"rb-files-filter-{anchor}", "files",
["File", "path", "status", "hash"], len(rows)), ""]
kind = "rb-files rb-files-path" if has_path else "rb-files"
return [*lines, f'<div class="{kind}">', *rows, "</div>"]
# The elements a line puts on the page: its HTML tags, and the links and
# code spans of the Markdown before a list.
_ELEMENT = re.compile(r"<[a-zA-Z]|\]\(|`[^`]+`")
def _element_weight(lines: list[str]) -> int:
"""How many elements the lines render to."""
return sum(len(_ELEMENT.findall(line)) for line in lines)
def _page_share(lines: list[str]) -> float:
"""The share of a page the lines render to, in thousandths: the rows
are HTML already, so their length is their weight in bytes."""
return max(_element_weight(lines) * 1000 / PAGE_ELEMENTS,
_characters(lines) * 1000 / PAGE_BYTES)
def _render_platform_systems(
by_system: dict, config_files: dict, emulator_files: dict | None,
platform: tuple[str, str] | None = None, moved: dict[str, str] | None = None,
config: dict | None = None,
) -> list[str]:
"""One collapsible block per system, listing every file it needs.
Split out of generate_platform_page: the block is most of that
function's branching, since each file renders a different set of
hashes, sizes and provenance depending on what the platform declares.
With ``platform`` (its key and name) and ``moved``, a list longer than
PLATFORM_SECTION_BUDGET goes to a page of its own, written into
``moved`` by stem, and the system's heading stays with a link to it.
"""
lines: list[str] = []
# Per-system detail sections (collapsible for large platforms)
use_collapsible = len(by_system) > 10
by_system_declared = _declared_by_system(config_files)
launched = _launcher_refs(config or {})
sections: list[dict] = []
for sys_id, files in sorted(by_system.items()):
ok_count = sum(1 for f in files if f["status"] == "ok")
total = len(files)
sys_emus = _system_emulators(sys_id, emulator_files, by_system_declared.get(sys_id))
anchor = sys_id.replace(" ", "-")
head = [f"{ok_count}/{total} files verified"]
if sys_emus:
emu_links = ", ".join(_emulator_named_link(e, "../") for e in sorted(sys_emus))
head[-1] += "\\"
head.append(f"Emulators: {emu_links}")
head.append("")
# One row per file, the evidence in its details. The sort is stable,
# so same-named entries keep the order verify reported them in,
# which is the declaration order.
rows: list[str] = []
has_path = False
seen_names: dict[str, int] = {}
for f in sorted(files, key=lambda x: x["name"]):
fname = f["name"]
declared = config_files.get((sys_id, fname), [])
nth = seen_names.get(fname, 0)
seen_names[fname] = nth + 1
cfg_entry = declared[nth] if nth < len(declared) else {}
has_path = has_path or bool(_row_path(fname, cfg_entry))
rows.append(_platform_file_row(
f, cfg_entry, str((config or {}).get("hash_type") or ""),
launched.get(fname.rsplit("/", 1)[-1].casefold())))
body = head + _platform_file_list(rows, has_path, anchor)
# Measured in the share of a page the list renders to.
size = _page_share(body)
if use_collapsible:
status_tag = "OK" if ok_count == total else _count(total - ok_count, "issue")
block = markup.details("note", f"{_count(total, 'file')} ({status_tag})", body)
while block and not block[-1]:
block.pop()
else:
block = body
sections.append({"sys_id": sys_id, "anchor": anchor, "head": head, "rows": rows,
"has_path": has_path, "block": block,
"size": size, "total": total, "ok": ok_count})
# A list longer than its budget goes to a page of its own, then the
# largest lists until the page's reference fits PLATFORM_REFERENCE_BUDGET:
# with each file's served copy and pinned readers, Batocera's 97 systems
# rendered 785 KB of HTML on one page.
own_page: set[str] = set()
if moved is not None and platform:
own_page = {sec["sys_id"] for sec in sections if sec["size"] > PLATFORM_SECTION_BUDGET}
kept = sum(sec["size"] for sec in sections if sec["sys_id"] not in own_page)
for sec in sorted(sections, key=lambda sec: -sec["size"]):
if kept <= PLATFORM_REFERENCE_BUDGET:
break
if sec["sys_id"] not in own_page:
own_page.add(sec["sys_id"])
kept -= sec["size"]
for sec in sections:
sys_id, anchor = sec["sys_id"], sec["anchor"]
total, ok_count = sec["total"], sec["ok"]
# Every system is a heading with the same anchor in both layouts:
# emulator cards link here, and the site search splits a page at its
# headings. Folded into blocks under one heading, every hash pasted
# in the search led to the systems overview of a 100-block page.
lines.append(f"### {_system_heading_link(sys_id, '../')} {{ #{anchor} }}")
lines.append("")
if moved is not None and platform and sys_id in own_page:
key, display = platform
runs = [sec["head"] + _platform_file_list(run, sec["has_path"], anchor)
for run in _blocks_in_runs([[row] for row in sec["rows"]],
PLATFORM_PART_BUDGET, _page_share)]
stems = [f"{key}-{anchor}" + (f"-{n}" if n > 1 else "")
for n in range(1, len(runs) + 1)]
for n, (stem, run) in enumerate(zip(stems, runs), 1):
part = f" (part {n} of {len(runs)})" if len(runs) > 1 else ""
# A console query landed here with no way to the console's
# own page: the list says whose it is first, linked.
moved[stem] = "\n".join([
"---", *_parent_front_matter((display, f"/platforms/{key}/")), "---", "",
f"# {display}: {system_name(sys_id)}{part}", "",
f"{display}'s list for {_system_named_link(sys_id, '../')}. "
f"Part of the [{display} page]({key}.md#{anchor}), whose other systems "
f"are listed there. Each file below is as {display} declares it, with "
"its status in the pack.",
*([""] + [", ".join(
f"[part {i}]({other}.md)" if other != stem else f"part {i}"
for i, other in enumerate(stems, 1))] if len(runs) > 1 else []),
"", "## Files", "", *markup.details("note", ROLE_LEGEND_TITLE, [ROLE_LEGEND]),
*search_excluded(run),
"", _date_line(),
]) + "\n"
# The count and status a folded system shows in its summary,
# linked to the page that lists the files.
tag = "OK" if ok_count == total else _count(total - ok_count, "issue")
count = f"{_count(total, 'file')} ({tag})"
lines.extend([
f"[{count}]({stems[0]}.md)" if len(stems) == 1 else f"{count}: " + ", ".join(
f"[part {i}]({stem}.md)" for i, stem in enumerate(stems, 1)),
"",
])
continue
# The section's heading stays searchable, its file list with every
# hash is the lookup's: retrodeck's arcade list was 495 KB of index.
lines.extend(search_excluded(sec["block"]))
return lines
# Platforms with an updated file published by export_native.py.
_EXPORTED: set[str] = set()
def _platform_data_links(name: str) -> str:
"""The platform's own data, machine-readable: the YAML transcribed from
its upstream list, this page's JSON and the manifest the installer reads.
An emulator page linked its YAML and JSON, a platform page nothing: a
tool had to download all twelve platforms in platforms.json and filter.
"""
links = [
f"[YAML]({REPO_URL}/blob/main/platforms/{name}.yml)",
f"[JSON](../api/v1/platforms/{name}.json)",
]
if (_REPO_ROOT / "install" / f"{name}.json").is_file():
# The site's own copy, byte for byte (_publish_manifests).
links.append(f"[install manifest](../api/v1/manifests/{name}.json)")
# The installed BIOS folder for clrmamepro and RomVault.
links.append(f"[DAT](../downloads/dat/{name}.dat)")
return ", ".join(links)
def _site_profiles() -> dict[str, dict]:
"""Every emulator profile, read once for the citations of a page."""
return _profiles_in(str(siteinputs.current().emulators), skip_aliases=True)
# Whose code a source reference cites, in one word: a platform page names
# each role once in ROLE_LEGEND. Written after every reference, "(emulator
# code, libretro port)" ran through Batocera's 14,000 words.
ROLE_WORDS = {
"libretro glue": "glue",
"emulator code, libretro port": "port",
"upstream emulator": "upstream",
"this build": "build",
}
ROLE_LEGEND_TITLE = "Source reference words"
ROLE_LEGEND = (
"In a file's details, a word before its source references says whose code they are. "
"**glue** means libretro glue, **port** means emulator code in the libretro port, "
"**upstream** means the upstream emulator and **build** means this build's own code."
)
def _refs_by_role(profile: dict, value: str | dict | None) -> str:
"""A source_ref's parts grouped by whose code they cite, each role named
once by its ROLE_WORDS word: `glue a.c:1, b.c:2 and port c.c:3`."""
from sitegen.sources import source_ref_items
texts = []
for label, items in source_ref_items(profile, value):
by_role: dict[str, list[str]] = {}
for part, role in items:
by_role.setdefault(role, []).append(part)
text = " and ".join(
(f"{ROLE_WORDS.get(role, role)} " if role else "") + ", ".join(parts)
for role, parts in by_role.items())
texts.append(f"**{label}:** {text}" if label else text)
return ", ".join(texts)
def _category_evidence_md(evidence: dict, launched: list[str] | None = None) -> str:
"""What establishes an entry's category, as the page shows it.
``launched`` holds the platform's launcher records that open the entry,
already rendered: "(by launcher)" alone named no record and no line.
"""
if evidence.get("read_by"):
groups: dict[bool, list[str]] = {True: [], False: []}
bare: list[str] = []
profiles = _site_profiles()
for reader in evidence["read_by"]:
# Pinned links, the repository named in words: the refs were
# plain code with the role word ("source") left in front.
profile = profiles.get(reader["emulator"], {})
refs = [
(f"`{e['name']}` at {_refs_by_role(profile, e['source_ref'])}"
if e.get("source_ref") else f"`{e['name']}`")
+ (" (by name)" if e.get("by") == "name" else "")
for e in reader.get("entries", [])
]
if reader["emulator"] == "launcher":
name = "the platform's launcher"
refs = list(launched or [])
else:
name = _emulator_link(reader["emulator"], "../")
groups[bool(reader.get("runs_system"))].append(
f"{name} ({', '.join(refs)})" if refs else f"{name} (by {reader['proof']})")
if not reader.get("runs_system"):
# A launcher record is this platform's own code: kept whole.
bare.append(f"{name} ({', '.join(refs)})"
if reader["emulator"] == "launcher" and refs else name)
if not groups[True]:
return "Read by " + ", ".join(groups[False])
text = "Read by " + ", ".join(groups[True])
# Cores of other systems that share the name: named, not cited, as
# their lines describe another machine's file.
if bare:
text += ", also named by " + ", ".join(bare)
return text
examined = evidence.get("cores_examined") or []
# A core the site gives no page (a test core) is named, not linked.
with_page = _profiles_with_page(str(siteinputs.current().emulators))
cores = ("cores examined: " + ", ".join(
_emulator_link(c, "../") if c in with_page else c for c in examined)
if examined else "no core examined")
if evidence.get("unsettled"):
return f"No reader found, not settled: {evidence['unsettled']} ({cores})"
return f"No reader found ({cores})"
def _profiles_by_core_name() -> dict[str, list[str]]:
"""Core name as a platform writes it -> the profiles with a page for it.
MinUI writes `mednafen_vb`, the profile and its page are `beetle_vb`.
"""
return _core_names_in(str(siteinputs.current().emulators))
@functools.cache
def _profiles_with_page(emulators_dir: str) -> frozenset[str]:
"""The profiles the site writes a page for: no alias, no test core."""
profiles = _profiles_in(emulators_dir, skip_aliases=True)
return frozenset(
k for k, v in profiles.items() if v.get("type") != "alias" and v.get("role") != "test"
)
@functools.cache
def _core_names_in(emulators_dir: str) -> dict[str, list[str]]:
profiles = _profiles_in(emulators_dir, skip_aliases=True)
with_page = _profiles_with_page(emulators_dir)
return {
core: sorted(k for k in keys if k in with_page)
for core, keys in upstream_profile_index(profiles).items()
}
def _core_name_links(cores: list[str]) -> list[str]:
"""A link per core to its profile page, the bare name where none exists."""
index = _profiles_by_core_name()
links: list[str] = []
for core in cores:
keys = [core] if core in index.get(core, []) else index.get(core, [])
if keys:
links.extend(_emulator_link(k, "../") for k in keys)
else:
links.append(f"`{core}`")
return links
def _core_folders_section(name: str, config: dict) -> list[str]:
"""Each folder the frontend hands a core, and the files the pack puts in it.
For a platform that names no file of its own (MinUI and its forks): the
folders come from its launch scripts, the files from its install manifest.
"""
folders = config.get("core_system_dirs") or {}
manifest = _REPO_ROOT / "install" / f"{name}.json"
files = json.loads(manifest.read_text())["files"] if manifest.is_file() else []
lines = [
"### Core folders",
"",
"Each folder below is the one the frontend gives that core. The pack "
"puts the files the core reads there.",
"",
"| Folder | Cores | Files |",
"|--------|-------|-------|",
]
for folder, info in sorted(folders.items()):
held = sorted(
f["dest"][len(folder) + 1:] for f in files
if f.get("dest", "").startswith(folder + "/")
)
cores = ", ".join(_core_name_links(info.get("cores", [])))
shown = ", ".join(f"`{n}`" for n in held) if held else "none needed"
lines.append(f"| `{folder}/` | {cores} | {shown} |")
lines.append("")
return lines
def _declared_by_system(config_files: dict) -> dict[str, list[dict]]:
"""The platform's own entries of each system, hashes included."""
by_system: dict[str, list[dict]] = {}
for (sys_id, _name), entries in config_files.items():
by_system.setdefault(sys_id, []).extend(entries)
return by_system
def _system_emulators(
sys_id: str, emulator_files: dict | None, files: list[dict] | None = None
) -> list[str]:
"""The emulators a platform runs for one of its systems.
A platform can group machines no profile names as one system: RetroArch
files NAOMI and Atomiswave as sega-dreamcast-arcade, the Enterprise 64
and 128 as enterprise-64-128. When no system id matches, the emulators
are the ones that read a file the system lists, by its name. A member of
an archive does not count: fbneo's boot.bin is read inside bubsys.zip,
and RomM's Dreamcast boot.bin is not that file.
"""
from model.systems import _norm_system_id
norm = _norm_system_id(sys_id)
by_id = [name for name, data in (emulator_files or {}).items()
if sys_id in data["systems"] or norm in data["norm"]]
if by_id or not files:
return by_id
names = {str(f.get("name", "")).lower() for f in files} - {""}
return [name for name, data in (emulator_files or {}).items()
if names & data.get("names", set())]
+94
View File
@@ -0,0 +1,94 @@
"""The platforms index and the setup table."""
from __future__ import annotations
import release_record
from model.guides import DEVICE_GROUPS, GROUP_TILES, GUIDES
from resolve.nativemode import check_label
from sitegen import markup
from sitegen.guidepage import NO_ZIP_FAQ
from sitegen.home import _group_members
from sitegen.install import has_release_pack
from sitegen.readme import release_totals
# Platform pages
def generate_platform_index(coverages: dict, registry: dict | None = None) -> str:
"""The Setups tab: every platform by the device it runs on, and one
line to the table that sets them side by side (setup_table), which is
reference matter and sits with how each setup checks its files."""
registry = registry or {}
lines = [
"# Setups",
"",
"Each setup's page gives the folder and the command.",
"",
]
for group, (label, _description) in DEVICE_GROUPS.items():
members = _group_members(coverages, registry, group)
if not members:
continue
# The group label names the devices, and each card carries its
# setup's own sentence. The kinds of device that run a setup
# follow, as on the home tiles.
lines += [f"## {label}", ""]
lines += markup.card_grid([
*((f"[{coverages[name]['platform']}]({name}.md)", [GUIDES[name].summary])
for name in members),
*((f"[{tile.name}](../{tile.link})", [tile.text])
for tile in GROUP_TILES.get(group, ())),
])
lines += [
f"Comparing setups? [Every setup side by side](../{SETUP_TABLE_LINK})",
"",
]
return "\n".join(lines) + "\n"
# Where the side-by-side table of setups is published: with how each setup
# checks its files, the column a reader compares.
SETUP_TABLE_PAGE = "wiki/verification-modes.md"
SETUP_TABLE_ANCHOR = "every-setup-at-a-glance"
SETUP_TABLE_LINK = f"{SETUP_TABLE_PAGE}#{SETUP_TABLE_ANCHOR}"
def setup_table(coverages: dict) -> list[str]:
"""Every setup side by side: the files on its own list, the files in its
ZIP, and how it checks them. Written under the Reference level, on the
page that explains each way of checking."""
lines = [
f"## Every setup at a glance {{ #{SETUP_TABLE_ANCHOR} }}",
"",
"| Setup | Files on its own list | Files in the ZIP | How it checks |",
"|-------|------:|------:|---------------|",
]
for name, cov in sorted(coverages.items(), key=lambda item: item[1]["platform"].casefold()):
listed = f"{cov['total']:,}" if cov["total"] else "No list of its own"
files, _size = release_totals(name, release_record.load_advertised())
zipped = (f"{files:,}" if files
else "No ZIP yet" if has_release_pack(name) else "No ZIP")
lines.append(
f"| [{cov['platform']}](../platforms/{name}.md) | {listed} | {zipped} | "
f"{check_label(cov['mode'], cov['config'].get('hash_rule'))} |"
)
lines += [
"",
"The ZIP adds the files its emulators load to the files on the setup's own list.",
"",
]
lines += ["No ZIP: the setup is served by the command alone. "
f"[Why?](../{NO_ZIP_FAQ})", ""]
return lines
def with_setup_table(page: str, coverages: dict) -> str:
"""The comparison table placed before the Next steps of its page, or at
its end."""
table = "\n".join(setup_table(coverages))
marker = "\n## Next steps"
if marker in page:
head, tail = page.split(marker, 1)
return f"{head.rstrip()}\n\n{table}{marker}{tail}"
return f"{page.rstrip()}\n\n{table}"
+271
View File
@@ -0,0 +1,271 @@
"""Each platform's page, and the files page."""
from __future__ import annotations
import json
import re
from model.guides import GUIDES
from model.systemnames import system_name
from resolve.nativemode import check_label, reads_file_contents
from sitegen import markup
from sitegen.config import REPO_URL, _date_line
from sitegen.decorate import level_label
from sitegen.diagrams import local_images
from sitegen.guidepage import _pack_buttons, _platform_guide
from sitegen.home import _stat
from sitegen.install import _platform_install_block
from sitegen.platformfiles import (
ROLE_LEGEND,
ROLE_LEGEND_TITLE,
_EXPORTED,
_core_folders_section,
_declared_by_system,
_emulator_named_link,
_launcher_unproven_section,
_platform_data_links,
_render_platform_systems,
_system_emulators,
)
from sitegen.render import _escape_tags, _pct
# A hash a platform's list writes, in words.
_HASH_WORDS = {"md5": "MD5", "sha1": "SHA-1", "sha256": "SHA-256", "crc32": "CRC32"}
def _transcribed_row(config: dict) -> list[str]:
"""The file every declaration on this page was read from: without it
a hash could not be traced to the revision that states it."""
from sitegen.sources import list_source
transcribed = str(config.get("source") or "")
if not transcribed:
return []
listed = list_source(transcribed)
moving = (listed.moving if listed else bool(
re.search(r"/(?:master|main|db)(?:/|$)|refs/heads/", transcribed)))
note = " (a branch: the revision read is not recorded)" if moving else ""
# Named in words: the raw URL broke into 25 lines of 8 characters
# on a phone.
link = (f"[{_escape_tags(listed.label)}]({listed.browse()})" if listed
else f"<{transcribed}>")
return [f"| Transcribed from | {link}{note} |"]
def _platform_meta_rows(name: str, config: dict, mode: str, registry: dict) -> list[str]:
"""The rows of a platform's detail card."""
rows = []
homepage = config.get("homepage", "")
version = config.get("version", "")
hash_type = config.get("hash_type", "")
base_dest = config.get("base_destination", "")
# The hash the list writes, when it is not the one the platform checks:
# RetroArch checks presence and its System.dat writes sha1.
if hash_type and hash_type != mode:
rows.append(f"| Hashes in the list | {_HASH_WORDS.get(hash_type, hash_type)} |")
if version:
rows.append(f"| Version | {version} |")
# base_destination is only the root the platform's own list writes its
# paths from: the pack strips it, so it is no folder to extract into.
if base_dest:
rows.append(f"| Paths in the platform's list start at | `{base_dest}/` |")
if homepage:
rows.append(f"| Homepage | [{homepage}]({homepage}) |")
rows.extend(_transcribed_row(config))
if name in _EXPORTED:
rows.append(f"| Updated file | [Download it and see the changes](../exports.md#{name}) |")
rows.append(f"| Data | {_platform_data_links(name)} |")
for cb in registry.get(name, {}).get("contributed_by", []) or []:
username = cb.get("username", "")
contribution = cb.get("contribution", "")
pr = cb.get("pr")
pr_link = f" ([#{pr}]({REPO_URL}/pull/{pr}))" if pr else ""
rows.append(
f"| Contributed by | [@{username}](https://github.com/{username}):"
f" {contribution}{pr_link} |"
)
return rows
def _platform_band(cov: dict) -> list[str]:
"""The coverage figures above a platform's detail card."""
config = cov["config"]
mode = cov["mode"]
pct = _pct(cov["present"], cov["total"])
mode_badge = (
"rb-badge-success" if reads_file_contents(mode) else "rb-badge-info"
)
return [
markup.block_open("div", 'class="rb-stats"'),
"",
*_stat(f"{cov['present']}/{cov['total']}", f"Coverage ({pct})"),
*_stat(str(cov["verified"]), "Verified"),
*_stat(str(cov["missing"]), "Missing"),
*_stat(f'<span class="rb-badge {mode_badge}">{check_label(mode, config.get("hash_rule"))}</span>',
"Checked by"),
"</div>",
"",
]
def _platform_declarations(cov: dict) -> tuple[dict[tuple[str, str], list[dict]], dict[str, list]]:
"""The declarations of a platform's list by system and name, and its
verify details by system."""
# The declaration behind each detail, by system and name in declaration
# order: keyed by name alone, the last of MiSTer's 23 boot.rom gave its
# MD5 to every system's row.
config_files: dict[tuple[str, str], list[dict]] = {}
for sys_id, system in cov["config"].get("systems", {}).items():
for fe in system.get("files", []):
fname = fe.get("name", "")
if fname:
config_files.setdefault((sys_id, fname), []).append(fe)
by_system: dict[str, list] = {}
for d in cov["details"]:
sys_id = d.get("system", "unknown")
by_system.setdefault(sys_id, []).append(d)
return config_files, by_system
def _platform_head(name: str, cov: dict, registry: dict, no_list: bool) -> list[str]:
"""A platform page down to its reference heading's notes: the title,
the summary and the guide."""
config = cov["config"]
display = cov["platform"]
homepage = config.get("homepage", "")
# The mark is drawn beside the title from the front matter: floated
# beside the first line at 48 px it read as a broken image.
logo_url = registry.get(name, {}).get("logo", "")
logo_url = local_images().get(logo_url, logo_url)
lines = [
*(["---", f"logo: {json.dumps(logo_url)}", "---", ""] if logo_url else []),
f"# {display}",
"",
]
summary = GUIDES[name].summary if name in GUIDES else ""
if summary:
lines += [summary + (f" [{display} website]({homepage})." if homepage else ""), ""]
if name in GUIDES:
lines += _platform_guide(name, display, cov, registry, no_list)
lines += [
"## Reference: every file by system { #reference-every-file-by-system }",
"",
level_label("reference"),
"",
"For checking the work: counts, the list's source and each file's hashes.",
"",
*(line for note in (GUIDES[name].reference_notes if name in GUIDES else ())
for line in (note, "")),
]
if no_list:
# MinUI and its forks hand each core a folder and name no file: a
# 0/0 coverage band read as "this device is not supported".
lines.extend(markup.aside("info", "No BIOS list of its own", [
f"{display} names no BIOS file itself: it gives each emulator core "
"its own folder and the core looks for its files there. The pack "
"places every file the cores it runs need into those folders. The "
"core files are listed further down this page.",
]))
return lines
def generate_platform_page(
name: str,
cov: dict,
registry: dict | None = None,
emulator_files: dict | None = None,
moved: dict[str, str] | None = None,
) -> str:
"""A guide first (folder, command, pack, check), then every file the
platform's list and its emulators need, under a reference heading.
``moved`` collects the pages of systems whose list is too long for it.
"""
registry = registry or {}
config = cov["config"]
display = cov["platform"]
no_list = not cov["total"] and registry.get(name, {}).get("native_list") == "none"
lines = _platform_head(name, cov, registry, no_list)
band = [] if no_list else _platform_band(cov)
lines.extend([*band, markup.block_open("div", 'class="rb-meta-card"'), "",
"| Detail | Value |", "|---|---|"])
lines.extend(_platform_meta_rows(name, config, cov["mode"], registry))
lines.extend(["", "</div>"])
if name not in GUIDES:
detect = (registry.get(name, {}).get("install") or {}).get("detect") or []
on_card = any(rule.get("method") == "card_marker" for rule in detect)
lines.extend(["", *_platform_install_block(name, display, on_card)])
lines.extend(["", _pack_buttons(name, f"Download {display} Pack", display=display)])
lines.append("")
config_files, by_system = _platform_declarations(cov)
if no_list:
lines.extend(_core_folders_section(name, config))
if _own_list_only(config):
lines.extend([f"**Cores:** {OWN_LIST_ONLY}", ""])
# System summary table (quick navigation)
lines.extend(
[] if no_list and not by_system else [
"### Systems overview",
"",
"| System | Files | Status | Emulators |",
"|--------|-------|--------|-----------|",
]
)
by_system_declared = _declared_by_system(config_files)
for sys_id, files in sorted(by_system.items()):
ok_count = sum(1 for f in files if f["status"] == "ok")
total = len(files)
non_ok = total - ok_count
if non_ok == 0:
status = '<span class="rb-badge rb-badge-success">OK</span>'
else:
status = (
f'<span class="rb-badge rb-badge-warning">'
f'{non_ok} issue{"s" if non_ok > 1 else ""}</span>'
)
sys_emus = _system_emulators(sys_id, emulator_files, by_system_declared.get(sys_id))
anchor = sys_id.replace(" ", "-")
# Named and linked as the detail blocks below do: the column held
# profile ids, none of 1,463 linked.
emu_str = ", ".join(_emulator_named_link(e, "../") for e in sorted(sys_emus)[:3])
if len(sys_emus) > 3:
emu_str += f" [+{len(sys_emus) - 3}](#{anchor})"
# The name a reader filters on, the id the list writes beside it.
# The id and the count are no words a reader searches for: indexed,
# every platform page answered a system id before its system's page.
lines.append(
f"| [{_escape_tags(system_name(sys_id))}](#{anchor}) "
f"<small data-pagefind-ignore>{sys_id}</small> "
f"| <span data-pagefind-ignore>{ok_count}/{total}</span> | {status} | {emu_str} |"
)
lines.append("")
if by_system:
lines.extend(markup.details("note", ROLE_LEGEND_TITLE, [ROLE_LEGEND]))
lines.extend(
_render_platform_systems(by_system, config_files, emulator_files,
(name, display), moved, config)
)
lines.extend(_launcher_unproven_section(config))
lines.extend(["", _date_line()])
return "\n".join(lines) + "\n"
# What a platform that declares no core (cores: []) is told, on its page
# and in the cross-reference.
OWN_LIST_ONLY = "None. Its own list is the whole truth: no core profile adds a file."
def _own_list_only(config: dict) -> bool:
"""The platform declares `cores: []`: its own list decides alone."""
return isinstance(config.get("cores"), list) and not config["cores"]
+344
View File
@@ -0,0 +1,344 @@
"""The provenance page, and the wanted lists it leads to."""
from __future__ import annotations
import html
import json
from datetime import datetime
from model.composition import compute_composition, count_catalog_matched
from provenance_report import distinct_missing
from sitegen import entries as siteentries, markup
from sitegen.cards import _PROVENANCE_LABELS, _ROMSET_SOURCES
from sitegen.config import _date_line
from sitegen.parts import _list_pages
from sitegen.render import _count, _escape_tags, _slugify_anchor
_PROVENANCE_HOMES = {
"redump": "http://redump.org/",
"no-intro": "https://no-intro.org/",
"tosec": "https://www.tosecdev.org/",
}
def _prov_title(data: dict) -> str:
"""Tooltip text for a provenance badge."""
parts = [data.get("dat", ""), data.get("description", "")]
return ": ".join(p for p in parts if p).replace('"', "&quot;")
def load_derivable(path: str = "derivable.json") -> dict[str, dict]:
"""Missing sha1 -> how the collection produces it, as the pipeline found.
Empty when the pipeline has not recorded it: the page then lists every
missing dump, as it did before the record existed.
"""
try:
with open(path, encoding="utf-8") as handle:
return json.load(handle)
except FileNotFoundError:
return {}
def _date_in_words(stamp: str) -> str:
"""`2026-08-07T...` as `<time datetime="2026-08-07">7 August 2026</time>`."""
try:
day = datetime.strptime(str(stamp)[:10], "%Y-%m-%d")
except ValueError:
return _escape_tags(str(stamp))
return f'<time datetime="{day:%Y-%m-%d}">{day.day} {day:%B %Y}</time>'
def generate_provenance_page(
db: dict, report: dict, derivable: dict[str, dict] | None = None,
moved: dict[str, str] | None = None,
) -> str:
"""Page explaining the verified dump badges and listing catalog gaps.
With ``moved``, each catalog's wanted list goes to a page of its own,
keyed by stem: the three lists made a 694 KB page."""
matched_files = count_catalog_matched(db)
total_files = compute_composition(db)["systems"]["files"]
# When each catalog was read: a 76-day-old snapshot showed no age.
as_of = ", ".join(
f"{_PROVENANCE_LABELS.get(source, source)} {_date_in_words(data['imported_at'])}"
for source, data in report.items() if data.get("imported_at")
)
lines = [
"# Dump provenance",
"",
*([f'<p class="rb-timestamp" data-pagefind-ignore>Catalogs as of: {as_of}.</p>', ""]
if as_of else []),
"Provenance says whether a file is, byte for byte, a dump that Redump, "
"No-Intro or TOSEC catalogues. It says where a dump is known from, "
"not whether an emulator accepts it: that is the emulator's code, read "
"in its profile. Example: `scph5501.bin` is Redump's `ps-30a.bin`.",
"",
f"**{matched_files:,}** of {total_files:,} system files match an entry "
"in a dump-preservation catalog. Those files carry a "
'<span class="rb-badge rb-badge-success">catalog</span> badge and the '
"catalog entry's own name on the [system pages](systems/index.md), "
'orange (<span class="rb-badge rb-badge-warning">TOSEC</span>) where '
"TOSEC flags the dump as bad, overdumped, hacked, cracked or fixed. "
"Arcade ROM sets and engine data "
"sit outside what those catalogs index, so they are excluded from the "
"ratio rather than counted as failures.",
"",
"## What the badge means",
"",
"The badge says the file is byte-identical to a dump catalogued by "
"No-Intro, Redump, or TOSEC. Matching is done on SHA1, falling back to "
"MD5 plus size for older catalog entries that predate SHA1. Filenames "
"are never used: the same dump is `fdsbios.nes` here, "
"`[BIOS] Family Computer Disk System (Japan) (En) (Rev 1).bin` at "
"No-Intro, and "
"`Nintendo Famicom Disk System BIOS (198x)(Nintendo)(JP)(en).bin` at "
"TOSEC.",
"",
"## What it does not mean",
"",
"A file without a badge is not inferior and works exactly the same. "
"Emulator behaviour is decided by [verification]"
"(wiki/verification-modes.md), which reads the emulator source code, "
"not by catalog membership. Plenty of files this project ships are "
"outside any catalog by nature: composites a core assembles for itself "
"(the MiSTer X68000 `boot.rom` is `cgrom.dat` joined to `iplrom.dat`), "
"modern console firmware updates, game data such as Diablo's `diabdat.mpq`, and "
"arcade sets tracked by MAME driver source instead.",
"",
"When the two views disagree, this project follows the code, because "
"that is what decides whether the emulator boots. The reasoning is in "
"the [technical questions](wiki/technical-faq.md#are-these-files-verified-against-original-"
"hardware-dumps).",
"",
"## Coverage",
"",
"| Catalog | In collection | Covered DATs | Snapshot |",
"|---------|--------------|-------------|----------|",
]
for source, data in report.items():
label = _PROVENANCE_LABELS.get(source, source)
home = _PROVENANCE_HOMES.get(source, "")
in_scope = data["matched"] + len(data["missing"])
pct = 100 * data["matched"] / in_scope if in_scope else 0
name = f"[{label}]({home})" if home else label
lines.append(
f"| {name} | {data['matched']:,}/{in_scope:,} ({pct:.0f}%) | "
f"{len(data['covered_dats'])} | {_date_in_words(data['imported_at'])} |"
)
lines.extend(
[
"",
"Coverage counts only DATs the collection already reaches: a DAT "
"counts as covered once at least one of its entries is held. "
"No-Intro tags every non-game dump `[BIOS]`, including digital "
"title distribution such as the Wii U and 3DS CDN catalogues, "
"which this project does not ship.",
"",
]
)
out_of_scope = {s: d["out_of_scope"] for s, d in report.items() if d["out_of_scope"]}
if out_of_scope:
detail = ", ".join(
f"{_PROVENANCE_LABELS.get(s, s)} {c:,}" for s, c in sorted(out_of_scope.items())
)
lines.extend(
[
f"Entries in DATs the collection does not cover at all are "
f"excluded from those numbers ({detail}).",
"",
]
)
derivable = derivable or {}
derived_entries, derived_by_source = _split_derivable(report, derivable)
total_missing = distinct_missing(report)
# The three counts below added up to more than the total above it.
listed = sum(len(data["missing"]) for data in report.values())
overlap = (
f" A dump two catalogs describe is listed under each, so the lists "
f"hold {listed:,} rows."
if listed != total_missing else ""
)
lines.extend(
[
"## Wanted: catalogued dumps this project does not have",
"",
f"The tables below list **{total_missing:,}** dumps a catalog "
f"describes and the collection lacks.{overlap} Nothing here ships in any "
"pack: it is an acquisition list, published with hashes so anyone "
"can check a personal collection against it. A contribution "
"matching one of these hashes is welcome: see "
"[Contributing](contributing.md).",
"",
markup.button("Download the list (CSV)", "downloads/provenance-wanted.csv"),
"",
]
)
for source, data in report.items():
if data["missing"]:
lines.extend(_wanted_section(source, data, derived_by_source.get(source, 0), moved))
lines.extend(_derivable_section(derived_entries, derivable))
lines.extend(["", _date_line()])
return "\n".join(lines) + "\n"
def _split_derivable(report: dict, derivable: dict[str, dict]) -> tuple[dict[str, dict], dict[str, int]]:
"""Take out of each catalog's missing dumps those the collection already
produces, by sha1, with how many each catalog lost.
A dump the collection already produces (the odd bytes of a Kickstart,
the halves of a character ROM) is no acquisition target: the page asked
the public for 79 of them."""
derived_entries: dict[str, dict] = {}
derived_by_source: dict[str, int] = {}
for source, data in report.items():
kept = []
for entry in data["missing"]:
sha1 = (entry.get("sha1") or "").lower()
if sha1 in derivable:
derived_entries.setdefault(sha1, entry)
derived_by_source[source] = derived_by_source.get(source, 0) + 1
else:
kept.append(entry)
data["missing"] = kept
return derived_entries, derived_by_source
def _wanted_dat_table(entries: list) -> list[str]:
"""One DAT's missing dumps as a table."""
table = ["| Name | Description | SHA1 |", "|------|-------------|------|"]
for entry in sorted(entries, key=lambda e: e["name"]):
sha1 = entry.get("sha1") or "-"
# A pipe in catalog text would split the markdown table row
name = entry["name"].replace("|", "-")
desc = (entry.get("description") or "").replace("|", "-")
# Where an emulator's romset already carries the dump.
for hit in entry.get("romsets", []):
desc += (
f" Ships in {_ROMSET_SOURCES.get(hit['source'], hit['source'])} "
f"`{hit['archive']}` as `{hit['member']}`."
)
table.append(f"| `{name}` | {desc} | `{sha1}` |")
return table
def _wanted_section(source: str, data: dict, derived: int, moved: dict[str, str] | None) -> list[str]:
"""A catalog's missing dumps, by DAT, or a line naming the page they went to."""
label = _PROVENANCE_LABELS.get(source, source)
by_dat: dict[str, list] = {}
for entry in data["missing"]:
for dat in entry.get("dats") or [entry.get("dat", "")]:
by_dat.setdefault(dat, []).append(entry)
lines = [f"### {label}", ""]
if moved is not None:
where = _list_pages(
f"provenance-{_slugify_anchor(source)}", f"Wanted from {label}",
f"Dumps {label} catalogues and the collection lacks. Part of "
f"[Dump provenance](provenance.md#{_slugify_anchor(label)}).",
[], [_wanted_list(source, label, data, by_dat, derived)],
moved, parent=("Dump provenance", "/provenance/"),
)
lines.extend([
f"{_count(len(data['missing']), 'dump')} in {_count(len(by_dat), 'DAT')}: "
f"listed on {where}.", "",
])
return lines
for dat in sorted(by_dat):
entries = by_dat[dat]
lines.extend(markup.details("note", f"{dat} ({len(entries)})", _wanted_dat_table(entries)))
return lines
def _derivable_section(derived_entries: dict[str, dict], derivable: dict[str, dict]) -> list[str]:
"""The catalogued dumps the collection produces from a file it holds."""
if not derived_entries:
return []
lines = [
"## Derivable: dumps the collection already produces",
"",
f"**{len(derived_entries):,}** catalogued dumps are not held as "
"files but come out of one that is: a byte or word split, a "
"half, a swap, or two chips joined. They are not wanted.",
"",
"| Name | Comes from | How | SHA1 |",
"|------|------------|-----|------|",
]
for sha1, entry in sorted(derived_entries.items(), key=lambda kv: kv[1]["name"]):
how = derivable[sha1]
sources = " + ".join(f"`{path}`" for path in how.get("from", []))
name = entry["name"].replace("|", "-")
lines.append(f"| `{name}` | {sources} | {how.get('transform', '')} | `{sha1}` |")
lines.append("")
return lines
def _wanted_list(source: str, label: str, data: dict, by_dat: dict[str, list],
derived: int) -> list[str]:
"""A catalog's wanted page: the counts, then every missing dump in one
table folded under a filter box.
The page was one closed block per DAT, 46 for TOSEC: a name was found
by opening each in turn. The box filters the whole list by name, DAT,
description or SHA1, and says how many rows it keeps.
"""
missing = data["missing"]
held = data["matched"]
reached = held + len(missing) + derived
dats = _count(len(data["covered_dats"]), "DAT")
lines = [
f"Held: **{held:,}** of {reached:,}, in the {dats} the collection reaches. "
f"Wanted: **{len(missing):,}**, from {_count(len(by_dat), 'DAT')}.",
"",
]
if derived:
verb = "is" if derived == 1 else "are"
lines.extend([
f"{derived:,} more {verb} [derivable]"
"(provenance.md#derivable-dumps-the-collection-already-produces).", ""])
if data.get("out_of_scope"):
lines.extend([f"{data['out_of_scope']:,} more sit in DATs the collection does not reach.", ""])
counts = ["| DAT | Wanted |", "|-----|--------|",
*(f"| {dat.replace('|', '-')} | {len(entries):,} |"
for dat, entries in sorted(by_dat.items()))]
lines.extend(markup.details("note", f"Wanted by DAT ({len(by_dat):,})", counts))
rows = []
for entry in sorted(missing, key=lambda e: (e["name"], e.get("sha1") or "")):
desc = markup.inline_html(entry.get("description") or "")
for hit in entry.get("romsets", []):
desc += markup.inline_html(
f" Ships in {_ROMSET_SOURCES.get(hit['source'], hit['source'])} "
f"`{hit['archive']}` as `{hit['member']}`.")
in_dats = ", ".join(html.escape(d) for d in (entry.get("dats") or [entry.get("dat", "")]))
sha1 = html.escape(entry.get("sha1") or "-")
# The search reads the name alone. The DAT names are searched once, in
# the count table above, and the site search holds no hashes. With the
# descriptions indexed too, the TOSEC list matched "2" 556 times
# (years, versions) and put the PlayStation page ahead of the
# PlayStation 2 one for "playstation 2 bios". The name and the hash
# sit in their cells as text: a catalog name is words, and in code
# each word wore its own box on a narrow column.
skip = markup.search_exclude()
rows.append("<tr>"
f"<td>{html.escape(entry['name'], quote=False)}</td>"
f"<td {skip}>{in_dats}</td><td {skip}>{desc or '-'}</td>"
f'<td class="rb-hash" {skip}>{sha1}</td></tr>')
heads = ["Name", "DAT", "Description", "SHA1"]
lines.extend([
siteentries.filter_box(f"rb-wanted-filter-{_slugify_anchor(source)}",
"dumps", heads, len(rows)),
'<details class="rb-details rb-details-note">',
f"<summary>All {_count(len(rows), 'wanted dump')}</summary>",
'<table class="rb-wanted" data-rb-stack="true">',
"<thead><tr>" + "".join(f'<th scope="col">{h}</th>' for h in heads) + "</tr></thead>",
"<tbody>", *rows, "</tbody>", "</table>", "</details>", "",
])
return lines
+71
View File
@@ -0,0 +1,71 @@
"""Manifests, target lists and reports copied where the site serves them."""
from __future__ import annotations
import json
import shutil
from pathlib import Path
import release_record
from sitegen.config import _REPO_ROOT
from sitegen.write import _record, write_if_changed
def write_release_advertised(generated: Path) -> None:
"""The release record as the pages read it, for the file picker.
The picker imported release.json whole and offered the ZIP of six setups
the registry no longer releases, while their pages said "No ZIP". It
reads this file instead: the platforms marked release_pack only.
"""
generated.mkdir(parents=True, exist_ok=True)
write_if_changed(
str(generated / "release-advertised.json"),
json.dumps(release_record.load_advertised(), ensure_ascii=False, indent=1,
sort_keys=True) + "\n",
)
def _publish_manifests(api: Path) -> list[tuple]:
"""The install manifests and the release record, beside the API.
The platform's list says what a setup checks. The manifest says what its
pack installs: Batocera's list holds 353 files, its pack 14,508. The
only copy was install/<platform>.json on the repository's main branch,
which no page named. Copied byte for byte: the SHA256 the catalog gives
is the repository file's.
"""
folder = api / "manifests"
folder.mkdir(parents=True, exist_ok=True)
assets: list[tuple] = []
for source in sorted((_REPO_ROOT / "install").glob("*.json")):
target = folder / source.name
shutil.copy2(source, target)
_record(target)
assets.append((target, f"Install manifest: {source.stem}", "application/json",
"schemas/install-manifest.schema.json"))
# The target lists install.py --target reads: no catalog entry, and
# api/v1/targets/ answered 404.
targets = api / "targets"
targets.mkdir(parents=True, exist_ok=True)
for source in sorted((_REPO_ROOT / "install" / "targets").glob("*.json")):
shutil.copy2(source, targets / source.name)
_record(targets / source.name)
assets.append((targets / source.name, f"Target list: {source.stem}",
"application/json", "schemas/target-manifest.schema.json"))
# Every change each updated platform file carries, for a maintainer who
# reviews them by script: the Exports page linked only the files.
exports = api / "exports"
exports.mkdir(parents=True, exist_ok=True)
for source in sorted((_REPO_ROOT / "exports").glob("*.json")):
shutil.copy2(source, exports / source.name)
_record(exports / source.name)
assets.append((exports / source.name, f"Updated platform file, its changes: {source.stem}",
"application/json", None))
release = _REPO_ROOT / "release.json"
if release.is_file():
shutil.copy2(release, api / "release.json")
_record(api / "release.json")
assets.append((api / "release.json", "Latest release: packs, sizes and assets",
"application/json", "schemas/release.schema.json"))
return assets
+163
View File
@@ -0,0 +1,163 @@
"""Contributing, not-found and data model pages."""
from __future__ import annotations
import json
from model.profiles import unique_emulator_profiles
from sitegen.home import _next_block
from sitegen.readme import contributing_text
def generate_contributing() -> str:
return contributing_text(
lambda page: f"{page}.md", "# Contributing", "on this site"
) + "\n" + "\n".join(_next_block([
"[Profiling an emulator](wiki/profiling.md), the first task most "
"contributions start from",
]))
# The end of a reference page: back to the index, or on to contributing.
def generate_not_found() -> str:
"""The page a stale link lands on. Pages have moved before (file cards
refiled between manufacturers), so it offers the search, the two pages
a visitor most often wants, and the list a moved page belongs to."""
return "\n".join([
"---",
"search: exclude",
"---",
"",
"# Page not found",
"",
'<p class="rb-lead">This address has no page. It may have moved since the link was written.</p>',
"",
'<p><button type="button" class="rb-notfound-search" data-rb-open-search>Search the site</button></p>',
"",
"- [Start here](index.md): what BIOS files are and how to install them",
"- [Get the files](which-pack.md): the pack or the command for each device",
"- Browse [platforms](platforms/index.md), [systems](systems/index.md) "
"or [emulators](emulators/index.md)",
"",
'<div id="rb-notfound-hint" hidden></div>',
"",
])
def reference_next() -> str:
return "\n" + "\n".join(_next_block([
"[Reference index](wiki/index.md), every reference page in one list",
"For contributors: [How to contribute](contributing.md)",
]))
# Wiki pages
# index, architecture, tools, profiling are maintained as wiki/ sources
# and copied verbatim by main(). Only data-model is generated dynamically.
def generate_wiki_data_model(db: dict, profiles: dict) -> str:
"""Generate data model documentation from actual database structure."""
files_count = len(db.get("files", {}))
by_md5 = len(db.get("indexes", {}).get("by_md5", {}))
by_name = len(db.get("indexes", {}).get("by_name", {}))
by_crc32 = len(db.get("indexes", {}).get("by_crc32", {}))
by_path = len(db.get("indexes", {}).get("by_path_suffix", {}))
by_sha256 = len(db.get("indexes", {}).get("by_sha256", {}))
# A real entry with real values: the PlayStation BIOS v3.0 (A).
sample_key = "0555c6fae8906f3f09baf5988f00e55f88e9f30b"
files = db.get("files", {})
sample: dict = files.get(sample_key) or next(iter(files.values()), {})
lines = [
"# Data model",
"",
"Three kinds of file hold everything this project knows. `database.json` "
"lists every file the collection holds, keyed by its SHA1. A platform YAML "
"copies the BIOS list a setup publishes. An emulator profile records what "
"one emulator opens, read from its code. The sections below show the "
"fields of each, with a real entry, to read the data or build on it.",
"",
"Example: `scph5501.bin` is one entry of `database.json` (key "
"`0555c6fa...`), one entry of `platforms/batocera.yml` (its MD5) and one "
"entry of `emulators/duckstation.yml` (its MD5, region and priority).",
"",
"## database.json",
"",
f"Primary key: SHA1. **{files_count}** file entries.",
"",
f"The entry of `{sample.get('name', '')}`:",
"",
"```json",
*json.dumps(sample, indent=2, ensure_ascii=False).splitlines(),
"```",
"",
"`provenance` maps each catalog that lists the file to the DAT and entry "
"it was matched against. It is present only when the file matches a "
"snapshot under `provenance/`. The join runs by SHA1 first, then by "
"MD5 + size. See [dump provenance](../provenance.md).",
"",
"### Indexes",
"",
"| Index | Entries | Purpose |",
"|-------|---------|---------|",
f"| `by_md5` | {by_md5} | MD5 to SHA1 lookup (Batocera, Recalbox verification) |",
f"| `by_name` | {by_name} | filename to SHA1 list (name-based resolution) |",
f"| `by_crc32` | {by_crc32} | CRC32 to SHA1 lookup |",
f"| `by_path_suffix` | {by_path} | relative path to SHA1 (regional variant disambiguation) |",
f"| `by_sha256` | {by_sha256} | SHA256 to SHA1 lookup (emulator profile validation) |",
"",
"### File resolution order",
"",
"`resolve_local_file` finds the file an entry describes by its hashes "
"first, then by its path, then by its name, and a filename or "
"destination never overrides a declared hash. The steps and their "
"return codes are written once, in "
"[the file resolution chain](verification-modes.md#file-resolution-chain).",
"",
"## Platform YAML",
"",
"Scraped from upstream sources. Structure:",
"",
"```yaml",
"platform: Batocera",
"verification_mode: md5 # how the platform checks files",
"hash_type: md5 # hash type in file entries",
"base_destination: bios # root directory for BIOS files",
"systems:",
" system-id:",
" files:",
" - name: filename",
" destination: path/in/bios/dir",
" md5: expected_hash",
" sha1: expected_hash",
" required: true",
"```",
"",
"Supports inheritance (`inherits: retroarch`) and shared groups",
"(`includes: [group_name]` referencing `_shared.yml`).",
"",
"`base_destination` is the prefix the pack applies to every entry. It is",
"empty when the upstream destinations already carry their own root, which",
"is why the RetroDECK pack ships `bios/` and `roms/` at its top level.",
"Core files then go under `core_destination` when the platform states one",
"(`bios` for AmberELEC and EmuELEC, whose lists also name `neogeo/` and",
"`ports/`), else under the root nearly every destination shares.",
"",
"## Emulator YAML",
"",
f"**{len(profiles)}** profile files, **{len(unique_emulator_profiles(profiles))}** "
"distinct emulators once aliases are folded in. Source-verified from "
"emulator code.",
"",
"See the [profiling guide](profiling.md) for the full field reference.",
"",
"## Static API and bulk exports",
"",
"The website publishes versioned JSON, CSV and SQLite metadata generated "
"from these same structures. Start with the [Data and API](../data.md) "
"catalog. Each downloadable artifact carries a SHA256 in "
"`api/v1/catalog.json`.",
"",
]
return "\n".join(lines) + "\n"
+739
View File
@@ -0,0 +1,739 @@
"""The start-with list atop a console: which file to get first."""
from __future__ import annotations
import re
from collections.abc import Iterator
from dataclasses import dataclass
from model.collection import SECTION_LABELS
from packs.crossref import FileConsumers
from sitegen import markup
from sitegen.cards import ROMSET_FAQ, _emulator_display, _romset_releases
from sitegen.consolecards import (
Card,
START_WITH_NAMES,
_Item,
_NO_PRIORITY,
_add_name,
_card_rank,
_entries_by_section,
_entry_systems,
_reading_pairs,
_region_order,
_setup_name,
_visible,
_without_files,
)
from sitegen.descriptions import _said_as_list
from sitegen.emulatorcards import _region_words
from sitegen.install import comes_with_app
from sitegen.render import _code, _count, console_anchor
class _StartGroup:
"""What one system of a section asks for."""
def __init__(self) -> None:
self.by_region: dict[str, list[str]] = {}
self.plain: list[str] = []
# Files an emulator reads when present and replaces when absent.
self.optional: list[str] = []
self.emulators: list[str] = []
# Each file an emulator requires, by its visible name, with the
# emulators requiring it and the name as the line writes it.
self.requires: dict[str, set[str]] = {}
self.written: dict[str, str] = {}
# Visible name -> the sha1 of the file it names.
self.sha1s: dict[str, str] = {}
# Emulators that replace a missing file with their own code.
self.hle: set[str] = set()
# Files an emulator reads when present and runs the same without.
self.extra: list[str] = []
# By line (a region, "" for every region): visible name -> the
# emulators requiring that file for the line. Three Mega CD BIOS,
# one per region, share the name cd_bios.rom.
self.line_readers: dict[str, dict[str, set[str]]] = {}
# (line, visible name, emulator) -> the name the emulator reads.
self.read_as: dict[tuple[str, str, str], str] = {}
# (line, visible name) -> the file name its card shows.
self.card_names: dict[tuple[str, str], str] = {}
# (line, visible name) of the files most of whose readers read
# them beside another one they require.
self.extras: set[tuple[str, str]] = set()
def require(self, name: str, emulator: str) -> None:
self.written.setdefault(_visible(name), name)
self.requires.setdefault(_visible(name), set()).add(emulator)
def read_for(self, line: str, name: str, emulator: str, read: str, card: str) -> None:
"""Record that ``emulator`` requires ``name`` for ``line``, under
the name ``read``, its card titled ``card``."""
visible = _visible(name)
self.line_readers.setdefault(line, {}).setdefault(visible, set()).add(emulator)
self.read_as.setdefault((line, visible, emulator), read)
self.card_names.setdefault((line, visible), card)
def absorb(self, other: _StartGroup) -> None:
for region, names in other.by_region.items():
for name in names:
_add_name(self.by_region.setdefault(region, []), name)
for mine, theirs in ((self.plain, other.plain), (self.optional, other.optional),
(self.extra, other.extra), (self.emulators, other.emulators)):
for name in theirs:
_add_name(mine, name)
for visible, emulators in other.requires.items():
self.written.setdefault(visible, other.written[visible])
self.requires.setdefault(visible, set()).update(emulators)
for visible, sha1 in other.sha1s.items():
self.sha1s.setdefault(visible, sha1)
self.hle.update(other.hle)
for line, readers in other.line_readers.items():
for visible, emulators in readers.items():
self.line_readers.setdefault(line, {}).setdefault(visible, set()).update(emulators)
for key, value in other.read_as.items():
self.read_as.setdefault(key, value)
for card_key, card_name in other.card_names.items():
self.card_names.setdefault(card_key, card_name)
self.extras |= other.extras
def requirers(self) -> set[str]:
return set().union(*self.requires.values()) if self.requires else set()
def as_read(self, visible: str, emulators: set[str], line: str | None = None) -> str:
"""A file as an emulator reading it instead is told to fetch it:
by its card's name, with the name it reads when that differs.
The line read "ares reads neo-epo.sp1" above a card titled
neo-epo.bin."""
lines = [line] if line is not None else sorted(self.line_readers)
for key in lines:
card = self.card_names.get((key, visible))
if card is None:
continue
reads = {self.read_as[(key, visible, e)] for e in emulators
if (key, visible, e) in self.read_as}
written = self.written.get(visible, _code(card))
# A linked name (a file under Arcade) keeps its link.
shown = written if _visible(written) == card else _code(card)
if len(reads) == 1 and next(iter(reads)) != card:
return f"{shown} (as {_code(next(iter(reads)))})"
return shown
return self.written.get(visible, _code(visible))
_Read = tuple[str, dict, "str | None"]
def _section_reads(
files: list[dict], consumers: FileConsumers, here: tuple[str, str] | None,
) -> tuple[dict[str, list[_Read]], list[dict]]:
"""The reads of each file the section names, by sha1, and the files the
start line may name: the section's primaries, then the Arcade files
its systems require."""
from sitegen.render import system_section
held = {str(f.get("sha1", "")) for f in files}
primaries = [f for f in files if "/.variants/" not in f["path"]]
kept: dict[str, list[_Read]] = {}
for f in primaries:
sha1 = str(f.get("sha1", ""))
for emulator, entry in _reading_pairs(sha1, consumers):
if comes_with_app(entry):
continue
system = None
systems = _entry_systems(emulator, entry)
if here is not None and systems:
system = next((s for s in systems if system_section(s) == here), None)
if system is None:
continue
kept.setdefault(sha1, []).append((emulator, entry, system))
candidates = list(primaries)
known = (getattr(consumers, "_db", None) or {}).get("files", {})
if here is not None:
for sha1, emulator, entry, system in _entries_by_section(consumers).get(here, []):
record = known.get(sha1)
parts = str((record or {}).get("path", "")).split("/")
if (sha1 in held or not record or comes_with_app(entry) or ".variants" in parts
or len(parts) < 3 or parts[1] != "Arcade"):
continue
if sha1 not in kept:
candidates.append({**record, "elsewhere": True})
kept.setdefault(sha1, []).append((emulator, entry, system))
return kept, candidates
class _SectionReads:
"""Each read of the files a start line may name, with the name the line
writes for it."""
def __init__(self, kept: dict[str, list[_Read]], ranked: list[dict],
consumers: FileConsumers) -> None:
self.kept = kept
self.rendered: dict[str, str] = {}
for f in ranked:
sha1 = str(f.get("sha1", ""))
pairs = kept.get(sha1, [])
name = _code(_setup_name(f, consumers, [(e, entry) for e, entry, _s in pairs]))
if f.get("elsewhere"):
name = f"[{name}]({markup.site_href(f'files/?sha1={sha1}')})"
self.rendered[sha1] = name
# A member read inside its archive is the archive's to name: FinalBurn
# Neo reads sfix.sfix inside neogeo.zip, and the line had it read
# sfix.sfix instead of neogeo.zip.
self.archives = {_visible(name): (name, sha1)
for sha1, name in reversed(self.rendered.items())}
db = getattr(consumers, "_db", None) or {}
self.known = db.get("files", {})
self.by_name = db.get("indexes", {}).get("by_name", {})
def archive_named(self, archive: str) -> tuple[str, str]:
"""The archive as the line names it, linked to its card when the
collection holds one, with that card's sha1."""
if archive in self.archives:
return self.archives[archive]
found = self.by_name.get(archive) or []
found = [found] if isinstance(found, str) else sorted(found)
found.sort(key=lambda s: "/.variants/" in str(self.known.get(s, {}).get("path", "")))
if not found:
return _code(archive), ""
return f"[{_code(archive)}]({markup.site_href(f'files/?sha1={found[0]}')})", ""
def reading(self, f: dict) -> Iterator[tuple[str, dict, str | None, str, str]]:
"""Each read of a file: the emulator, its entry, the system, the
name the line writes and the sha1 of the card it names."""
sha1 = str(f.get("sha1", ""))
for emulator, entry, system in self.kept.get(sha1, []):
name, named = self.rendered[sha1], sha1
if entry.get("archive"):
name, named = self.archive_named(str(entry["archive"]))
yield emulator, entry, system, name, named
def _weak_starts(ranked: list[dict], reads: _SectionReads) -> tuple[dict[str, set[str]], set[str]]:
"""The emulators requiring each file, and the files that are extras.
A file as many of whose readers require another file and read this
one only when present is an extra, not a start file: NAOMI opened on
hod2bios.zip, which 13 of the 19 emulators listing it read beside
naomi.zip for the House of the Dead 2 alone."""
requiring: dict[str, set[str]] = {}
optional: dict[str, set[str]] = {}
for f in ranked:
for emulator, entry, _system, name, named in reads.reading(f):
if entry.get("hle_fallback"):
continue
side = requiring if entry.get("required", True) else optional
side.setdefault(named or _visible(name), set()).add(emulator)
needs_other = {emulator: {key for key, emulators in requiring.items() if emulator in emulators}
for emulators in requiring.values() for emulator in emulators}
weak = {key for key, emulators in requiring.items()
if len(emulators) <= len({e for e in optional.get(key, ())
if needs_other.get(e, set()) - {key}})}
return requiring, weak
def _group_place(emulator: str, entry: dict) -> tuple[str, str, tuple[str, ...]] | None:
"""The requirement a member of a group answers, or None outside a group."""
if entry.get("group") and entry.get("required", True) and not entry.get("hle_fallback"):
return (emulator, str(entry["group"]),
tuple(sorted(str(r) for r in entry.get("region") or [])))
return None
def _chosen_members(ranked: list[dict], reads: _SectionReads,
requiring: dict[str, set[str]]) -> dict[tuple, str]:
"""A group's members are one requirement, any of them answering it: the
emulator requires on the line the member most emulators require, its
search order breaking a tie. PicoDrive's four Europe Mega CD names
each read as a file to get beside the bios_CD_E.bin of every other."""
members: dict[tuple, list[tuple[tuple, str]]] = {}
for f in ranked:
for emulator, entry, _system, name, named in reads.reading(f):
place = _group_place(emulator, entry)
if place is not None:
member = named or _visible(name)
rank = (-len(requiring.get(member, ())),
entry["priority"] if isinstance(entry.get("priority"), int) else _NO_PRIORITY,
_visible(name))
members.setdefault(place, []).append((rank, member))
return {place: min(found)[1] for place, found in members.items()}
def _add_start_read(group: _StartGroup, f: dict, read_by: tuple[str, dict, str, str],
weak: set[str]) -> None:
"""One read of a file into its system's group: ``read_by`` is the
emulator, its entry, the name the line writes and the card's sha1."""
emulator, entry, name, named = read_by
if named:
group.sha1s.setdefault(_visible(name), named)
if emulator not in group.emulators:
group.emulators.append(emulator)
if entry.get("hle_fallback"):
_add_name(group.optional, name)
group.hle.add(emulator)
return
if not entry.get("required", True):
_add_name(group.extra, name)
return
group.require(name, emulator)
read = str(entry.get("archive") or entry.get("name") or _visible(name))
card = str(entry["archive"]) if entry.get("archive") else str(f["name"])
regions = sorted({str(r) for r in entry.get("region") or []})
for region in regions or [""]:
_add_name(group.by_region.setdefault(region, []) if region else group.plain, name)
group.read_for(region, name, emulator, read, card)
if (named or _visible(name)) in weak:
group.extras.add((region, _visible(name)))
def _start_groups(
files: list[dict], consumers: FileConsumers, section: tuple[str, str] | None
) -> dict[str | None, _StartGroup]:
"""The files of a section an emulator reads, by the system they are
read for. An entry is the section's when one of its systems leads
here: the DS section named five DSi files, and the NES one FBNeo's
YM2608 sample, read for a system with no section of its own. An entry
that names no system, in a profile of several, reads the section's own
console. A file the system requires but filed under
Arcade, where sets serve every machine, is named too, linked to its
card: the Neo Geo BIOS. One filed under another console is that
console's, whatever system an emulator files it under (BizHawk reads
the Mega CD BIOS for its Genesis), and one under Other is a single
emulator's, its shaders and fonts. A file the emulator ships with is
no file to fetch."""
from model.systemnames import _heading_name, system_name
from model.collection import _manufacturer_slug
here = (_manufacturer_slug(section[0]), section[1]) if section else None
kept, candidates = _section_reads(files, consumers, here)
groups: dict[str | None, _StartGroup] = {}
ranked = sorted(candidates, key=lambda f: _card_rank(f, consumers))
reads = _SectionReads(kept, ranked, consumers)
requiring, weak = _weak_starts(ranked, reads)
chosen = _chosen_members(ranked, reads, requiring)
for f in ranked:
for emulator, entry, system, name, named in reads.reading(f):
place = _group_place(emulator, entry)
if place is not None and chosen.get(place) != (named or _visible(name)):
continue
try:
key = system_name(system) if system else None
except KeyError:
key = None
group = groups.setdefault(key, _StartGroup())
_add_start_read(group, f, (emulator, entry, name, named), weak)
named_keys = [key for key in groups if key is not None]
if None in groups and named_keys:
# An entry that names no system reads the section's own console.
heading = _heading_name(*section) if section else None
groups[heading if heading in groups else named_keys[0]].absorb(groups.pop(None))
return groups
def _start_with(
files: list[dict], consumers: FileConsumers, first_below: bool = True,
section: tuple[str, str] | None = None,
) -> list[str]:
"""The line a console section opens on: the files an emulator requires,
by the region the emulator picks each for, and by system when the
section holds several.
``section`` is the (manufacturer, console) the files are under: an
entry read for another console's system is left to that console.
Read from the profiles' system, required, hle_fallback and region
fields, never typed per system. A system most of whose emulators run
without its files says so, and names the few that require one. A
section where no emulator reads a file gets no line.
"""
return _start(files, consumers, first_below, section)[0]
def _start_order(
files: list[dict], consumers: FileConsumers, section: tuple[str, str] | None = None,
) -> list[str]:
"""The sha1s of the files a section's start line names, in its order:
the cards come in that order, so "first below" is true."""
return _start(files, consumers, True, section)[1]
def _start(
files: list[dict], consumers: FileConsumers, first_below: bool,
section: tuple[str, str] | None,
) -> tuple[list[str], list[str]]:
"""The start line and the sha1s it names, in order."""
groups = _start_groups(files, consumers, section)
sha1s: dict[str, str] = {}
for group in groups.values():
for visible, card_sha1 in group.sha1s.items():
sha1s.setdefault(visible, card_sha1)
held = {str(f.get("sha1", "")) for f in files}
lines = _lead_file(groups)
if not lines:
lines = _group_lines(groups, first_below, held, sha1s,
_section_label(*section) if section and section != OTHER_ARCADE else "")
order: list[str] = []
for line in lines:
for visible in re.findall(r"`([^`]*)`", line):
sha1 = sha1s.get(visible)
if sha1 and sha1 not in order:
order.append(sha1)
return [_link_held_names(line, sha1s, held) for line in lines], order
def _link_held_names(line: str, sha1s: dict[str, str], held: set[str]) -> str:
"""Each file the start line names leads to its card, where it downloads:
the Apple II line named eight files and none was a way to get one."""
def link(match: re.Match) -> str:
sha1 = sha1s.get(match[1], "")
return f"[{match[0]}](#sha1-{sha1[:12]})" if sha1 in held else match[0]
# A name inside a link already (a "Keep it zipped" archive) stays as
# is, and so does the name a file is read under, "(as `d2fdc.zip`)".
return re.sub(r"(?<!\[)(?<!\(as )`([^`]*)`(?!\]\()", link, line)
def _group_lines(
groups: dict[str | None, _StartGroup], first_below: bool, held: set[str],
sha1s: dict[str, str], console: str = "",
) -> list[str]:
"""One block per system, as the section opens on them. ``console`` names
the section in a line that picks a BIOS by region."""
keys = sorted(groups, key=lambda k: str(k).casefold())
blocks: dict[str | None, list[tuple[str, str]]] = {}
for key in keys:
block = _group_start(groups[key], first_below and not blocks)
if block and first_below and not blocks:
# "First below" holds only when the first file named is a card
# of this page: the Neo Geo BIOS is filed under Arcade.
first = re.search(r"`([^`]*)`", block[0][1])
if first and sha1s.get(first[1]) not in held:
block = _group_start(groups[key], False)
if block:
blocks[key] = block
if not blocks:
return []
if len(blocks) == 1:
return _start_lines(next(iter(blocks.values())), console)
if all(lead == "*" for block in blocks.values() for lead, _text in block):
# No machine of the section needs a file: the SNES said "Start with"
# over two lines that each said no file is needed.
lines = ["**No file needed** on any of these machines:", ""]
lines += [f"- **{key}**: {text.lstrip(': ')}"
for key, block in blocks.items() for _lead, text in block]
return [*lines, ""]
lines = ["**Start with** the files of the machine:", ""]
for key, block in blocks.items():
for lead, text in block:
if lead == "*":
lines.append(f"- **{key}**: no file needed{text}")
continue
if lead == "+":
# What the others read instead ends the machine's line.
end = "" if lines[-1].endswith(".") else "."
lines[-1] = f"{lines[-1]}{end} {text}"
continue
lines.append(f"- **{key}, {lead}**: {text}" if lead else f"- **{key}**: {text}")
return [*lines, ""]
def _display_names(emulators: set[str] | list[str]) -> list[str]:
return sorted({_emulator_display(e) for e in emulators}, key=str.casefold)
def _names_counted(names: list[str], most: int = 3, noun: str = "") -> str:
"""Names as "a, b and c", the ones past ``most`` counted: "a, b, c and
12 more". One past ``most`` is named, not counted as "1 more"."""
if len(names) > most + 1:
more = f"{len(names) - most} more" + (f" {noun}" if noun else "")
return f"{', '.join(names[:most])} and {more}"
return _said_as_list(names)
def _lead_file(groups: dict[str | None, _StartGroup]) -> list[str]:
"""A section of several systems where most emulators require one file:
that file first, and the emulators that read another instead. The Neo
Geo section listed three machines, and neogeo.zip, which 26 emulators
read, came after a file ares alone reads."""
if len(groups) < 2:
return []
emulators: set[str] = set()
requires: dict[str, set[str]] = {}
written: dict[str, str] = {}
holder: dict[str, _StartGroup] = {}
for group in groups.values():
emulators.update(group.emulators)
for visible, readers in group.requires.items():
requires.setdefault(visible, set()).update(readers)
written.setdefault(visible, group.written[visible])
holder.setdefault(visible, group)
if not requires:
return []
top = max(requires, key=lambda v: len(requires[v]))
readers = requires[top]
if 2 * len(readers) <= len(emulators):
return []
zipped = " Keep it zipped." if top.casefold().endswith(".zip") else ""
names = _display_names(readers)
said = (_names_counted(names, 2, "emulators") if len(names) > 2
else _said_as_list(names))
lines = [f"**Start with** {written[top]}.{zipped} {said} read{'s' if len(names) == 1 else ''} it.",
""]
# The emulators that require other files and not this one, by the
# files they require, each by its card's name.
others: dict[tuple[str, ...], set[str]] = {}
for emulator in emulators - readers:
theirs = tuple(holder[v].as_read(v, {emulator}) for v in requires
if emulator in requires[v])
if theirs:
others.setdefault(theirs, set()).add(emulator)
sentences = []
for files, who in sorted(others.items(), key=lambda item: (-len(item[1]), item[0])):
names = _display_names(who)
verb = "reads" if len(names) == 1 else "read"
sentences.append(f"{_names_counted(names)} {verb} {_said_as_list(list(files))} instead.")
if sentences:
lines += [" ".join(sentences), ""]
return lines
@dataclass(frozen=True)
class _GroupWords:
"""How one system's start line says its files."""
group: _StartGroup
first_below: bool
def listed(self, names: list[str], below: bool | None = None) -> str:
below = self.first_below if below is None else below
if len(names) <= START_WITH_NAMES:
return ", ".join(names)
# The first three by rank, the rest counted: "the 9 files" named
# none, and the Neo Geo BIOS everyone reads is filed under Arcade.
return f"{', '.join(names[:3])} and {_count(len(names) - 3, 'more file')}" + (
", first below" if below else "")
def instead_of(self, line: str, names: list[str], answered: set[str]) -> str:
"""What the emulators no other name answers read instead, one
sentence per set of files: "FinalBurn Neo reads fdsbios.zip instead"."""
group = self.group
readers = group.line_readers.get(line, {})
others: dict[tuple[str, ...], set[str]] = {}
for emulator in sorted(set().union(*(readers.get(_visible(n), set()) for n in names))
- answered):
theirs = tuple(group.as_read(_visible(n), {emulator}, line) for n in names
if emulator in readers.get(_visible(n), set()))
others.setdefault(theirs, set()).add(emulator)
sentences = []
for files, who in sorted(others.items(), key=lambda item: (-len(item[1]), item[0])):
shown = _display_names(who)
verb = "reads" if len(shown) == 1 else "read"
sentences.append(f"{_names_counted(shown)} {verb} {_said_as_list(list(files))} instead.")
return " ".join(sentences)
def split(self, line: str, names: list[str]) -> tuple[list[str], str, set[str]]:
"""A line's names as the files to start with, the sentence naming
what other emulators read instead, and every emulator the line
answers. Names no emulator requires beside another are other names
for one slot: "fdsbios.zip, disksys.rom" read as two files to get."""
group = self.group
readers = group.line_readers.get(line, {})
sets = {n: readers.get(_visible(n), set()) for n in names}
lead = max(names, key=lambda n: len(sets[n]))
main = [n for n in names if n == lead or sets[n] <= sets[lead]]
rest = [n for n in names if n not in main]
# A file the lead's readers require beside it is a start file too,
# unless most of its readers take it as an extra.
main = [n for n in main if n == lead or (line, _visible(n)) not in group.extras]
return main, self.instead_of(line, rest, set(sets[lead])), set().union(*sets.values())
def _runs_without(words: _GroupWords) -> list[tuple[str, str]]:
"""The line of a system most of whose emulators run without its files,
or nothing."""
group = words.group
requirers = group.requirers()
hle = group.hle - requirers
running = set(group.emulators) - requirers
# One that replaces the file with its own code runs, with less
# accuracy, and counts half: most PlayStation cores have such a
# fallback, and a reader still starts with the BIOS.
if not (requirers and 2 * len(requirers) <= 2 * len(running - hle) + len(hle)):
return []
free = _display_names(running)
needing = _display_names(requirers)
names = list(group.written.values())
verb = "requires" if len(needing) == 1 else "require"
if all(len(readers) == len(requirers) for readers in group.requires.values()):
return [("*", f" with {_names_counted(free)}. Only {_names_counted(needing)} {verb} "
f"{words.listed(names, False)}.")]
# Each requires some of the files: "bsnes, FinalBurn Neo and 3
# more require 22 files" read as 22 files for a bsnes user.
these = f"these {len(names)} files" if len(names) > START_WITH_NAMES else "these files"
return [("*", f" with {_names_counted(free)}. Only {_names_counted(needing)} {verb} "
f"some of {these}: {words.listed(names, False)}.")]
def _region_lines(words: _GroupWords) -> tuple[list[tuple[str, str]], set[str], set[str]]:
"""The lines of the files picked by region, the emulators they answer
and the names they give."""
from model.region import _PARENT
group = words.group
order = _region_order()
# A territory its region answers the same way adds nothing: Brazil
# under Latin America.
by_region = {r: names for r, names in group.by_region.items()
if group.by_region.get(_PARENT.get(r, "")) != names}
# Regions that need the same files share a line.
regional: dict[tuple[str, ...], str] = {}
answered: set[str] = set()
shown: set[str] = set()
for region in sorted(by_region, key=lambda r: (order.get(r, len(order)), r)):
main, sentence, readers = words.split(region, by_region[region])
answered |= readers
shown |= {_visible(n) for n in by_region[region]}
text = f"{words.listed(main)}. {sentence}" if sentence else words.listed(main)
same = next((rs for rs, held in regional.items() if held == text), None)
if same is None:
regional[(region,)] = text
else:
regional[same + (region,)] = regional.pop(same)
out = [(", ".join(_region_words(r) for r in regions), regional[regions])
for regions in sorted(regional, key=lambda rs: (order.get(rs[0], len(order)), rs))]
return out, answered, shown
def _plain_lines(words: _GroupWords, regional: bool, answered: set[str],
shown: set[str]) -> list[tuple[str, str]]:
"""The lines of the files every region needs, after the ``regional`` ones."""
group = words.group
out: list[tuple[str, str]] = []
# A name a region line gives already is no "also", and one only
# emulators no region line answers reads is an "instead": armsx1 reads
# scph1001.bin where the others pick a BIOS by region.
plain = [n for n in group.plain if _visible(n) not in shown]
if plain and regional:
readers = group.line_readers.get("", {})
also = [n for n in plain if readers.get(_visible(n), set()) & answered]
if also:
out.append(("", words.listed(also)))
sentence = words.instead_of("", [n for n in plain if n not in also], answered)
if sentence:
out.append(("+", sentence))
elif plain:
main, sentence, _readers = words.split("", plain)
out.append(("", words.listed(main)))
if sentence:
out.append(("+", sentence))
return out
def _group_start(group: _StartGroup, first_below: bool) -> list[tuple[str, str]]:
"""One system's start as (lead, text) pairs. The lead is the regions a
line is for, "" the files every region needs, "*" the line of a system
that runs without any file.
A file is a start file when the emulators requiring it outweigh those
that run without it. The Game Boy opened on dmg_boot.bin, which Emux
GB alone of 13 requires, under a home page that says the Game Boy
needs no BIOS."""
words = _GroupWords(group, first_below)
without = _runs_without(words)
if without:
return without
out, answered, shown = _region_lines(words)
out.extend(_plain_lines(words, bool(out), answered, shown))
if not out and group.optional:
out.append(("*", f"{_without_files(group.emulators)}. "
f"For full accuracy: {words.listed(group.optional)}."))
elif not out and group.extra:
# The Mega Drive's emulators read the TMSS BIOS when it is there:
# the section said nothing under a home page saying none is needed.
out.append(("*", f"{_without_files(group.emulators)}. "
f"Optional: {words.listed(group.extra, False)}."))
return out
def _start_lines(block: list[tuple[str, str]], console: str = "") -> list[str]:
"""One system's start, as the lines its section opens on. A BIOS picked
by region is named with its console: "playstation bios" found the
PlayStation 2 page first, its file names holding "BIOS" and the
PlayStation page's text never saying "PlayStation BIOS"."""
lead, text = block[0]
if lead == "*":
return [f"**No file needed**{text}", ""]
# What the emulators no line answers read instead, after the lines.
instead = " ".join(text for lead, text in block if lead == "+")
block = [(lead, text) for lead, text in block if lead != "+"]
if len(block) == 1 and block[0][0] == "":
named, _sep, _where = block[0][1].partition(", first below")
below = " They come first below." if _sep else ""
return [" ".join(filter(None, [f"**Start with**: {named}.{below}", instead])), ""]
bios = f"the {console} BIOS" if console else "the BIOS"
lines = [f"**Start with** {bios} for the region of the games:", ""]
for lead, text in block:
lines.append(f"- **{lead or 'Some emulators also require'}**: {text}")
if instead:
lines += ["", instead]
return [*lines, ""]
def _cards_markdown(cards: list[Card]) -> list[str]:
"""Primaries, then the variants in a closed block."""
lines = [line for variant, card, _sha1 in cards if not variant for line in card]
variants = [card for variant, card, _sha1 in cards if variant]
if variants:
# A variant gets the same card as a primary: the revision a
# platform pins is the one a reader comes to find, and showed as
# a name and a truncated MD5, nothing said who pins it.
lines.extend(markup.details(
"note", f"Variants ({len(variants)})", [line for card in variants for line in card]))
return lines
def _parts(cards: list[_Item], budget: int, sizes: list[int]) -> list[list[_Item]]:
"""Cards in runs of at most ``budget`` bytes, in order, ``sizes``
giving each card's weight."""
parts: list[list[_Item]] = [[]]
size = 0
for index, card in enumerate(cards):
weight = sizes[index]
if parts[-1] and size + weight > budget:
parts.append([])
size = 0
parts[-1].append(card)
size += weight
return parts
def _console_heading(manufacturer: str, console: str, label: str = "") -> str:
"""A console's heading, its name alone. An icon on 79 of 544 headings
read as missing art on the rest, set the text at two positions on one
page and faded out on one theme or the other. ``label`` is the text
when it differs from the folder, the id staying the folder's."""
return f"## {label or console} {{ #{console_anchor(manufacturer, console)} }}"
def _romset_note(consoles: dict[str, list]) -> list[str]:
"""The line a page of MAME or FBNeo sets carries: an arcade player
looking for the version found the answer only under Reference."""
releases = _romset_releases()
if not any(str(f.get("name", "")) in releases for files in consoles.values() for f in files):
return []
return ["MAME and FBNeo sets must match the emulator's version. "
f"[Which version each core reads]({ROMSET_FAQ}).", ""]
# The Arcade folder of files no board claims: the folder is named after
# its maker, which said nothing about what it holds.
OTHER_ARCADE = ("Arcade", "Arcade")
OTHER_ARCADE_LABEL = "Other arcade files"
def _section_label(manufacturer: str, console: str) -> str:
"""The heading a section shows."""
if (manufacturer, console) == OTHER_ARCADE:
return OTHER_ARCADE_LABEL
return SECTION_LABELS.get((manufacturer, console), console)
+1 -1
View File
@@ -265,7 +265,7 @@ def steps_figure(tab: str) -> list[str]:
def tab_demo(tab: str) -> list[str]:
"""The recording a tab shows, as generate_site writes the component."""
from generate_site import install_demo
from sitegen.home import install_demo
variant = demo_variant(tab)
return install_demo(variant, tab) if variant else []
+409
View File
@@ -0,0 +1,409 @@
"""Structured data and DAT files: schema.org records and Logiqx catalogs of the collection."""
from __future__ import annotations
import json
import re
import urllib.request
from pathlib import Path
from model.collection import collection_paths
from model.systemnames import system_name
from sitegen import starlight as sitestarlight
from sitegen.cards import emulator_file_anchors
from sitegen.config import REPO_URL, SITE_NAME, SITE_URL, _REPO_ROOT
from sitegen.descriptions import EMULATOR_SNIPPETS, NOTHING_TO_FETCH, PAGE_DATA
from sitegen.emulatorcards import _snippet_noun
from sitegen.install import comes_with_app
from sitegen.lookup import _data_member_digests, _hash_values
from sitegen.render import _system_page_map
from sitegen.write import write_if_changed
SYSTEM_PARTS_IN_FULL = 250
def collection_dat(db: dict, generated_at: str) -> str:
"""The collection as a Logiqx DAT, the format clrmamepro and RomVault read.
One game per bios/<Manufacturer>/<Console>/ folder, named
Manufacturer\\Console, each file a rom named by its path below that
folder, subfolders joined with a backslash as Logiqx DATs write them. An auditor checking a BIOS tree against the
collection had JSON, CSV and SQLite, and a converter to write.
"""
games: dict[str, list[dict]] = {}
files = db.get("files", {})
# Every copy, not the one path the database keeps: an audit of bios/
# read the 2,502 others as unknown files, and a fix moved them away
# from the engines that read them by path.
for sha1, paths in collection_paths(db).items():
for path in sorted(paths):
parts = path.split("/")
folder = parts[1:3] if len(parts) > 3 else parts[1:2]
# A backslash is how a Logiqx set name writes a subfolder: named
# "Sony - PlayStation", the set was looked for beside Sony/, and an
# audit of a copy of bios/ found 330 sets missing.
games.setdefault("\\".join(folder), []).append(
{**files[sha1], "_rom": "\\".join(parts[1 + len(folder):])}
)
return _logiqx(SITE_NAME, f"{SITE_NAME} collection ({sum(map(len, games.values()))} files)",
games, generated_at)
def _write_platform_dats(folder: Path, db: dict, members: dict, generated_at: str) -> list[Path]:
"""downloads/dat/<platform>.dat for each install manifest."""
folder.mkdir(parents=True, exist_ok=True)
digests = _data_member_digests(members)
written = []
for source in sorted((_REPO_ROOT / "install").glob("*.json")):
manifest = json.loads(source.read_text(encoding="utf-8"))
path = folder / f"{source.stem}.dat"
write_if_changed(str(path), platform_dat(manifest, db, digests, generated_at))
written.append(path)
return written
def platform_dat(manifest: dict, db: dict, member_digests: dict[str, dict[str, str]],
generated_at: str) -> str:
"""What one setup's BIOS folder holds once installed, as a Logiqx DAT.
One game named after the folder (`bios`, `system`), each file a rom
named by its place below it, as the install manifest writes it: the
files of the setup's list and those its cores load, and the members of
its data directories. A Batocera user auditing share/bios against the
collection DAT met thousands of sets laid out by manufacturer.
"""
files = db.get("files", {})
roms: list[dict] = []
for entry in manifest.get("files") or []:
if entry.get("root") == "save":
continue # installed in the save directory, not this folder
sha1 = str(entry.get("sha1", ""))
roms.append({**files.get(sha1, {}), "sha1": sha1, "size": entry.get("size", 0),
"_rom": str(entry["dest"]).replace("/", "\\")})
for tree in manifest.get("data_directories") or []:
dest = str(tree.get("dest") or "").strip("/")
for member, info in (tree.get("files") or {}).items():
sha1 = str(info.get("sha1", ""))
path = f"{dest}/{member}" if dest else member
roms.append({**member_digests.get(sha1, {}), "sha1": sha1,
"size": info.get("size", 0), "_rom": path.replace("/", "\\")})
folder = str(manifest.get("base_destination") or "bios").strip("/").rsplit("/", 1)[-1]
name = f"{SITE_NAME} - {manifest.get('display_name') or manifest['platform']}"
unique = list({rom["_rom"]: rom for rom in reversed(roms)}.values())
return _logiqx(name, f"{name} ({len(unique)} files)", {folder: unique}, generated_at)
def _logiqx(name: str, description: str, games: dict[str, list[dict]], generated_at: str) -> str:
"""Games of roms as a Logiqx datafile, each rom's `_rom` its name."""
import xml.etree.ElementTree as ET
root = ET.Element("datafile")
header = ET.SubElement(root, "header")
version = generated_at[:10].replace("-", "")
for tag, text in (
("name", name),
("description", description),
("version", version),
("date", generated_at[:10]),
("author", SITE_NAME),
("homepage", SITE_URL),
("url", REPO_URL),
):
ET.SubElement(header, tag).text = text
for game_name in sorted(games):
game = ET.SubElement(root, "game", name=game_name)
ET.SubElement(game, "description").text = game_name
for entry in sorted(games[game_name], key=lambda e: e["_rom"]):
attributes = {"name": entry["_rom"], "size": str(entry.get("size", 0))}
for attribute, field in (("crc", "crc32"), ("md5", "md5"), ("sha1", "sha1")):
if entry.get(field):
attributes[attribute] = str(entry[field]).lower()
ET.SubElement(game, "rom", attributes)
ET.indent(root, space="\t")
return (
'<?xml version="1.0" encoding="UTF-8"?>\n'
'<!DOCTYPE datafile PUBLIC "-//Logiqx//DTD ROM Management Datafile//EN" '
'"http://www.logiqx.com/Dats/datafile.dtd">\n'
+ ET.tostring(root, encoding="unicode") + "\n"
)
def system_structured_data(slug: str, consoles: dict[str, list]) -> dict:
"""A system page's files for a machine: each card as a CreativeWork.
The pages that hold a card per file published a bare TechArticle with
no file, hash or provenance, while emulator pages listed theirs.
"""
parts = []
for _console, entries in sorted(consoles.items()):
for entry in entries:
sha1 = str(entry.get("sha1") or "")
part: dict = {"@type": "CreativeWork", "name": str(entry.get("name", ""))}
if sha1:
part["url"] = urllib.parse.urljoin(SITE_URL, f"systems/{slug}/#sha1-{sha1[:12]}")
identifiers = [
f"{field}:{str(entry[field]).lower()}"
for field in ("sha1", "md5", "crc32", "sha256") if entry.get(field)
]
if identifiers:
part["identifier"] = identifiers
if entry.get("size"):
part["contentSize"] = f"{entry['size']} B"
citations = [
f"{catalog}: {record.get('dat', '')} ({record.get('name', '')})"
for catalog, record in sorted((entry.get("provenance") or {}).items())
if isinstance(record, dict)
]
if citations:
part["citation"] = citations
parts.append(part)
if len(parts) > SYSTEM_PARTS_IN_FULL:
# A page of cards carried up to 2.6 MB of JSON-LD (game-engines), a
# quarter of its weight: past the cap a page lists its
# catalogue-verified files and points at the full table.
return {
"hasPart": [part for part in parts if part.get("citation")],
"isBasedOn": urllib.parse.urljoin(SITE_URL, "downloads/files.csv"),
}
return {"hasPart": parts} if parts else {}
def platform_structured_data(name: str, coverage: dict) -> dict:
"""A platform page's declarations for a machine reader.
The page printed thousands of hashes while its JSON-LD named only the
page: a crawler could not learn which md5 Batocera requires for a file.
The software and its version are the subject, and each declared file, with
the hashes the platform checks, is a part. Past SYSTEM_PARTS_IN_FULL the
parts give way to the platform-files table, as system pages do.
"""
config = coverage.get("config") or {}
about: dict = {"@type": "SoftwareApplication", "name": str(coverage.get("platform", name))}
if config.get("version"):
about["softwareVersion"] = str(config["version"])
if config.get("homepage"):
about["url"] = str(config["homepage"])
parts = []
for system_id, system in sorted((config.get("systems") or {}).items()):
for entry in system.get("files") or []:
if not isinstance(entry, dict) or not entry.get("name"):
continue
part: dict = {
"@type": "CreativeWork",
"name": str(entry.get("destination") or entry["name"]),
"url": urllib.parse.urljoin(SITE_URL, f"platforms/{name}/#{system_id}"),
}
identifiers = [
f"{field}:{value}"
for field in ("sha1", "md5", "crc32", "sha256")
for value in _hash_values(entry.get(field))
]
if identifiers:
part["identifier"] = identifiers
parts.append(part)
data: dict = {"about": about}
if len(parts) > SYSTEM_PARTS_IN_FULL:
data["isBasedOn"] = urllib.parse.urljoin(SITE_URL, "downloads/platform-files.csv")
elif parts:
data["hasPart"] = parts
return data
def dataset_structured_data(exports: list[dict], db: dict) -> dict:
"""The data page as a schema.org Dataset a harvester can index.
It was a Dataset named "Data & API" with no download, licence, date or
creator, so Google Dataset Search and open-data catalogues had nothing
to list. The exports are metadata this project authors: MIT, as the
LICENSE's scope says.
"""
data: dict = {
"name": f"{SITE_NAME} collection data",
"license": "https://opensource.org/licenses/MIT",
"creator": {"@type": "Organization", "name": SITE_NAME, "url": REPO_URL},
"distribution": [
{
"@type": "DataDownload",
"name": item["title"],
"contentUrl": urllib.parse.urljoin(SITE_URL, item["url"]),
"encodingFormat": item["media_type"],
"contentSize": f"{item['bytes']} B",
"sha256": item["sha256"],
}
for item in exports
],
}
generated = str(db.get("generated_at") or "")[:10]
if generated:
data["dateModified"] = generated
return data
def emulator_file_aliases(files: list[dict], anchors: list[str]) -> list[str]:
"""The plain file-<path> id each card also answers to, or "".
A link cited as emulators/raze/#file-duke3d-grp must still land once the
card is addressed by its hash: the first card of that path keeps the
plain id, unless another card already is it.
"""
taken = set(anchors)
aliases = []
for f, anchor in zip(files, anchors):
base = "file-" + (
re.sub(
r"[^a-z0-9]+", "-",
str(f.get("path") or f.get("standalone_path") or f.get("name", "")).lower(),
).strip("-") or "entry"
)
if base in taken or anchor == base:
aliases.append("")
else:
taken.add(base)
aliases.append(base)
return aliases
# A commit id: hexadecimal with a letter and a digit, 7 to 40 long. A version
# that holds one (0.8.139-2-g25e1ee2fd5) names no release.
_COMMIT_ID = re.compile(
r"(?<![0-9a-f])(?=[0-9a-f]*[a-f])(?=[0-9a-f]*[0-9])[0-9a-f]{7,40}(?![0-9a-f])", re.I)
def release_versions(profile: dict) -> dict[str, str]:
"""The `core_version` of a profile by build mode ("" when one covers
every build), kept only where it names a release: a number and no
commit id. A commit id of digits only reads as a number, so a run that
starts one of the profile's own pins is one too (supermodel3's
"0.3a-1481545-mm")."""
pins = [str(value).casefold()
for field in ("source_commit", "upstream_commit")
for value in (profile[field].values() if isinstance(profile.get(field), dict)
else [profile.get(field)])
if value]
def names_a_commit(value: str) -> bool:
return bool(_COMMIT_ID.search(value)) or any(
pin.startswith(run) for run in re.findall(r"[0-9a-f]{7,40}", value.casefold())
for pin in pins)
stated = profile.get("core_version")
pairs = stated.items() if isinstance(stated, dict) else [("", stated)]
versions = {str(mode): str(value or "").strip() for mode, value in pairs}
return {mode: value for mode, value in versions.items()
if re.search(r"[0-9]", value) and not names_a_commit(value)}
def record_emulator_page(name: str, profile: dict) -> None:
"""What the title and the description of an emulator page read."""
key = f"emulators/{name}.md"
PAGE_DATA[key] = emulator_structured_data(profile)
listed = [f for f in profile.get("files") or [] if isinstance(f, dict)]
fetched = [f for f in listed if f.get("name") and not comes_with_app(f)]
systems = profile.get("systems") or []
first = systems[0] if systems else ""
makers = [_system_page_map[sys_id][0] for sys_id in systems if sys_id in _system_page_map]
if makers:
sitestarlight.EMULATOR_CARDS[f"emulators/{name}"] = makers[0]
else:
sitestarlight.EMULATOR_CARDS.pop(f"emulators/{name}", None)
# The first system's files first: "dreamcast bios" found Flycast's
# page, whose required NAOMI archives came before dc_boot.bin.
names: dict[str, str] = {}
for f in sorted(fetched, key=lambda f: (f.get("system", first) != first,
f.get("required") is not True)):
base = Path(str(f["name"])).name
names.setdefault(base.casefold(), base)
firmware = [f for f in fetched if f.get("category", "bios") in ("bios", "bios_zip")]
EMULATOR_SNIPPETS[key] = (
# One console names an emulator of five systems, not BizHawk of 40.
system_name(first) if 0 < len(systems) <= 5 else "",
list(names.values()),
len({Path(str(f["name"])).name.casefold() for f in fetched if f.get("required") is True}),
_snippet_noun(names.values(), len(firmware), len(fetched)),
)
if listed and all(comes_with_app(f) for f in listed):
NOTHING_TO_FETCH.add(key)
else:
NOTHING_TO_FETCH.discard(key)
def emulator_structured_data(profile: dict) -> dict:
"""What an emulator page states, for a reader of its JSON-LD.
The block said only the page name: a crawler could not learn which files
the core loads, their hashes, the source read or when.
"""
data: dict = {}
# Every repository the profile reads. The source repository carries the
# release the profile describes, never a commit id: a pin is no version.
# The upstream of a port is another code base and states none.
versions = release_versions(profile)
about = []
seen: set[str] = set()
for field in ("source", "upstream"):
urls = profile.get(field)
for mode, url in (urls.items() if isinstance(urls, dict) else [("", urls)]):
if not url or not str(url).startswith("http") or str(url) in seen:
continue
seen.add(str(url))
entry = {
"@type": "SoftwareSourceCode",
"name": str(profile.get("emulator", "")),
"codeRepository": str(url),
}
version = (versions.get(mode) or versions.get("")) if field == "source" else None
if version:
entry["version"] = version
about.append(entry)
if about:
data["about"] = about[0] if len(about) == 1 else about
if profile.get("profiled_date"):
data["dateModified"] = str(profile["profiled_date"])
parts = []
files = [f for f in profile.get("files") or [] if isinstance(f, dict)]
for f, anchor in zip(files, emulator_file_anchors(files)):
if not f.get("name"):
continue
# One identifier per accepted value: "sha256:a,b,c,d" matched no
# exact search (mesence's BS-X.bin).
identifiers = [
f"{field}:{value}"
for field in ("sha1", "sha256", "md5", "crc32")
for value in _hash_values(f.get(field))
]
part: dict[str, object] = {
"@type": "CreativeWork",
"name": str(f.get("path") or f["name"]),
# The card's own anchor, as system and platform parts carry.
"url": f"#{anchor}",
}
if identifiers:
part["identifier"] = identifiers
# An archive is identified by its members: MAME and FBNeo hash them,
# never the ZIP, and 1 338 archive parts had no identifier at all.
members = [
{
"@type": "CreativeWork",
"name": str(member.get("name", "")),
"identifier": [
f"{field}:{value}"
for field in ("sha1", "crc32")
for value in _hash_values(member.get(field))
],
}
for member in f.get("contents") or []
if isinstance(member, dict) and member.get("name")
and (member.get("sha1") or member.get("crc32"))
]
if members:
part["hasPart"] = members
parts.append(part)
if len(parts) > SYSTEM_PARTS_IN_FULL:
# MAME's 1,564 entries and their members were 614 KB of JSON-LD: past
# the cap the members are left to the profile's JSON.
for part in parts:
part.pop("hasPart", None)
if parts:
data["hasPart"] = parts
return data
+622
View File
@@ -0,0 +1,622 @@
"""The system pages: each manufacturer's, its consoles and arcade boards."""
from __future__ import annotations
import dataclasses
import functools
import html
import json
import re
import urllib.request
from dataclasses import dataclass
from model.collection import SECTION_LABELS, _slug
from model.composition import GAME_DATA_TOPS
from packs.crossref import FileConsumers
from sitegen import markup
from sitegen.cards import _icon_symbol
from sitegen.config import _REPO_ROOT, _date_line
from sitegen.consolecards import (
CARD_HTML_RATIO,
CONSOLE_PAGES,
Card,
INSTALL_HTML_RATIO,
SYSTEM_PAGE_BUDGET,
SYSTEM_SUMMARY_HTML,
_console_cards,
_install_box_weight,
)
from sitegen.decorate import DEMOTED_WEIGHT, SEARCH_WEIGHT
from sitegen.fields import search_excluded
from sitegen.home import _next_block
from sitegen.install import _console_install_block, _platform_display
from sitegen.parts import _parent_front_matter
from sitegen.render import _count, _slugify_anchor, console_href, record_console_pages
from sitegen.startwith import (
OTHER_ARCADE,
_cards_markdown,
_console_heading,
_parts,
_romset_note,
_section_label,
_start_order,
_start_with,
)
from sitegen.systemsindex import _folder_emulator
_NEXT_FROM_SYSTEMS = [
"[Get the files](../which-pack.md), for the setup in use",
"[When a game does not start](../wiki/troubleshooting.md)",
"[Every emulator](../emulators/index.md), and the files each one reads",
]
# The arcade boards the system pages give a section, by the console key
# their section goes by (the board's name) -> the board's system id. Set by
# arcade_board_sections() before the first system page is written.
_BOARD_CONSOLES: dict[str, str] = {}
# (manufacturer, console) -> the boards whose sets left that folder's
# section for the boards' own pages. The section names them.
_BOARDS_FROM: dict[tuple[str, str], set[str]] = {}
@dataclass
class _BoardSort:
"""Where each archive goes: its board, the machine that owns it, or the
folder it sits in."""
boards: dict[str, list] = dataclasses.field(default_factory=dict)
folders: dict[str, list] = dataclasses.field(default_factory=dict)
seen: dict[str, set[str]] = dataclasses.field(default_factory=dict)
# The sets a reviewed machine owns go to its section: neogeo.zip sat on
# five Arcade pages, the Atom's and the MZ-2000's sets on board pages.
machines: dict[tuple[str, str], list] = dataclasses.field(default_factory=dict)
makers: dict[str, dict[str, list]] = dataclasses.field(default_factory=dict)
def file_on_board(self, board: str, f: dict) -> None:
# One card per content: a copy under Arcade and one under MAME
# are the same file.
if str(f.get("sha1", "")) in self.seen.setdefault(board, set()):
return
self.seen[board].add(str(f.get("sha1", "")))
self.boards.setdefault(board, []).append(f)
def arcade_folders(self, arcade: dict[str, list], by_name: dict[str, str]) -> None:
"""The folders of bios/Arcade/, each file to its board or machine."""
from sitegen.render import arcade_board, archive_machine
from model.collection import record_card_move
for console in sorted(arcade):
joined = by_name.get(console.casefold())
for f in arcade[console]:
sha1 = str(f.get("sha1", ""))
board = joined or arcade_board(sha1)
machine = None if board else archive_machine(sha1)
if board is not None:
self.file_on_board(board, f)
elif machine is not None:
self.machines.setdefault(machine, []).append(f)
record_card_move("Arcade", console, sha1, *machine)
else:
self.folders.setdefault(console, []).append(f)
def maker_folders(self, manufacturers: dict[str, dict[str, list]]) -> None:
"""A board's set filed under a machine's folder is on the board's page
too, whatever the folder: naomi.zip under the Dreamcast was the copy
five setups list, and the NAOMI page did not name it."""
from sitegen.render import arcade_board, archive_machine
from model.collection import record_card_move
for mfr, consoles in manufacturers.items():
if mfr == "Arcade":
continue
for console, files in consoles.items():
kept = []
for f in files:
sha1 = str(f.get("sha1", ""))
board = arcade_board(sha1)
machine = None if board else archive_machine(sha1)
if board is not None:
self.file_on_board(board, f)
_BOARDS_FROM.setdefault((mfr, console), set()).add(board)
elif machine is not None and machine != (mfr, console):
# The Atom's own set sat with the BBC Micro.
self.machines.setdefault(machine, []).append(f)
record_card_move(mfr, console, sha1, *machine)
else:
kept.append(f)
if len(kept) != len(files):
self.makers.setdefault(mfr, dict(consoles))[console] = kept
def machine_sections(self, manufacturers: dict[str, dict[str, list]]) -> None:
"""The sets a machine owns, added to its section."""
for (mfr, console), files in sorted(self.machines.items()):
consoles = self.makers.setdefault(mfr, dict(manufacturers.get(mfr, {})))
held = {str(f.get("sha1", "")) for f in consoles.get(console, [])}
consoles[console] = [*consoles.get(console, []),
*(f for f in files if str(f.get("sha1", "")) not in held)]
def _installs_by_board(
installs: dict[str, dict[str, list[tuple[str, str]]]],
) -> dict[str, dict[str, list[tuple[str, str]]]]:
"""A system's install commands, moved to its board's section."""
from sitegen.render import system_section
moved: dict[str, dict[str, list[tuple[str, str]]]] = {}
for slug, consoles in installs.items():
for console, pairs in consoles.items():
for platform, sys_id in pairs:
section = system_section(sys_id)
if section and section[0] == "arcade" and section[1] in _BOARD_CONSOLES:
slug_to, console_to = section
else:
slug_to, console_to = slug, console
moved.setdefault(slug_to, {}).setdefault(console_to, []).append((platform, sys_id))
return moved
def arcade_board_sections(
manufacturers: dict[str, dict[str, list]],
installs: dict[str, dict[str, list[tuple[str, str]]]],
) -> tuple[dict[str, dict[str, list]], dict[str, dict[str, list[tuple[str, str]]]]]:
"""The Arcade page grouped by board, and each board's install commands.
The Arcade sections were the folders of bios/Arcade/: NAOMI, PGM and
ZN-1 had no section, and their names stayed plain on 568 emulator
pages. Each archive goes to the board siterender.arcade_board() reads
from the profiles, never from its folder, and a folder named after a
board (Namco System 246) joins it, whatever maker's folder holds the
copy. A set a reviewed machine owns (siterender.archive_machine) goes
to that machine's section. Files neither claims stay in their
folders. Each board is recorded (siterender.record_board_section) before
any page links one, and a system's install commands follow its link to
the board's section. Call after reset_console_pages()."""
from sitegen.render import arcade_boards, record_board_section
_BOARD_CONSOLES.clear()
_BOARDS_FROM.clear()
arcade = manufacturers.get("Arcade")
if not arcade:
return manufacturers, installs
names = arcade_boards()
by_name = {name.casefold(): board for board, name in names.items()}
sort = _BoardSort()
sort.arcade_folders(arcade, by_name)
sort.maker_folders(manufacturers)
sort.machine_sections(manufacturers)
for board in sorted(sort.boards):
record_board_section(board)
_BOARD_CONSOLES[names[board]] = board
regrouped = {**sort.folders, **{names[board]: files for board, files in sort.boards.items()}}
makers = {mfr: {console: files for console, files in consoles.items() if files}
for mfr, consoles in sort.makers.items()}
return {**manufacturers, **makers, "Arcade": regrouped}, _installs_by_board(installs)
def _boards_line(manufacturer: str, console: str) -> list[str]:
"""The line of a section whose board sets went to the boards' pages:
the Dreamcast folder holds NAOMI's and Atomiswave's."""
from sitegen.render import arcade_boards
boards = _BOARDS_FROM.get((manufacturer, console))
if not boards:
return []
names = arcade_boards()
links = [f"[{names[board]}]({console_href('arcade', names[board]).removeprefix('systems/')})"
for board in sorted(boards, key=lambda b: names[b].casefold())]
return [f"**Arcade board BIOS** on the boards' own pages: {', '.join(links)}.", ""]
def _part_name(manufacturer: str, console: str) -> str:
"""What a part's title calls the files: "Arcade files a to b"."""
if (manufacturer, console) == OTHER_ARCADE:
return "Arcade"
return SECTION_LABELS.get((manufacturer, console), console)
def _system_front_matter(
parent: tuple[str, str] | None = None,
prev: tuple[str, str] | None = None,
following: tuple[str, str] | None = None,
weight: float | None = None,
consoles: list[str] | None = None,
) -> list[str]:
"""The front matter of a system page: the page it belongs to, the
parts before and after it (label, site path), its search weight and
the consoles it holds, which the search reads as a field."""
lines = _parent_front_matter(parent)
for key, link in (("prev", prev), ("next", following)):
if link:
lines += [f"{key}:", f" label: {json.dumps(link[0])}", f" link: {json.dumps(link[1])}"]
if weight is not None:
lines.append(f"searchWeight: {weight}")
if consoles:
lines += ["consoles:", *(f" - {json.dumps(name)}" for name in consoles)]
return ["---", *lines, "---", ""] if lines else []
def _part_weight() -> float:
"""The search weight of a part page: its cards keep their own weight."""
return SEARCH_WEIGHT.get("part", DEMOTED_WEIGHT)
@functools.cache
def _manifest_systems(platform: str) -> frozenset[str]:
"""The system ids a platform's install manifest records: --system
refuses any other."""
manifest = _REPO_ROOT / "install" / f"{platform}.json"
if not manifest.is_file():
return frozenset()
document = json.loads(manifest.read_text(encoding="utf-8"))
return frozenset(
str(system)
for entry in (document.get("files") or []) + (document.get("omitted_files") or [])
for system in entry.get("systems") or []
)
def _install_pairs(
declared: list[tuple[str, str]], lead: str | None, consumers: FileConsumers,
) -> list[tuple[str, str]]:
"""A section's install commands: the setups whose system leads here,
then each setup that files the section's first file under a system of
its own (RetroArch files neogeo.zip under arcade), with that id."""
pairs = list(declared)
have = {platform for platform, _system in pairs}
for platform, systems in sorted(getattr(consumers, "platform_systems", {})
.get(lead or "", {}).items()):
if platform in have:
continue
recorded = [s for s in sorted(systems) if s in _manifest_systems(platform)]
if recorded:
pairs.append((platform, recorded[0]))
have.add(platform)
return sorted(pairs, key=lambda pair: (_platform_display(pair[0]).casefold(), pair[1]))
@dataclass(frozen=True)
class _ConsoleParts:
"""A console moved to pages of its own: the pages and what each holds."""
label: str
stems: list[str]
parts: list[list[Card]]
titles: list[str]
lead: set[str]
def _card_weight(card: list[str]) -> int:
return sum(len(line) + 1 for line in card)
@dataclass
class _MakerPages:
"""What a manufacturer's pages are built from, and how each part reads."""
manufacturer: str
consoles: dict[str, list]
consumers: FileConsumers
installs: dict[str, list[tuple[str, str]]]
budget: int
slug: str = ""
boards: dict[str, str] = dataclasses.field(default_factory=dict)
json_next: str = ""
ordered: list[str] = dataclasses.field(default_factory=list)
starts: dict[str, list[str]] = dataclasses.field(default_factory=dict)
intro: str = ""
legend: list[str] = dataclasses.field(default_factory=list)
machines: list[str] = dataclasses.field(default_factory=list)
front: list[str] = dataclasses.field(default_factory=list)
def __post_init__(self) -> None:
manufacturer, consoles = self.manufacturer, self.consoles
self.slug = _slug(manufacturer)
self.boards = {console: _BOARD_CONSOLES[console] for console in consoles
if manufacturer == "Arcade" and console in _BOARD_CONSOLES}
self.json_next = (f"[Every hash of these files, as JSON](../api/v1/systems/"
f"{urllib.parse.quote(self.slug)}.json)")
# Boards first on the Arcade page, then the folders of sets for many
# machines. Such a folder starts nowhere: its line named konamigv.zip,
# sys573.zip and 97 more, files of boards with lines of their own.
boards = self.boards
self.ordered = sorted(consoles, key=lambda c: (bool(boards) and c not in boards, c))
self.starts = {console: [] if boards and console not in boards
else _start_order(consoles[console], self.consumers, (manufacturer, console))
for console in consoles}
# One line, then the legend closed: four paragraphs said the same on
# every maker's page before its first console.
self.intro = f"Every BIOS file for {manufacturer} machines, one card per file."
self.legend = search_excluded(markup.details("note", "How to read a card", [
"A card gives the file's fingerprints, the emulators that read it, the setups "
"that list it and where to download it. A file can have several versions, one "
"per region or revision: the main one comes first, the others under "
"\"Variants\". To install the files of one console, open its \"Install\" box.",
"",
"**On the setup's list** names the setups whose own BIOS list has the file, by "
"the name each gives it. **Packed for its emulators by** names the setups whose "
"pack adds it because one of their emulators reads it.",
]))
# The consoles a page answers for, a search field: machines only. An
# emulator's folder under Other put that page first for "dolphin", and
# a console with a page of its own is that page's to answer for.
self.machines = [console for console in self.ordered
if manufacturer not in ("Other", *GAME_DATA_TOPS)
and (manufacturer != "Arcade" or console in boards)]
self.front = self.consoles_front()
def start_of(self, console: str, first_below: bool = True) -> list[str]:
if self.boards and console not in self.boards:
return []
return [*_start_with(self.consoles[console], self.consumers, first_below,
(self.manufacturer, console)),
*_boards_line(self.manufacturer, console)]
def cards_of(self, console: str, anchors: set[str], by_name: bool = False) -> list[Card]:
return _console_cards(self.manufacturer, self.consoles[console], self.consumers, anchors,
by_name, self.starts[console])
def install_block(self, console: str) -> list[str]:
lead = self.starts[console][0] if self.starts[console] else None
return _console_install_block(
_section_label(self.manufacturer, console),
_install_pairs(self.installs.get(console, []), lead, self.consumers))
def all_sections(self) -> dict[str, list[Card]]:
anchors: set[str] = set()
return {console: self.cards_of(console, anchors) for console in self.ordered}
def consoles_front(self, kept: set[str] | None = None) -> list[str]:
return _system_front_matter(consoles=[
_section_label(self.manufacturer, c) for c in self.machines
if kept is None or c in kept])
def head(self, front: list[str]) -> list[str]:
"""A maker's page down to its first console."""
return [
*front, f"# {self.manufacturer}", "", self.intro, "", *self.legend,
*_romset_note(self.consoles), *_icon_symbol(),
]
def whole_page(self, sections: dict[str, list[Card]]) -> str:
lines = self.head(self.front)
for console, cards in sections.items():
lines.append(_console_heading(self.manufacturer, console,
_section_label(self.manufacturer, console)))
lines.append("")
lines.extend(self.start_of(console))
lines.extend(self.install_block(console))
lines.extend(_cards_markdown(cards))
lines.append("")
lines.extend(_next_block([*_NEXT_FROM_SYSTEMS, self.json_next]))
lines.extend(["", _date_line()])
return "\n".join(lines) + "\n"
def cut(self, console: str, by_name: bool) -> list[list[Card]]:
"""A console's cards in parts of at most the budget, evened out."""
# Cards are rendered again for their own page: the anchors a page
# holds are its own.
cards = self.cards_of(console, set(), by_name)
with markup.using("mkdocs"):
sizes = [_card_weight(card) for _variant, card, _sha1 in self.cards_of(
console, set(), by_name)]
parts = _parts(cards, self.budget, sizes)
if len(parts) < 2:
return parts
# Even parts: cut at budget, the PlayStation 2 was 137 cards
# and 4. The same number of parts, each near the mean.
share = -(-sum(sizes) // len(parts))
even = _parts(cards, share, sizes)
while len(even) > len(parts):
share += max(1, share // 50)
even = _parts(cards, share, sizes)
return even
def moved(self, weights: dict[str, int], rendered: dict[str, float]) -> set[str]:
"""Every board has a page of its own. Then the heaviest sections move
to pages of their own until what stays on the manufacturer's page is
half the budget: a section of one file keeps its place, and a reader
does not open 91 pages to browse Other."""
moved: set[str] = set(self.boards) | (
set(self.consoles) if self.manufacturer in CONSOLE_PAGES else set())
for console in sorted(weights, key=lambda c: (-weights[c], c)):
if sum(w for c, w in weights.items() if c not in moved) <= self.budget // 2:
break
moved.add(console)
# Then until what stays holds its estimate as it renders.
for console in sorted(rendered, key=lambda c: (-rendered[c], c)):
if sum(w for c, w in rendered.items() if c not in moved) <= SYSTEM_SUMMARY_HTML:
break
moved.add(console)
return moved
def part_page(self, console: str, index: int, plan: _ConsoleParts) -> str:
"""Part ``index`` of a console moved to pages of its own."""
stems, part, label = plan.stems, plan.parts[index], plan.label
neighbours = [(plan.titles[i], f"/systems/{stems[i]}/")
for i in (index - 1, index + 1) if 0 <= i < len(stems)]
lines = [
*_system_front_matter(
(self.manufacturer, f"/systems/{self.slug}/"),
prev=neighbours[0] if index > 0 else None,
following=neighbours[-1] if index + 1 < len(stems) else None,
weight=_part_weight() if len(stems) > 1 else None,
consoles=[label] if index == 0 and console in self.machines else None),
# The crumbs end on the maker's page: no line says it again.
f"# {plan.titles[index]}", "", *_icon_symbol(),
]
if len(stems) > 1:
others = ", ".join(
f"[part {i + 1}]({other}.md)" for i, other in enumerate(stems) if i != index)
lines.extend([f"This part holds {_part_range(part, plan.lead)}. The others: {others}.",
""])
# A board's page is its one section: its title names it, and a
# heading of the same name said it a third time. Its cards come
# under "Files", as every page of one console's.
if index == 0:
lines.extend(self.start_of(console, len(stems) == 1))
lines.extend(self.legend)
lines.extend(_romset_note({console: self.consoles[console]}))
lines.extend(self.install_block(console))
lines.extend(["## Files", ""])
lines.extend(_cards_markdown(part))
lines.append("")
lines.extend(_next_block([f"[{self.manufacturer}]({self.slug}.md), every section"]
+ _NEXT_FROM_SYSTEMS + [self.json_next]))
lines.extend(["", _date_line()])
return "\n".join(lines) + "\n"
def moved_section(self, console: str, pages: dict[str, tuple[str, dict[str, list]]]) -> list[str]:
"""A console moved to pages of its own: the lines the summary keeps
under its heading. Its pages go into ``pages``."""
from sitegen.render import board_slug
manufacturer = self.manufacturer
label = _section_label(manufacturer, console)
# One page keeps the required files first. Parts are named by their
# first and last file, so a console cut in parts goes by name, the
# files the start line names first.
parts = self.cut(console, False)
if len(parts) > 1:
parts = self.cut(console, True)
board = self.boards.get(console)
base = (f"arcade-{board_slug(board)}" if board
else f"{self.slug}-{_slugify_anchor(console) or 'files'}")
stems = [base if index == 0 else f"{base}-{index + 1}" for index in range(len(parts))]
clash = set(stems) & set(pages)
if clash:
raise RuntimeError(f"two system sections take one page: {sorted(clash)}")
record_console_pages(self.slug, console, stems, [
[sha1 for _variant, _card, sha1 in part] for part in parts
])
lead = set(self.starts[console])
# A part by the files it holds: "Arcade: Arcade, part 3 of 5" said
# nothing a search result could use. A folder under Other goes by
# its emulator's name: "mame files" named the folder.
named = _folder_emulator(console)[0] if manufacturer == "Other" else None
titles = ([f"{manufacturer}: {named or label}"] if len(stems) == 1 else [
"{} files {} to {}".format(named or _part_name(manufacturer, console),
*_part_ends(part, lead))
for part in parts])
count = _count(len(self.consoles[console]), "file")
summary = list(self.start_of(console, False))
if len(stems) == 1:
own = "its" if len(self.consoles[console]) == 1 else "their"
summary.append(f"{count}, on [{own} own page]({stems[0]}.md).")
else:
summary.append(f"{count}, on {len(stems)} pages by file name:")
summary.append("")
for index, (stem, part) in enumerate(zip(stems, parts)):
summary.append(f"- [Part {index + 1}]({stem}.md): {_part_range(part, lead)}")
summary.append("")
plan = _ConsoleParts(label, stems, parts, titles, lead)
for index, (stem, part) in enumerate(zip(stems, parts)):
text = self.part_page(console, index, plan)
held = {sha1 for _variant, _card, sha1 in part}
pages[stem] = (text, {console: [
f for f in self.consoles[console] if str(f.get("sha1", "")) in held]})
return summary
def system_pages(
manufacturer: str,
consoles: dict[str, list],
consumers: FileConsumers,
installs: dict[str, list[tuple[str, str]]] | None = None,
budget: int = SYSTEM_PAGE_BUDGET,
) -> dict[str, tuple[str, dict[str, list]]]:
"""A manufacturer's pages by stem under systems/: one page, or a summary
and a page per console when the whole would pass ``budget``. Each page
comes with the files whose cards it holds, by console.
Every console keeps its heading on the summary, so a link to
systems/<maker>/#<console> still lands, and site.js sends a card
anchor the page no longer holds to the card's new place. The pages
each card and console went to are recorded for every other link
(siterender.record_console_pages). An arcade board has a page of its
own, systems/arcade-<board slug>/, under a heading of that id.
"""
maker = _MakerPages(manufacturer, consoles, consumers, installs or {}, budget)
slug = maker.slug
# Sizes are those of the MkDocs Markdown the budget was set on, so the
# pages split where they always have and no card changes address.
with markup.using("mkdocs"):
measured = maker.all_sections()
measured_text = maker.whole_page(measured)
weights = {
console: sum(_card_weight(card) for _variant, card, _sha1 in cards)
for console, cards in measured.items()
}
# An install box is a few lines of Markdown and about nine times that
# once highlighted: ten of them were 295 KB of the 583 KB Nintendo
# page, which the card weights never counted. A page is also cut when
# its estimate as it renders passes the summary's.
with markup.using("mkdocs"):
boxes = {console: _install_box_weight(maker.install_block(console)) for console in consoles}
rendered = {console: CARD_HTML_RATIO * weights[console] + INSTALL_HTML_RATIO * boxes[console]
for console in weights}
if (not maker.boards and manufacturer not in CONSOLE_PAGES and len(measured_text) <= budget
and sum(rendered.values()) <= SYSTEM_SUMMARY_HTML):
text = maker.whole_page(maker.all_sections()) if markup.starlight() else measured_text
return {slug: (text, consoles)}
moved = maker.moved(weights, rendered)
pages: dict[str, tuple[str, dict[str, list]]] = {}
summary = maker.head(maker.consoles_front(set(consoles) - moved))
summary_anchors: set[str] = set()
for console in maker.ordered:
label = _section_label(manufacturer, console)
summary.append(_console_heading(manufacturer, console, label))
summary.append("")
if console not in moved:
summary.extend(maker.start_of(console))
summary.extend(maker.install_block(console))
summary.extend(_cards_markdown(maker.cards_of(console, summary_anchors)))
summary.append("")
continue
summary.extend(maker.moved_section(console, pages))
summary.extend(_next_block([*_NEXT_FROM_SYSTEMS, maker.json_next]))
summary.extend(["", _date_line()])
kept = {console: files for console, files in consoles.items() if console not in moved}
return {slug: ("\n".join(summary) + "\n", kept), **pages}
def _part_ends(part: list[Card], lead: set[str] | frozenset[str] = frozenset()) -> tuple[str, str]:
"""The first and last file names of a part, as the cards show them.
The files a start line puts first are left out when the part holds
others: the range is the run by name that follows them."""
named = [card for card in part if card[2] not in lead] or part
names = []
for _variant, card, _sha1 in named:
# An HTML heading on the site, a Markdown one in the size yardstick.
match = re.search(r"`([^`]*)`|<code>(.*?)</code>", card[2])
if match is None:
raise ValueError(f"a card heading names no file: {card[2]!r}")
names.append(match[1] if match[1] is not None else html.unescape(match[2]))
return names[0], names[-1]
def _part_range(part: list[Card], lead: set[str] | frozenset[str] = frozenset()) -> str:
"""The first and last file names of a part, with its count."""
first, last = _part_ends(part, lead)
if len(part) == 1:
return f"`{first}`"
return f"{_count(len(part), 'file')}, `{first}` to `{last}`"
def generate_system_page(
manufacturer: str,
consoles: dict[str, list],
consumers: FileConsumers,
installs: dict[str, list[tuple[str, str]]] | None = None,
) -> str:
"""One manufacturer's page, a section per console.
``installs`` gives, per console, the (platform, system id) pairs whose
install command the section offers. A page over the budget is the
summary system_pages writes, its consoles on pages of their own.
"""
return system_pages(manufacturer, consoles, consumers, installs)[_slug(manufacturer)][0]
+145
View File
@@ -0,0 +1,145 @@
"""The systems index."""
from __future__ import annotations
from model.collection import SECTION_LABELS, _profiles_on_disk, _slug
from model.composition import GAME_DATA_TOPS
from sitegen import starlight as sitestarlight
from sitegen.render import _count, console_href
from sitegen.startwith import _section_label
def _console_display(manufacturer: str, console: str) -> str:
"""A console section's name as the reader looks for it: the heading
system_name gives its id, or the folder alone under a program's top
(Other, Arcade), where "Other mame" would name nothing."""
from model.collection import _PROGRAM_TOPS
from model.systemnames import _heading_name
return console if manufacturer in _PROGRAM_TOPS else _heading_name(manufacturer, console)
def generate_systems_index(manufacturers: dict) -> str:
"""Every console in one table, found by its own name.
The index listed 74 manufacturers and no console: someone looking for
PlayStation had to know it is filed under Sony, and Other hid 91
sections. Manufacturer pages stay the containers.
"""
for old, new in SYSTEM_PAGES_MOVED.items():
sitestarlight.MOVED_PAGES.setdefault(old, new)
total_mfr = len(manufacturers)
total_consoles = sum(len(c) for c in manufacturers.values())
# A copy filed under two folders appears on both pages, counted once here.
total_files = len({
f.get("sha1") for consoles in manufacturers.values()
for files in consoles.values() for f in files
})
lines = [
"# Systems",
"",
"Every BIOS file the collection holds, by console. Open a console to "
"see each file, the emulators that read it and the setups that list it.",
"",
f"{_count(total_consoles, 'console')}, {_count(total_files, 'file')} in the "
f"repository, from {_count(total_mfr, 'manufacturer')}.",
"",
]
# Other holds one folder per emulator: a7800 or altirra in the console
# table named no console. Arcade boards are neither consoles nor
# computers, and the crumb of their page says Arcade too.
def kind(mfr: str) -> str:
if mfr in GAME_DATA_TOPS:
return "games"
if mfr == "Arcade":
return "arcade"
return "programs" if mfr == "Other" else "consoles"
for heading, group, first, note in (
("Consoles and computers", "consoles", "Console", ""),
("Arcade", "arcade", "Name",
"Arcade boards, and the sets each arcade emulator family reads."),
("Emulator folders", "programs", "Folder",
"Files kept under the emulator that reads them, not under a console."),
("Game engines and PC games", "games", "Name",
"Game engines and PC games hold the files a game engine reads, such "
"as the data of a game, rather than the BIOS of a machine."),
):
rows = sorted(
((_folder_emulator(console)[0] if group == "programs"
else _section_label(mfr, console) if mfr == "Arcade"
or (mfr, console) in SECTION_LABELS
else _console_display(mfr, console), mfr, console, len(files))
for mfr, consoles in manufacturers.items() if kind(mfr) == group
for console, files in consoles.items()),
key=lambda row: (row[0].casefold(), row[1].casefold(), row[2]),
)
if not rows:
continue
lines += [f"## {heading}", ""]
if note:
lines += [note, ""]
if group == "programs":
# Each folder by the emulator's name, linked to its page: the
# rows read a7800 and azaharplus beside console names, and
# every maker cell said Other.
lines += ["| Emulator | Files |", "|---------|------:|"]
for name, mfr, console, count in rows:
href = console_href(_slug(mfr), console).removeprefix("systems/")
key = _folder_emulator(console)[1]
cell = name.replace("|", "-")
cell = f"[{cell}](../emulators/{key}.md)" if key else cell
lines.append(f"| {cell} | [{_count(count, 'file')}]({href}) |")
lines.append("")
continue
lines += [
# The count before the maker: on a phone the last column is
# the one scrolled off, and most names carry the maker already.
f"| {first} | Files | Maker |",
"|---------|------:|-------|",
]
for name, mfr, console, count in rows:
cell = name.replace("|", "-")
href = console_href(_slug(mfr), console).removeprefix("systems/")
lines.append(f"| [{cell}]({href}) | {count:,} | [{mfr}]({_slug(mfr)}.md) |")
lines.append("")
return "\n".join(lines) + "\n"
def _folder_emulator(folder: str) -> tuple[str, str]:
"""The display name and profile of the emulator a folder under Other is
named after, by its profile key or its name, else the folder and "".
"""
profiles = _profiles_on_disk()
if folder in profiles and profiles[folder].get("type") != "alias" and profiles[folder].get("role") != "test":
return str(profiles[folder].get("emulator") or folder), folder
for key in sorted(profiles):
profile = profiles[key]
if profile.get("type") == "alias" or profile.get("role") == "test":
continue
names = {str(profile.get(field) or "").casefold() for field in ("emulator", "display_name")}
if folder.casefold() in names:
return str(profile.get("emulator") or key), key
return folder, ""
# System pages published under an address no page holds since, and where
# their files went: the Atom and the MZ were boards, ScummVM's and SDLPAL's
# files were on two pages, the Dreamcast lost its NAOMI sets. An address
# redirects only while no page takes it back (sitestarlight.redirects).
SYSTEM_PAGES_MOVED = {
"systems/arcade-acorn-atom.md": "systems/acorn.md",
"systems/arcade-sharp-mz-2000.md": "systems/sharp.md",
"systems/arcade-sharp-mz-2500.md": "systems/sharp.md",
"systems/arcade-miuchiz.md": "systems/arcade.md",
"systems/arcade-yamaha-ym2608.md": "systems/arcade.md",
# Oric is filed under its maker since 2026-10-23, and a reader still
# followed the old address to the 404 page.
"systems/oric.md": "systems/tangerine.md#oric",
"systems/other-scummvm.md": "systems/scummvm.md",
"systems/other-sdlpal.md": "systems/sdlpal.md",
"systems/sega-dreamcast.md": "systems/sega.md",
}
+128
View File
@@ -0,0 +1,128 @@
"""The release and version lines the pages state, and stats.json."""
from __future__ import annotations
import re
from datetime import datetime
import release_record
from model import siteinputs
from model.composition import count_catalog_matched
from model.platforms import load_platform_config
from model.profiles import unique_emulator_profiles
from sitegen.config import RELEASE_URL, REPO_URL, _timestamp
def compute_stats(db: dict, coverages: dict, profiles: dict) -> dict:
unique = unique_emulator_profiles(profiles)
systems: set[str] = set()
for p in unique.values():
systems.update(p.get("systems", []))
return {
"schema_version": 1,
"generated_at": _timestamp(),
"files": db.get("total_files", 0),
"size_bytes": db.get("total_size", 0),
"platforms": len(coverages),
"emulators": len(unique),
"systems": len(systems),
"catalog_matched": count_catalog_matched(db),
"source": REPO_URL,
"downloads": RELEASE_URL,
}
def _release_date(tag: str) -> str:
"""The date a release tag names (v2026.10.10), in words, or empty."""
match = re.fullmatch(r"v(\d{4})\.(\d{2})\.(\d{2})", tag or "")
if not match:
return ""
moment = datetime(int(match[1]), int(match[2]), int(match[3]))
return f"{moment.day} {moment.strftime('%B %Y')}"
def _pack_version(pack_name: str, platforms: list[str]) -> str:
"""The platform version a pack was built for, from its name
(Batocera_43.1_BIOS_Pack.zip is 43.1).
Read past the platform part the builder writes, not at the last
underscore: AmberELEC_prerelease-20261019_1835 read as 1835.
"""
from packs.naming import platform_pack_prefix
stem = pack_name.removesuffix("_BIOS_Pack.zip")
prefix = platform_pack_prefix(
platforms, platforms[0], str(siteinputs.current().platforms)
) + "_"
return stem[len(prefix):] if stem.startswith(prefix) else ""
def _pack_platforms(platform_name: str, record: dict, pack_name: str) -> list[str]:
"""The platforms a release pack was built for, the one asked first."""
listed = list(record.get("packs", {}).get(pack_name, {}).get("platforms") or [])
return listed or [platform_name]
def release_line(platform_name: str, record: dict) -> list[str]:
"""Which release the buttons serve, with its checksums and signature, and
the version gap when the page describes a newer platform than the pack."""
tag = record.get("tag")
pack_name = release_record.pack_name_for(platform_name, record)
if not tag or not pack_name:
return []
base = f"{REPO_URL}/releases/download/{tag}"
built = _release_date(tag)
lines = [
f"Pack {tag}{f', built {built}' if built else ''}. "
f"[SHA256SUMS.txt]({base}/SHA256SUMS.txt) and its "
f"[signature]({base}/SHA256SUMS.txt.sig).",
]
config = load_platform_config(platform_name, str(siteinputs.current().platforms))
page_version = str(config.get("version") or "")
pack_version = _pack_version(
pack_name, _pack_platforms(platform_name, record, pack_name)
)
if page_version and pack_version and page_version.lstrip("v") != pack_version.lstrip("v"):
display = config.get("platform", platform_name)
lines.append(f"This pack was built for {display} {pack_version}. The command "
f"installs the files for {display} {page_version}.")
return lines
def other_version(platform_name: str, prefix: str = "../") -> str:
"""What a reader on another version of the setup does with the pack.
Our data says which list the pack was made from, not what an older list
lacks. A bare `--check` was no command to run for someone holding a ZIP:
the line links the setup page's commands that check."""
target = f"{prefix}platforms/{platform_name}.md#how-to-check"
return f"Other version? [Check the files]({target}) after copying."
def setup_version(platform_name: str, record: dict | None = None) -> str:
"""The setup and version whose BIOS list the pack was made from
("Batocera 43.1"): the version in the pack's name, else the version the
platform YAML was read at. Empty when neither says, or when the
platform has no YAML to read a version from."""
try:
config = load_platform_config(platform_name, str(siteinputs.current().platforms))
except FileNotFoundError:
return ""
pack_name = release_record.pack_name_for(platform_name, record or {})
version = (
_pack_version(pack_name, _pack_platforms(platform_name, record or {}, pack_name))
if pack_name else ""
) or str(config.get("version") or "")
if not version:
return ""
return f"{config.get('platform', platform_name)} {version.removeprefix('v')}"
def version_line(platform_name: str, record: dict, named: bool = False,
prefix: str = "../") -> str:
"""The version the pack fits, and what to do on another. *named* when
the release line already named the pack's version."""
made_from = setup_version(platform_name, record)
other = other_version(platform_name, prefix)
if named or not made_from:
return other
return f"Made for {made_from}. {other}"
+302
View File
@@ -0,0 +1,302 @@
"""The which-pack page: the folder each setup reads."""
from __future__ import annotations
import release_record
from core.paths import REPO_ROOT
from core.ziptools import build_zip_contents_index
from model import siteinputs
from model.guides import (
ALSO_RUNS,
DEVICE_GROUPS,
GROUP_ANCHORS,
GUIDES,
Guide,
PACKAGE_COMMAND,
TERMINALS,
install_command,
)
from model.platforms import load_platform_config
from model.registry import load_platform_registry
from packs.crossref import FileConsumers
from sitegen import markup, steps as sitesteps
from sitegen.config import RELEASE_URL
from sitegen.guidepage import NO_ZIP_FAQ, devices_meta, first_screen_words, get_page_link
from sitegen.guides import fence, terminal_tabs, trust_box
from sitegen.home import _group_keys, _next_block, _runs_on, setup_picker
from sitegen.install import _installer, has_release_pack
from sitegen.readme import NO_PACK, download_links
from sitegen.render import _fmt_size
# Build cross-reference indexes
def _build_file_consumers(db: dict, coverages: dict, profiles: dict) -> FileConsumers:
"""Which platforms and emulators read each collected file."""
consumers = FileConsumers(db, build_zip_contents_index(db))
consumers.add_platforms({name: cov["config"] for name, cov in coverages.items()})
consumers.add_emulators(profiles)
consumers.add_manifests(REPO_ROOT / "install")
return consumers
def _build_emulator_file_index(profiles: dict) -> dict[str, dict]:
"""Map emulator_name -> {systems, norm}, for the platform pages.
norm holds the systems as _norm_system_id reads them: a platform files
the Mega Drive as sega-mega-drive and genesis_plus_gx as sega-megadrive,
and an exact match left the RetroArch page with no emulator for it.
"""
from model.systems import _norm_system_id
return {
name: {
"systems": set(profile.get("systems", [])),
"norm": {_norm_system_id(str(s)) for s in profile.get("systems", [])},
# Archive members are read inside their archive, never by name.
"names": {
str(entry["name"]).lower()
for entry in profile.get("files") or []
if isinstance(entry, dict) and entry.get("name")
and not entry.get("archive")
},
}
for name, profile in profiles.items()
if profile.get("type") != "alias"
}
def _folder_cell(name: str, guide: Guide, prefix: str = "") -> str:
"""The BIOS folder in a table cell, or a link where it depends on the system."""
if len(guide.folders) > 3:
return f"Depends on the system: [listed on its page]({prefix}platforms/{name}.md#where-the-files-go)"
return "<br>".join(f"{label}: {path}" for label, path in guide.folders)
def _pack_cell(name: str, record: dict, prefix: str = "") -> str:
"""The pack's parts and size, or the command where the release has none."""
if not has_release_pack(name):
return f"No ZIP. [{NO_PACK}]({prefix}platforms/{name}.md#install)."
pack = release_record.pack_for(name, record)
if record.get("tag") and not (pack and pack.get("assets")):
return f"No ZIP yet. [{NO_PACK}]({prefix}platforms/{name}.md#install)."
# One small button to the setup's get/ page, which lists every part, and
# the size after it.
link = download_links(name, record, "ZIP", page=get_page_link(name, prefix),
button=lambda text, url: markup.button(text, url))
size = pack.get("download_size") if pack else None
return f"{link} ({_fmt_size(size)})" if size else link
def _own_root_folders(registry: dict) -> dict[str, str]:
"""Platforms whose pack holds its own top folder, with where it unzips.
The same rule as extract_notes: a list written from an empty base
destination carries its root in every path."""
folders = {}
for key, entry in registry.items():
config = load_platform_config(key, str(siteinputs.current().platforms))
if config.get("base_destination") == "" and entry.get("extract_to"):
folders[key] = entry["extract_to"]
return folders
def _folder_row(key: str, display: dict[str, str], registry: dict, record: dict,
own_root: dict[str, str]) -> str:
"""One setup's row: where it runs, its BIOS folder and its ZIP. A setup
whose ZIP holds its own top folder says where to unzip it, and the
BIOS folder itself when it has no ZIP to unzip."""
guide = GUIDES[key]
pack = release_record.pack_for(key, record)
zipped = bool(pack and pack.get("assets"))
folder = (f"Unzip into `{own_root[key]}`" if key in own_root and zipped
else _folder_cell(key, guide))
return (f"| [{display[key]}](platforms/{key}.md) | "
f"{guide.runs_on or _runs_on(registry[key], guide)} | {folder} | "
f"{_pack_cell(key, record)} |")
def _folder_tables(registry: dict, record: dict, display: dict[str, str]) -> list[str]:
"""Every setup's folder and ZIP, one table per device group, the groups
of one setup together under "Other setups" as on the tiles. A row for
each setup that runs another (LaunchBox, Android) under its group."""
own_root = _own_root_folders(registry)
header = ["| Setup | Runs on | BIOS folder | ZIP |", "|-------|---------|-------------|-----|"]
lines: list[str] = []
alone: list[str] = []
for group, (label, _description) in DEVICE_GROUPS.items():
members = _group_keys(registry, group, display)
if len(members) == 1 and not ALSO_RUNS.get(group):
alone += members
continue
if not members:
continue
lines += [f'<span id="{GROUP_ANCHORS[group]}"></span>**{label}**', "", *header]
lines += [_folder_row(key, display, registry, record, own_root) for key in members]
lines += [
f"| {setup} | {runs_on} | {folder}, same as "
f"[{display[uses]}](platforms/{uses}.md) | {_pack_cell(uses, record)} |"
for setup, _summary, uses, runs_on, folder in ALSO_RUNS.get(group, ())
]
lines.append("")
if alone:
anchors = "".join(f'<span id="{GROUP_ANCHORS[registry[key]["device_group"]]}"></span>'
for key in alone)
lines += [f"{anchors}**Other setups**", "", *header,
*(_folder_row(key, display, registry, record, own_root) for key in alone), ""]
return lines
# iPhone and iPad: no terminal, so each app is filled its own way. Every
# step is the app's own: RetroArch's iOS guide (Files app, On My iPhone >
# RetroArch) and platform_darwin.m (system under Documents/RetroArch), the
# DS BIOS rows of Delta's Settings.storyboard, Provenance's import guide.
IOS_SOURCES = {
"retroarch_docs": "https://github.com/libretro/docs/blob/"
"cfa4c1a17e586c01d3a48e9eda12b6c989f8954f/docs/guides/install-ios.md?plain=1#L94",
"retroarch_code": "https://github.com/libretro/RetroArch/blob/"
"5333a7c5a59e268470834a96f86047d3cb6139a9/frontend/drivers/platform_darwin.m#L438-L459",
"delta": "https://github.com/rileytestut/Delta/blob/"
"c1d3d068e019e6493eed45654569db3cc5beb86a/Delta/Base.lproj/Settings.storyboard#L2448-L2500",
"provenance": "https://wiki.provenance-emu.com/using-provenance/importing-roms",
}
IOS_DEVICES = ("iPhone", "iPad", "iOS", "Delta", "Provenance")
# The same names as which-pack's search terms, the section's meta field
# alone leaving "ios" unanswered.
IOS_TERMS = tuple(name.lower() for name in IOS_DEVICES)
def ios_section() -> list[str]:
"""The section the iPhone and iPad tile opens: the consoles picked on a
computer, then each app's own way in."""
return [
"## iPhone and iPad { #iphone-and-ipad }",
"",
devices_meta(IOS_DEVICES),
"",
"[Pick the consoles](which-pack.md?platform=retroarch#only-some-consoles) "
"on a computer. Copy them to the app.",
"",
"- **RetroArch**: Files app, **On My iPhone > RetroArch**, then "
f"`RetroArch/system/` ([docs]({IOS_SOURCES['retroarch_docs']}), "
f"[code]({IOS_SOURCES['retroarch_code']})).",
"- **Delta**, for DS games: import `bios7.bin`, `bios9.bin` and `firmware.bin` "
f"in **Settings**, under **Nintendo DS** ([code]({IOS_SOURCES['delta']})).",
"- **Provenance**: share the file, then **Copy to Provenance** "
f"([docs]({IOS_SOURCES['provenance']})).",
"",
]
def generate_which_pack() -> str:
"""The device picker: every registered platform as a tile under the
device it runs on, the ZIP advice with every folder and ZIP in one closed
table, the console picker, and the command for a setup not listed.
The tiles are the choice. Open tables under them listed every setup a
second time and made the page 11,800 px tall on a phone."""
registry = load_platform_registry(str(siteinputs.current().platforms))
record = release_record.load_advertised()
display = {key: load_platform_config(key, str(siteinputs.current().platforms)).get("platform", key)
for key in registry}
all_tabs = ("windows", "macos", "linux", "steamdeck", "android")
# The quick install box also runs on a game system: its tab shows the
# handheld recording (sitesteps).
box_tabs = (*all_tabs, "device")
box_steps, box_demos = sitesteps.install_box(box_tabs)
# Python is on most Linux and macOS machines: the package runs the same
# installer there without the bootstrap.
for tab in ("macos", "linux"):
box_demos[tab] = [*box_demos[tab],
f"With Python 3.8 or newer, `{PACKAGE_COMMAND}` does the same.", ""]
lines = [
"---",
f"terms: {', '.join(IOS_TERMS)}",
"---",
"",
"# Get the files",
"",
"Pick the setup. Its page gives the folder and the command.",
"",
"## Pick the setup { #pick-your-setup }",
"",
*setup_picker(registry, display),
"## Folders and ZIP files { #manual-download }",
"",
"- A big ZIP comes in parts, like `Pack.part1of2.zip`. Download every part.",
"- Unzip them into the BIOS folder. Put the files straight in it, "
"not in a new folder.",
"- Leave the ZIPs inside, like `neogeo.zip`, as they are.",
"- A few ZIPs hold their own top folder. Their setup's page says where "
"to unzip them.",
"",
*markup.details("note", "Every folder and ZIP in one table",
_folder_tables(registry, record, display)),
]
pending = any(has_release_pack(key) and not (pack and pack.get("assets"))
for key, pack in ((key, release_record.pack_for(key, record)) for key in registry))
if record.get("tag") and pending:
lines += ["Setups added after the last release have no ZIP until the next one.", ""]
lines += ["No ZIP on a row: the command serves that setup. ZIPs are made for the "
f"setups most people download. [Why?]({NO_ZIP_FAQ})", ""]
lines += [
f"The ZIPs come from the [latest release]({RELEASE_URL}). The command may "
"install newer files.",
"",
"## Only some consoles?",
"",
"Pick them here, and get the files and the command. Or use the command's "
f"**{_installer().TUI_SYSTEMS_ROW}**.",
"",
"<FilePicker />",
"",
*ios_section(),
"## Not in the list? One command finds it { #quick-install }",
"",
"A **terminal** is a window for typing commands.",
"",
*terminal_tabs(box_tabs, {}, under_steps=box_steps, under_command=box_demos),
"On Batocera, Recalbox and other game systems, run it on the device. "
"The setup's page shows how.",
"",
*first_screen_words(),
"",
*trust_box(""),
"**Check the folder later.** Add `--check`. It changes nothing.",
"",
*terminal_tabs(all_tabs, dict.fromkeys(TERMINALS, "--check"), steps=False),
*markup.details("note", "Fill an SD card from a computer", [
"Name the setup and the BIOS folder on the card. For RetroArch on a "
"Nintendo Switch:",
"",
"Linux, macOS:",
"",
*fence("sh", install_command(
"sh", "--platform retroarch --dest /path/to/sdcard/retroarch/cores/system")),
"",
"Windows (PowerShell, E: being the card):",
"",
*fence("powershell", install_command(
"powershell", "--platform retroarch --dest E:\\retroarch\\cores\\system")),
]),
*markup.details("note", "Copy the BIOS files from an old card", [
"Plug the old card in and add `--from` with its folder. The BIOS files "
"found there are copied, and the rest downloaded. The old card is only read.",
"",
"Linux, macOS:",
"",
*fence("sh", install_command("sh", "--from /media/me/OLDCARD")),
"",
"Windows (PowerShell, E: being the old card):",
"",
*fence("powershell", install_command("powershell", "--from E:\\")),
]),
"Details: [All installer options](wiki/installer.md).",
"",
*_next_block([
"[First install, step by step](wiki/first-install.md)",
"[When a game does not start](wiki/troubleshooting.md)",
]),
]
return "\n".join(lines) + "\n"
+43 -38
View File
@@ -1001,13 +1001,13 @@ class FaqRegressions(unittest.TestCase):
# Typed by hand, the table and the prose under it kept MAME 0.160
# and FinalBurn Neo 1.0.0.2, versions no source at the pins states,
# and the test holding them to the profiles kept the errors in step.
import generate_site
from sitegen import emulatorcards
from model.profiles import load_emulator_profiles
profiles = load_emulator_profiles(str(ROOT / "emulators"), skip_aliases=False)
page = (ROOT / "wiki" / "technical-faq.md").read_text(encoding="utf-8")
self.assertEqual(
page, generate_site.with_romset_table(page, profiles),
page, emulatorcards.with_romset_table(page, profiles),
"wiki/technical-faq.md romset table is stale: run scripts/generate_site.py",
)
prose = page.split("### How this is known", 1)[1].split("\n## ", 1)[0]
@@ -4461,7 +4461,7 @@ class TheSiteCountsSlotsNotVersions(unittest.TestCase):
59 files, 46 missing, where verify --emulator said 23 slots, 12 missing."""
def test_one_held_version_fills_the_slot(self):
from scripts.generate_site import _emulator_file_summary, _emulator_held_line
from scripts.sitegen.emulatorpage import _emulator_file_summary, _emulator_held_line
files = [
{"name": "DUKE3D.GRP", "crc32": "1"},
@@ -4866,7 +4866,7 @@ class AFileCardSaysAllItKnows(unittest.TestCase):
showed standalone_path, and gave no file an anchor to link to."""
def test_members_standalone_path_and_anchor(self):
from scripts.generate_site import _render_emulator_file
from scripts.sitegen.emulatorcards import _render_emulator_file
entry = {
"name": "neogeo.zip", "path": "neogeo.zip", "category": "bios_zip",
@@ -4891,7 +4891,7 @@ class EmulatorPagesStateTheirDataForMachines(unittest.TestCase):
"""Every emulator page's JSON-LD differed only by name and url."""
def test_source_pin_date_and_files(self):
from scripts.generate_site import emulator_structured_data
from scripts.sitegen.structured import emulator_structured_data
data = emulator_structured_data({
"emulator": "DuckStation", "source": "https://github.com/stenzek/duckstation",
@@ -4912,7 +4912,7 @@ class EmulatorPagesStateTheirDataForMachines(unittest.TestCase):
"""xemu's libretro build lives in another repository. Each source
repository states the release of its build, a version holding a
commit id states none, and a port's upstream is another code base."""
from scripts.generate_site import emulator_structured_data
from scripts.sitegen.structured import emulator_structured_data
data = emulator_structured_data({
"emulator": "MesenCE",
@@ -5380,9 +5380,9 @@ class BundledFilesAreNotToSource(unittest.TestCase):
self.assertNotIn("n64.psh", summary)
def test_the_site_gives_it_its_own_status(self):
import generate_site
from sitegen import dataexports
rows = generate_site._gap_export_rows({}, {"daedalusx64": {
rows = dataexports._gap_export_rows({}, {"daedalusx64": {
"emulator": "DaedalusX64", "systems": ["nintendo-64"],
"gap_details": [{"name": "n64.psh", "source": "missing", "required": True,
"in_repo": False, "bundled": True}],
@@ -5472,7 +5472,7 @@ class AdlerValuesReadLikeTheDownloads(unittest.TestCase):
byte-swapped ROM, so the raw ea3734fe in files.csv matched neither."""
def test_values_and_the_swap_are_stated(self):
from scripts.generate_site import _render_emulator_file
from scripts.sitegen.emulatorcards import _render_emulator_file
entry = {"name": "dsp_rom.bin", "path": "dsp_rom.bin",
"known_hash_adler32": ["0x66f334fe", "0xE789B5A5"],
@@ -5492,7 +5492,7 @@ class GapsPageCountsOneWay(unittest.TestCase):
of the same platform already holds."""
def test_settled_declarations_are_listed_apart(self):
from scripts.generate_site import _render_problem_files
from scripts.sitegen.gaps import _render_problem_files
problems = [{"platform": "RetroDECK", "name": "dsifirmware.bin", "status": "untested",
"required": True, "reason": "x", "discrepancy": ""}]
@@ -5506,7 +5506,7 @@ class GapsPageCountsOneWay(unittest.TestCase):
def test_missing_says_the_destination_count_of_the_opening_sentence(self):
# The page opened on "48 are missing" (by destination) above a
# heading that said "10 files": one row per name.
from scripts.generate_site import _render_problem_files
from scripts.sitegen.gaps import _render_problem_files
problems = [{"platform": "AmberELEC", "name": "hardwareconfig.xml",
"status": "missing", "required": True, "reason": "",
@@ -5519,7 +5519,7 @@ class GapsPageCountsOneWay(unittest.TestCase):
def test_a_missing_row_links_each_entry_and_names_its_folder(self):
"""The row said `N88_KNJ1.ROM | unread | yes | AmberELEC` in plain text:
neither where the list puts it nor which cores were examined."""
from scripts.generate_site import _render_problem_files
from scripts.sitegen.gaps import _render_problem_files
problems = [{"platform": "AmberELEC", "platform_key": "amberelec", "name": "N88_KNJ1.ROM",
"status": "missing", "required": True, "reason": "", "discrepancy": "",
@@ -5530,7 +5530,7 @@ class GapsPageCountsOneWay(unittest.TestCase):
"`bios/quasi88/N88_KNJ1.ROM` |", text)
def test_the_destination_is_the_list_entrys(self):
from scripts.generate_site import _declared_destination
from scripts.sitegen.gaps import _declared_destination
from model.platforms import load_platform_config
config = load_platform_config("amberelec", str(ROOT / "platforms"))
@@ -5552,7 +5552,7 @@ class UnsourceableCardSaysWhy(unittest.TestCase):
and nothing else. The reason was only on the gaps page."""
def test_reason_and_link(self):
from scripts.generate_site import _render_emulator_file
from scripts.sitegen.emulatorcards import _render_emulator_file
entry = {"name": "nds_firmware_modified.bin", "path": "x.bin",
"unsourceable": "written by the firmware editor, so no dump of it exists"}
@@ -5567,7 +5567,7 @@ class UnsourceableCardSaysWhy(unittest.TestCase):
"""The section read "Acknowledged gaps ... (verified from source
code)" while No-Intro lists XM7's KANJI2.ROM and MAME's fm7740sx.zip
carries it: the flag only keeps a homonym out, the file is wanted."""
from scripts.generate_site import generate_gap_analysis
from scripts.sitegen.gaps import generate_gap_analysis
unsourced = {"name": "KANJI2.ROM", "reason": "no dump distributed", "source_ref": ""}
report = {"xm7": {"emulator": "XM7", "gaps": 0, "gap_missing": 0, "gap_bios": 0,
@@ -5593,15 +5593,15 @@ class CollectionCardsSayWhereToGetTheFile(unittest.TestCase):
scph5501.bin and no path or link to the bytes."""
def test_raw_and_release_asset_urls(self):
import scripts.generate_site as site
from scripts.sitegen import cards
site._RELEASE_ASSET_NAMES = None
self.addCleanup(setattr, site, "_RELEASE_ASSET_NAMES", None)
cards._RELEASE_ASSET_NAMES = None
self.addCleanup(setattr, cards, "_RELEASE_ASSET_NAMES", None)
self.assertEqual(
site._fetch_url("bios/Sony/PlayStation/scph5501.bin"),
cards._fetch_url("bios/Sony/PlayStation/scph5501.bin"),
"https://raw.githubusercontent.com/Abdess/retrobios/main/bios/Sony/PlayStation/scph5501.bin",
)
self.assertTrue(site._fetch_url("bios/Arcade/MAME/MAME 0.174 Arcade XML.dat").endswith(
self.assertTrue(cards._fetch_url("bios/Arcade/MAME/MAME 0.174 Arcade XML.dat").endswith(
"/releases/download/large-files/MAME.0.174.Arcade.XML.dat"
))
@@ -5613,7 +5613,8 @@ class CollectionCardsCarryFullHashes(unittest.TestCase):
CRC32 or SHA256."""
def test_every_hash_in_full(self):
from scripts.generate_site import FileConsumers, _system_file_card
from scripts.generate_site import FileConsumers
from scripts.sitegen.cards import _system_file_card
entry = {"name": "DUKE.RTS", "path": "bios/x/DUKE.RTS", "size": 10,
"sha1": "a" * 40, "md5": "9d29f9673bbdb56068acf7645c13749c",
@@ -5629,7 +5630,7 @@ class AHeldRevisionLinksItsBuildFile(unittest.TestCase):
and the path a pinned link needs. 36 profiles carry one."""
def test_the_build_file_row(self):
from scripts.generate_site import _build_rows
from scripts.sitegen.emulatorcards import _build_rows
rows = _build_rows({"pin_frozen": "KNULLI builds this revision.", "pin_build": [{
"platform": "knulli", "repo": "https://github.com/knulli-cfw/knulli-linux",
@@ -5641,7 +5642,7 @@ class AHeldRevisionLinksItsBuildFile(unittest.TestCase):
"at `20260511` sets `ADVANCED_DRASTIC_VERSION` |", rows)
def test_a_build_read_at_a_recorded_commit_links(self):
from scripts.generate_site import _build_rows
from scripts.sitegen.emulatorcards import _build_rows
pin = "46128cd252cdecae852a4d0bafa2aaf9d03ab563"
rows = _build_rows({"pin_build": [{
@@ -5666,7 +5667,8 @@ class AVariantCardSaysWhatToSaveItAs(unittest.TestCase):
the storage name, and nothing said RetroBat looks for advision.zip."""
def test_the_name_to_save_it_under(self):
from scripts.generate_site import FileConsumers, _system_file_card
from scripts.generate_site import FileConsumers
from scripts.sitegen.cards import _system_file_card
entry = {"name": "advision.zip", "size": 10, "sha1": "a" * 40,
"path": "bios/Entex/Adventure Vision/.variants/advision.zip.1c086064"}
@@ -5684,7 +5686,8 @@ class NullReadsAsNone(unittest.TestCase):
printed `bios_filename: None`: a stated "there is none" read as a gap."""
def test_page_and_values(self):
from scripts.generate_site import _plain_value, generate_emulator_page
from scripts.sitegen.fields import _plain_value
from scripts.sitegen.emulatorpage import generate_emulator_page
self.assertEqual(_plain_value(None), "none")
page = generate_emulator_page(
@@ -5713,7 +5716,7 @@ class EmulatorCardsLinkTheCopyAndTheSection(unittest.TestCase):
def test_copy_and_sections(self):
from types import SimpleNamespace
from scripts.generate_site import _render_emulator_file
from scripts.sitegen.emulatorcards import _render_emulator_file
sha1 = "ef9194ab4804aa0aa8540d846caf291b28331165"
consumers = SimpleNamespace(
@@ -5738,7 +5741,7 @@ class VersionAnchorsFollowContent(unittest.TestCase):
@staticmethod
def _anchors(files):
from scripts.generate_site import generate_emulator_page
from scripts.sitegen.emulatorpage import generate_emulator_page
page = generate_emulator_page(
"raze", {"emulator": "Raze", "type": "standalone", "files": files},
@@ -5769,18 +5772,19 @@ class SitemapDatesComeFromThePage(unittest.TestCase):
def test_the_page_date_or_none_reaches_the_sitemap(self):
import tempfile
from scripts import generate_site
from scripts.sitegen import decorate
from scripts.sitegen import descriptions as sitegen_descriptions
saved = dict(generate_site.PAGE_DATA)
self.addCleanup(lambda: (generate_site.PAGE_DATA.clear(),
generate_site.PAGE_DATA.update(saved)))
saved = dict(sitegen_descriptions.PAGE_DATA)
self.addCleanup(lambda: (sitegen_descriptions.PAGE_DATA.clear(),
sitegen_descriptions.PAGE_DATA.update(saved)))
with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp:
docs = Path(tmp)
(docs / "emulators").mkdir()
(docs / "emulators" / "dated.md").write_text("# Dated\n\nA page with its own date.\n")
(docs / "emulators" / "undated.md").write_text("# Undated\n\nA page with no date.\n")
generate_site.PAGE_DATA["emulators/dated.md"] = {"dateModified": "2026-10-04"}
lastmod = generate_site.decorate_markdown_pages(docs)
sitegen_descriptions.PAGE_DATA["emulators/dated.md"] = {"dateModified": "2026-10-04"}
lastmod = decorate.decorate_markdown_pages(docs)
self.assertEqual(lastmod, {"/retrobios/emulators/dated/": "2026-10-04"})
# The sitemap reads that map, and leaves every other page undated.
config = (ROOT / "website" / "astro.config.mjs").read_text(encoding="utf-8")
@@ -5807,7 +5811,7 @@ class TheDatasetDescribesItsDownloads(unittest.TestCase):
licence, date or creator: nothing a dataset harvester could index."""
def test_distribution_licence_and_date(self):
from scripts.generate_site import dataset_structured_data
from scripts.sitegen.structured import dataset_structured_data
exports = [{"title": "Content database", "url": "api/v1/database.json",
"media_type": "application/json", "bytes": 10, "sha256": "ab" * 32}]
@@ -5827,7 +5831,7 @@ class SystemPagesDescribeTheirFiles(unittest.TestCase):
provenance for the pages that carry a card per file."""
def test_parts_carry_hashes_anchor_and_provenance(self):
from scripts.generate_site import system_structured_data
from scripts.sitegen.structured import system_structured_data
entry = {"name": "scph5501.bin", "sha1": "0555c6fae8906f3f09baf5988f00e55f88e9f30b",
"md5": "490f666e1afb15b7362b406ed1cea246", "crc32": "8d8cb7e4", "size": 524288,
@@ -5839,7 +5843,7 @@ class SystemPagesDescribeTheirFiles(unittest.TestCase):
self.assertIn("redump: Sony - PlayStation - BIOS Images (ps-30a.bin)", part["citation"])
def test_a_huge_page_lists_its_verified_files_and_points_at_the_table(self):
from scripts.generate_site import SYSTEM_PARTS_IN_FULL, system_structured_data
from scripts.sitegen.structured import SYSTEM_PARTS_IN_FULL, system_structured_data
plain = [{"name": f"f{i}", "sha1": f"{i:040x}"} for i in range(SYSTEM_PARTS_IN_FULL)]
cited = {"name": "v", "sha1": "f" * 40,
@@ -5858,7 +5862,7 @@ class TheCollectionShipsADat(unittest.TestCase):
def test_round_trip_through_the_logiqx_parser(self):
sys.path.insert(0, str(ROOT / "scripts" / "scraper"))
from logiqx_parser import parse_logiqx
from scripts.generate_site import collection_dat
from scripts.sitegen.structured import collection_dat
db = {"files": {
"a" * 40: {"path": "bios/Sony/PlayStation/scph5501.bin", "size": 4,
@@ -5881,7 +5885,8 @@ class TheCollectionShipsADat(unittest.TestCase):
Batocera reads."""
sys.path.insert(0, str(ROOT / "scripts" / "scraper"))
from logiqx_parser import parse_logiqx
from scripts.generate_site import _platform_data_links, platform_dat
from scripts.sitegen.platformfiles import _platform_data_links
from scripts.sitegen.structured import platform_dat
db = {"files": {"a" * 40: {"size": 4, "crc32": "8D8CB7E4", "md5": "1" * 32,
"sha1": "a" * 40}}}
+2 -2
View File
@@ -15,7 +15,7 @@ from unittest import mock
import generate_readme
from sitegen import readme
import generate_site
from sitegen import reference
REPO_ROOT = Path(__file__).resolve().parent.parent
@@ -32,7 +32,7 @@ class OneContributingText(unittest.TestCase):
def test_repository_and_site_pages_match(self):
self.assertEqual(
_normalized(readme.generate_contributing()),
_normalized(generate_site.generate_contributing()),
_normalized(reference.generate_contributing()),
)
+9 -9
View File
@@ -72,10 +72,10 @@ def _section(text: str, heading: str) -> str:
def _which_pack() -> str:
import generate_site
from sitegen import whichpack
with contextlib.chdir(REPO_ROOT):
return generate_site.generate_which_pack()
return whichpack.generate_which_pack()
class TheDownloadTablesFollowTheRegistry(unittest.TestCase):
@@ -215,7 +215,7 @@ class DownloadLinksKeepTheirAddress(unittest.TestCase):
row for them offers the command."""
from model.registry import list_registered_platforms
from model.platforms import load_platform_config
import generate_site
from sitegen import install
record = release_record.load_advertised()
page = _which_pack()
@@ -224,7 +224,7 @@ class DownloadLinksKeepTheirAddress(unittest.TestCase):
continue
label = load_platform_config(key, "platforms").get("platform", key)
row = next(line for line in page.splitlines() if line.startswith(f"| [{label}]("))
state = "No ZIP yet." if generate_site.has_release_pack(key) else "No ZIP."
state = "No ZIP yet." if install.has_release_pack(key) else "No ZIP."
with self.subTest(platform=key):
self.assertNotIn("/releases/", row)
self.assertIn(f"{state} [Use the command](platforms/{key}.md#install).", row)
@@ -431,9 +431,9 @@ class PagesOpenOnTheirContent(unittest.TestCase):
before saying anything about a pack."""
def test_no_paragraph_announces_its_page(self):
import generate_site
from sitegen import whichpack
text = generate_site.generate_which_pack()
text = whichpack.generate_which_pack()
announcing = [
line for line in text.splitlines()
if re.match(r"(This|The) (page|section) ", line)
@@ -672,12 +672,12 @@ class ArchiveRecipesAreCountedFromTheRecipes(unittest.TestCase):
self.assertIn(f"({SITE_URL}wiki/archive-recipes/)", line)
def test_the_page_counts(self) -> None:
import generate_site
from sitegen import emulatorcards
page = _read("wiki/archive-recipes.md")
self.assertEqual(generate_site.with_archive_counts(page, self.counts), page,
self.assertEqual(emulatorcards.with_archive_counts(page, self.counts), page,
"wiki/archive-recipes.md counts are stale: run scripts/generate_site.py")
for line in generate_site.archive_recipe_lines(self.counts):
for line in emulatorcards.archive_recipe_lines(self.counts):
self.assertIn(line, page)
def test_the_page_command_is_the_tools(self) -> None:
+1 -1
View File
@@ -16,7 +16,7 @@ import unittest
from pathlib import Path
from packs.crossref import FileConsumers, entry_target
from generate_site import generate_system_page
from sitegen.systempages import generate_system_page
REPO_ROOT = Path(__file__).resolve().parent.parent
+2 -2
View File
@@ -14694,9 +14694,9 @@ class ProvenCardsAndCounts(unittest.TestCase):
def test_which_pack_names_the_first_screen(self):
"""Which-pack said the command opens a screen
where Install and Choose systems are, the second screen."""
import generate_site
from sitegen import guidepage
words = " ".join(generate_site.first_screen_words())
words = " ".join(guidepage.first_screen_words())
found, nothing = fresh_state(), install.TuiState(os_type="linux", home=HOME)
found.stack = ["setup"]
self.assertIn(install.tui_view(found, 80, 24)[0].split(": ", 1)[1].strip(), words)
+2 -2
View File
@@ -422,7 +422,7 @@ class TheSitePageOfACardPlatform(unittest.TestCase):
the frontend hands its cores and the files the pack puts in each."""
def test_folders_replace_the_empty_coverage(self):
import generate_site
from sitegen import platformpage
from model.database import load_database
from model.registry import load_platform_registry
from sitegen.readme import compute_coverage
@@ -432,7 +432,7 @@ class TheSitePageOfACardPlatform(unittest.TestCase):
registry = load_platform_registry(str(REPO_ROOT / "platforms"))
db = load_database(str(REPO_ROOT / "database.json"))
cov = compute_coverage("minui", str(REPO_ROOT / "platforms"), db)
page = generate_site.generate_platform_page("minui", cov, registry, {})
page = platformpage.generate_platform_page("minui", cov, registry, {})
self.assertNotIn("0/0", page)
self.assertNotIn("## Systems overview", page)
self.assertIn("| `Bios/PS/` | [pcsx_rearmed](../emulators/pcsx_rearmed.md) |", page)
+3 -3
View File
@@ -37,7 +37,7 @@ from packs import datatrees
from packs import manifest as packs_manifest
from packs import platformpack
from sitegen import readme as sitegen_readme
import generate_site
from sitegen import home
import release_notes
import release_record
from packs import parts
@@ -519,9 +519,9 @@ class TheCollectionTotalNamesTheCollection(unittest.TestCase):
"files": {},
"indexes": {},
}
sentence = generate_site.composition_sentence(db)
sentence = home.composition_sentence(db)
self.assertTrue(sentence.startswith("The collection"), sentence)
self.assertEqual(generate_site.COLLECTION_FILES_LABEL, "Files collected")
self.assertEqual(home.COLLECTION_FILES_LABEL, "Files collected")
class RefusedFilesAreNotPresent(unittest.TestCase):
+1 -1
View File
@@ -456,7 +456,7 @@ class GeneratedSiteProse(unittest.TestCase):
"""The site pages carry strings no tracked file shows verbatim."""
def test_generated_pages(self):
from generate_site import LOCAL_NOTE_DIRS
from sitegen.decorate import LOCAL_NOTE_DIRS
from tests import sitepages
+3 -3
View File
@@ -16,7 +16,7 @@ from scripts.model.dumpcatalog import (
load_provenance_snapshots,
write_provenance_snapshot,
)
from scripts.generate_site import generate_provenance_page
from scripts.sitegen.provenance import generate_provenance_page
from scripts.provenance_report import build_report
from scripts.scraper.dat_pack_importer import _bios_entries, import_pack
from scripts.scraper.logiqx_parser import parse_logiqx, validate_logiqx_format
@@ -669,7 +669,7 @@ class TheWantedPageAsksOnlyForWhatCannotBeMade(unittest.TestCase):
already produces (a Kickstart's odd bytes, a character ROM's halves)."""
def test_a_derivable_dump_moves_out_of_the_wanted_list(self):
from scripts import generate_site
from scripts.sitegen import provenance as sitegen_provenance
report = {"tosec": {
"imported_at": "2026-01-01", "dats": {}, "total": 2, "matched": 0,
@@ -681,7 +681,7 @@ class TheWantedPageAsksOnlyForWhatCannotBeMade(unittest.TestCase):
}}
derivable = {"a" * 40: {"from": ["bios/Commodore/Amiga/a1200.rom"],
"transform": "byte swap"}}
page = generate_site.generate_provenance_page({"files": {}}, report, derivable)
page = sitegen_provenance.generate_provenance_page({"files": {}}, report, derivable)
wanted, _, derived = page.partition("## Derivable")
self.assertIn("**1** dumps a catalog", wanted)
self.assertNotIn("kick31.rom", wanted)
+11 -9
View File
@@ -53,10 +53,10 @@ def _write_registry(root: Path, platforms: dict) -> str:
def _which_pack() -> str:
import generate_site
from sitegen import whichpack
with contextlib.chdir(REPO_ROOT):
return generate_site.generate_which_pack()
return whichpack.generate_which_pack()
class TheFieldIsTheList(unittest.TestCase):
@@ -255,15 +255,16 @@ class TheTablesFollowTheField(unittest.TestCase):
class EverySurfaceSaysWhy(unittest.TestCase):
def test_a_setup_page_says_no_zip_with_the_command_beside_it(self):
import generate_site
from sitegen import guidepage
line = generate_site.no_zip_line("KNULLI")
line = guidepage.no_zip_line("KNULLI")
self.assertEqual(line, "No ZIP for KNULLI. The command installs every file and checks it.")
with contextlib.chdir(REPO_ROOT):
block = generate_site._pack_buttons("knulli")
guide = generate_site._guide_download(
block = guidepage._pack_buttons("knulli")
guide = guidepage._guide_download(
"knulli", "KNULLI", generate_site.GUIDES["knulli"], None, "## Download")
self.assertIn(line, block)
self.assertIn(generate_site.NO_ZIP_FAQ, block)
self.assertIn(guidepage.NO_ZIP_FAQ, block)
self.assertIn(line, "\n".join(guide))
self.assertNotIn("yet", block)
@@ -471,12 +472,12 @@ class TheReleaseNotesThankPeople(unittest.TestCase):
class EveryPlatformHasAPermanentPage(unittest.TestCase):
def test_a_page_for_every_registered_platform(self):
import generate_site
from sitegen import getpages
record = release_record.load_advertised()
with contextlib.chdir(REPO_ROOT):
for name in list_registered_platforms(PLATFORMS):
page = generate_site.generate_get_page(name)
page = getpages.generate_get_page(name)
pack = release_record.pack_for(name, record)
with self.subTest(platform=name):
self.assertRegex(page, r"\n# (.+ )?BIOS (pack|files)( for .+)?\n")
@@ -491,8 +492,9 @@ class EveryPlatformHasAPermanentPage(unittest.TestCase):
def test_the_generator_writes_and_sweeps_them(self):
import generate_site
from sitegen import config
self.assertIn(release_record.GET_DIR, generate_site.GENERATED_DIRS)
self.assertIn(release_record.GET_DIR, config.GENERATED_DIRS)
source = Path(generate_site.__file__).read_text(encoding="utf-8")
self.assertIn('write_if_changed(str(get_dir / f"{name}.md"), generate_get_page(name))',
source)
+2 -2
View File
@@ -68,7 +68,7 @@ class WhatLeftIsRecorded(unittest.TestCase):
class TheLookupAnswersForIt(unittest.TestCase):
def test_records_lead_to_the_card_in_its_place(self):
import generate_site
from sitegen import lookup
retired = {OLD: {"name": "a2diskiing.zip", "path": "bios/Arcade/Arcade/a2diskiing.zip",
"crc32": "292ef826", "left": "2026-10-22", "successor": "ee" * 20},
@@ -76,7 +76,7 @@ class TheLookupAnswersForIt(unittest.TestCase):
"left": "2026-10-23", "successor": NEW}}
files = {NEW: {"name": "a2diskiing.zip"}}
locations = [{"sha1": NEW, "url": "/retrobios/systems/apple/#sha1-d9d9d9d9d9d9"}]
records = generate_site.retired_records(retired, files, locations)
records = lookup.retired_records(retired, files, locations)
found = {(r["sha1"], r["algorithm"]): r for r in records}
# Followed to the file held today, through the copy that left after.
self.assertEqual(found[(OLD, "sha1")]["url"], locations[0]["url"])
+5 -4
View File
@@ -16,7 +16,8 @@ from pathlib import Path
import yaml
from model.database import load_database
from generate_site import _availability_check, _file_badges
from sitegen.emulatorpage import _availability_check
from sitegen.emulatorcards import _file_badges
REPO_ROOT = Path(__file__).resolve().parent.parent
@@ -74,7 +75,7 @@ class AHeldEntrySaysWhere(unittest.TestCase):
import tempfile
import zipfile
import generate_site
from sitegen import emulatorcards
from packs.crossref import FileConsumers, held_copy
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp:
@@ -98,12 +99,12 @@ class AHeldEntrySaysWhere(unittest.TestCase):
consumers = FileConsumers({"files": {"z" * 40: {
"path": "bios/Arcade/MAME/spectrum_opus.zip"}}}, data_dir_registry={})
line = generate_site._held_copy_line(
line = emulatorcards._held_copy_line(
("bios/Arcade/MAME/spectrum_opus.zip", "specmate.rom"), consumers)
self.assertEqual(line, "Collection copy: member `specmate.rom` of "
"[`bios/Arcade/MAME/spectrum_opus.zip`]"
"(../systems/arcade.md#sha1-zzzzzzzzzzzz)")
line = generate_site._held_copy_line(("data/dolphin-sys/GC/font_western.bin", ""),
line = emulatorcards._held_copy_line(("data/dolphin-sys/GC/font_western.bin", ""),
consumers)
self.assertEqual(line, "Collection copy: `GC/font_western.bin` in the "
"`dolphin-sys` data directory")
+3 -3
View File
@@ -258,13 +258,13 @@ class GeneratedSurfaces(unittest.TestCase):
"""The install boxes weigh in the split of a manufacturer's page,
fitted on the 66-character raw address: weighed at their new length,
Nintendo DS fell back onto the Nintendo summary and lost its page."""
import generate_site
from sitegen import consolecards
tail = " | sh -s -- --check"
self.assertEqual(generate_site._install_box_weight([f"curl -fsSL {INSTALL_SH}{tail}"]),
self.assertEqual(consolecards._install_box_weight([f"curl -fsSL {INSTALL_SH}{tail}"]),
len("curl -fsSL ") + 66 + len(tail) + 1)
line = f"&([scriptblock]::Create((irm {INSTALL_PS1}))) --check"
self.assertEqual(generate_site._install_box_weight([line]),
self.assertEqual(consolecards._install_box_weight([line]),
len(line) - len(INSTALL_PS1) + 67 + 1)
def test_the_readme_shows_the_short_form(self):
+6 -6
View File
@@ -272,17 +272,17 @@ class TheRules(unittest.TestCase):
def test_a_large_data_directory_is_listed_on_pages_of_its_own(self):
"""Dolphin's Sys tree put 16,900 elements on the Dolphin page. Its
files are found where they moved."""
import generate_site
from sitegen import lookup
members = {f"Sys/{i:05d}.ini": {"sha1": f"{i:040x}", "size": 1}
for i in range(generate_site.DATA_TREE_ROWS_PER_PAGE + 1)}
pages = generate_site.data_tree_pages("dolphin-sys", members)
for i in range(lookup.DATA_TREE_ROWS_PER_PAGE + 1)}
pages = lookup.data_tree_pages("dolphin-sys", members)
self.assertEqual([stem for stem, _names in pages], ["data-dolphin-sys", "data-dolphin-sys-2"])
self.assertEqual(generate_site.data_tree_pages("small", dict(list(members.items())[:3])), [])
items = generate_site.file_location_items(
self.assertEqual(lookup.data_tree_pages("small", dict(list(members.items())[:3])), [])
items = lookup.file_location_items(
{"files": {}}, {"dolphin": {"data_directories": [{"ref": "dolphin-sys"}]}},
{"dolphin-sys": members})
last = f"{generate_site.DATA_TREE_ROWS_PER_PAGE:040x}"
last = f"{lookup.DATA_TREE_ROWS_PER_PAGE:040x}"
self.assertIn({"sha1": last, "url": f"/retrobios/emulators/data-dolphin-sys-2/#sha1-{last[:12]}"}, items)
def test_no_float_rule_for_right_aligned_images(self):
+8 -7
View File
@@ -19,7 +19,8 @@ from pathlib import Path
import yaml
import generate_site
from sitegen import decorate
from sitegen import nav as sitegen_nav
from model import guides
from model.guides import GUIDES, GuideError, load_guides
@@ -150,7 +151,7 @@ def _wiki_copy(tmp: str) -> Path:
class NavFromFrontMatter(unittest.TestCase):
def _nav(self, wiki: Path) -> dict:
nav = generate_site.generate_nav({}, {}, {}, {}, wiki)
nav = sitegen_nav.generate_nav({}, {}, {}, {}, wiki)
return {next(iter(tab)): next(iter(tab.values())) for tab in nav}
def test_the_repository_nav_matches_the_pages(self):
@@ -178,7 +179,7 @@ class NavFromFrontMatter(unittest.TestCase):
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp") as tmp:
wiki = _wiki_copy(tmp)
(wiki / "orphan.md").write_text("# Orphan\n\nText.\n", encoding="utf-8")
with self.assertRaisesRegex(generate_site.NavError,
with self.assertRaisesRegex(sitegen_nav.NavError,
r"wiki/orphan\.md: front matter needs `level:`"):
self._nav(wiki)
@@ -188,7 +189,7 @@ class NavFromFrontMatter(unittest.TestCase):
(wiki / "orphan.md").write_text(
"---\nlevel: reference\n---\n\n# Orphan\n", encoding="utf-8")
with self.assertRaisesRegex(
generate_site.NavError,
sitegen_nav.NavError,
r"wiki/orphan\.md: front matter needs `order:`.*Reference tab",
):
self._nav(wiki)
@@ -198,7 +199,7 @@ class NavFromFrontMatter(unittest.TestCase):
wiki = _wiki_copy(tmp)
(wiki / "twin.md").write_text(
"---\nlevel: contribute\norder: 20\n---\n\n# Twin\n", encoding="utf-8")
with self.assertRaisesRegex(generate_site.NavError,
with self.assertRaisesRegex(sitegen_nav.NavError,
r"wiki/adding-a-platform\.md and wiki/twin\.md"):
self._nav(wiki)
@@ -212,9 +213,9 @@ class NavFromFrontMatter(unittest.TestCase):
def test_every_wiki_page_states_its_place(self):
for page in sorted(WIKI.glob("*.md")):
meta = generate_site._front_matter(page.read_text(encoding="utf-8"))
meta = decorate._front_matter(page.read_text(encoding="utf-8"))
with self.subTest(page=page.name):
self.assertIn(meta.get("level"), generate_site.TABS)
self.assertIn(meta.get("level"), sitegen_nav.TABS)
self.assertTrue(meta.get("nav") is False or isinstance(meta.get("order"), int))
+7 -6
View File
@@ -13,7 +13,8 @@ import re
import unittest
from pathlib import Path
import generate_site
from sitegen import crossref
from sitegen import platformpage
from model.registry import list_registered_platforms
from model.profiles import load_emulator_profiles
from model.platforms import load_platform_config
@@ -32,14 +33,14 @@ class SiteCoreCounts(unittest.TestCase):
config = load_platform_config(name, platforms)
coverages[name] = {"platform": config.get("platform", name), "config": config}
moved: dict[str, str] = {}
page = generate_site.generate_cross_reference(coverages, profiles, moved)
page = crossref.generate_cross_reference(coverages, profiles, moved)
shown = {
m.group(1): int(m.group(2))
for m in re.finditer(r"^\| \[([^\]]+)\]\(platforms/[^)]+\) \| (\d+)", page, re.M)
}
for name, cov in coverages.items():
with self.subTest(page=name):
if generate_site._own_list_only(cov["config"]):
if platformpage._own_list_only(cov["config"]):
# cores: [] (MiSTer, BizHawk): no core table, the overview
# row points at the platform's own list instead.
self.assertNotIn(f"cross-reference-{name}", moved)
@@ -66,17 +67,17 @@ class AllLibretroLabel(unittest.TestCase):
}
def test_a_list_naming_retroarch_is_labelled(self):
note = generate_site._core_scope_note(
note = crossref._core_scope_note(
{"cores": ["retroarch", "sa"]}, self.PROFILES)
self.assertEqual(note, " (all libretro, plus 1 other core)")
def test_the_string_form_is_labelled(self):
note = generate_site._core_scope_note({"cores": "all_libretro"}, self.PROFILES)
note = crossref._core_scope_note({"cores": "all_libretro"}, self.PROFILES)
self.assertEqual(note, " (all libretro)")
def test_a_selection_is_not(self):
self.assertEqual(
generate_site._core_scope_note({"cores": ["a", "sa"]}, self.PROFILES), "")
crossref._core_scope_note({"cores": ["a", "sa"]}, self.PROFILES), "")
if __name__ == "__main__":
+9 -8
View File
@@ -193,8 +193,9 @@ def _tab_bodies(markdown: str) -> dict[str, str]:
class TheTwoPagesShowIt(unittest.TestCase):
def test_home_shows_the_terminal_recording(self):
import generate_site
from sitegen import home
tag = generate_site.install_demo()[0]
tag = home.install_demo()[0]
self.assertIn(f'description="{sitegen_readme.demo_description()}"', tag)
source = Path(generate_site.__file__).read_text(encoding="utf-8")
body = source[source.index("def generate_home("):]
@@ -202,9 +203,9 @@ class TheTwoPagesShowIt(unittest.TestCase):
self.assertIn("*install_demo(),", body)
def test_each_tab_of_get_your_files_shows_its_variant(self):
import generate_site
from sitegen import whichpack
tabs = _tab_bodies(generate_site.generate_which_pack())
tabs = _tab_bodies(whichpack.generate_which_pack())
expected = {"Windows": None, "macOS": "default", "Linux": "default",
"Steam Deck": "default", "Android (Termux)": "default",
"On the device": "handheld"}
@@ -220,15 +221,15 @@ class TheTwoPagesShowIt(unittest.TestCase):
self.assertIn(f'width="{_facts(variant)["width"]}"', demos[0])
self.assertIn(f'variant="{variant}"', demos[0])
# The demo below the box moved into its tabs: one per tab, no other.
page = generate_site.generate_which_pack()
page = whichpack.generate_which_pack()
self.assertEqual(page.count("<InstallDemo "), len(expected) - 1)
def test_the_site_serves_the_videos_not_the_gif(self):
import generate_site
from sitegen import guidepage
expected = tuple(name for variant in make_demo.VARIANTS.values()
for name in variant.outputs if not name.endswith(".gif"))
self.assertEqual(sorted(generate_site.DEMO_ASSETS), sorted(expected))
self.assertEqual(sorted(guidepage.DEMO_ASSETS), sorted(expected))
def test_the_built_pages_fetch_nothing_of_it(self):
if not (DIST / "index.html").is_file():
@@ -259,9 +260,9 @@ class TheTwoPagesShowIt(unittest.TestCase):
def generate_site_assets() -> tuple[str, ...]:
import generate_site
from sitegen import guidepage
return generate_site.DEMO_ASSETS
return guidepage.DEMO_ASSETS
if __name__ == "__main__":
+14 -12
View File
@@ -18,7 +18,9 @@ import unittest
from html.parser import HTMLParser
from pathlib import Path
import generate_site as gs
from sitegen import cards
from sitegen import emulatorcards
from sitegen import install
from sitegen import markup
REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -103,7 +105,7 @@ def _card() -> dict:
class ASystemCardShowsTheAnswerFirst(unittest.TestCase):
def setUp(self) -> None:
self.lines = gs._system_file_card(_card(), _card_consumers(SHA1))
self.lines = cards._system_file_card(_card(), _card_consumers(SHA1))
self.text = "\n".join(self.lines)
self.fold = self.text[self.text.index("<details"):self.text.index("</details>")]
self.shown = self.text.replace(self.fold, "")
@@ -132,7 +134,7 @@ class ASystemCardShowsTheAnswerFirst(unittest.TestCase):
# The yardstick list a page is cut by holds every fact: the
# Starlight card holds each of its values.
with markup.using("mkdocs"):
yardstick = "\n".join(gs._system_file_card(_card(), _card_consumers(SHA1)))
yardstick = "\n".join(cards._system_file_card(_card(), _card_consumers(SHA1)))
for label, values in re.findall(r"(?m)^- ([^:]+): (.*)$", yardstick):
self.assertIn(f"<dt>{label}</dt>", self.text)
for value in re.findall(r"[0-9a-f]{8,64}|`[^`]+`", values):
@@ -150,7 +152,7 @@ class AnEmulatorCardFoldsItsHashes(unittest.TestCase):
"required": True, "note": "Read at boot.", "priority": 5,
"validation": ["md5"], "source_ref": "src/core/bios.cpp:47"}
profile = {"emulator": "DuckStation", "files": [entry], "systems": ["sony-playstation"]}
self.text = "\n".join(gs._render_emulator_file(
self.text = "\n".join(emulatorcards._render_emulator_file(
entry, profile, None, profile["files"], lambda _f: True, anchor="file-scph5501-bin"))
self.fold = self.text[self.text.index("<details"):self.text.index("</details>")]
self.shown = self.text.replace(self.fold, "")
@@ -174,7 +176,7 @@ class AnEmulatorCardFoldsItsHashes(unittest.TestCase):
def test_the_markdown_yardstick_is_unchanged(self) -> None:
with markup.using("mkdocs"):
entry = {"name": "a.bin", "md5": "b" * 32, "size": 4}
text = "\n".join(gs._render_emulator_file(
text = "\n".join(emulatorcards._render_emulator_file(
entry, {"files": [entry]}, None, [entry], lambda _f: True))
self.assertNotIn("<details", text)
self.assertIn("- MD5: ", text)
@@ -185,7 +187,7 @@ PAIRS = [("emudeck", "sony-psp"), ("retroarch", "sony-psp"), ("retrobat", "Neo G
class AnInstallBoxShowsOneCommand(unittest.TestCase):
def setUp(self) -> None:
self.text = "\n".join(gs._console_install_block("PlayStation Portable", PAIRS))
self.text = "\n".join(install._console_install_block("PlayStation Portable", PAIRS))
def test_one_command_per_tab_for_the_setup_picked(self) -> None:
tabs = self.text[self.text.index("<Tabs"):self.text.index("</Tabs>")]
@@ -198,10 +200,10 @@ class AnInstallBoxShowsOneCommand(unittest.TestCase):
def test_the_default_setup(self) -> None:
"""AmberELEC led 17 system pages, a handheld system under the
Windows tab, for being first in alphabetical order."""
self.assertEqual(gs._default_setup([("amberelec", "psx"), ("retroarch", "Sony - PlayStation")]),
self.assertEqual(install._default_setup([("amberelec", "psx"), ("retroarch", "Sony - PlayStation")]),
("retroarch", "Sony - PlayStation"))
self.assertEqual(gs._default_setup([("amberelec", "x"), ("batocera", "x")]), ("batocera", "x"))
self.assertEqual(gs._default_setup([("amberelec", "x"), ("knulli", "x")]), ("amberelec", "x"))
self.assertEqual(install._default_setup([("amberelec", "x"), ("batocera", "x")]), ("batocera", "x"))
self.assertEqual(install._default_setup([("amberelec", "x"), ("knulli", "x")]), ("amberelec", "x"))
select = re.search(r"<select>(.*?)</select>", self.text).group(1)
self.assertEqual(re.findall(r'<option value="([^"]+)" selected', select), ["retroarch"])
@@ -224,7 +226,7 @@ class AnInstallBoxShowsOneCommand(unittest.TestCase):
self.assertIn("https://<wbr>abdess.github.io", listed)
def test_one_setup_keeps_its_two_blocks(self) -> None:
text = "\n".join(gs._console_install_block("PlayStation Portable", PAIRS[:1]))
text = "\n".join(install._console_install_block("PlayStation Portable", PAIRS[:1]))
self.assertNotIn("<select", text)
self.assertIn('```sh title="Terminal"', text)
self.assertIn('```powershell title="PowerShell"', text)
@@ -233,7 +235,7 @@ class AnInstallBoxShowsOneCommand(unittest.TestCase):
# The budgets that cut a system page are measured on this Markdown:
# a box that changed it would move cards to other pages.
with markup.using("mkdocs"):
text = "\n".join(gs._console_install_block("PlayStation Portable", PAIRS))
text = "\n".join(install._console_install_block("PlayStation Portable", PAIRS))
self.assertNotIn("<select", text)
self.assertEqual(text.count("# RetroBat"), 2)
self.assertEqual(text.count("/i | sh"), 3)
@@ -254,7 +256,7 @@ class TheSetupListLooksLikeAList(unittest.TestCase):
# The arrow is defined for both themes.
self.assertEqual(len(re.findall(r"--rb-select-arrow:", css)), 2)
# The box's select sits in Markdown content, where the shared rule applies.
box = "\n".join(gs._console_install_block("PlayStation Portable", PAIRS))
box = "\n".join(install._console_install_block("PlayStation Portable", PAIRS))
self.assertIn('<label class="rb-install-setup">Setup <select>', box)
def test_the_built_select_shows_the_arrow(self) -> None:
+25 -21
View File
@@ -10,7 +10,11 @@ import tests
import unittest
from pathlib import Path
import generate_site as gs
from sitegen import cards
from sitegen import decorate
from sitegen import descriptions
from sitegen import emulatorpage
from sitegen import structured
REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -18,7 +22,7 @@ EMPTY_DB = {"files": {}, "indexes": {"by_name": {}}}
def _page(name: str, profile: dict) -> str:
return gs.generate_emulator_page(name, profile, EMPTY_DB, None, set())
return emulatorpage.generate_emulator_page(name, profile, EMPTY_DB, None, set())
class WhereAndHowAFileIsRead(unittest.TestCase):
@@ -71,7 +75,7 @@ class WhoShipsTheBuildAndWhy(unittest.TestCase):
def test_the_version_links_its_proof(self):
"""`0.97, stated in libretro/handy.h` was bare text beside a pinned
Revision link: the #define it reads was one search away."""
import generate_site as gs
from sitegen import emulatorcards
from sitegen import sources
import yaml
@@ -79,15 +83,15 @@ class WhoShipsTheBuildAndWhy(unittest.TestCase):
path = handy["version_basis"]["path"]
self.assertIn(path, sources.cited_paths(handy))
self.assertIn(f"stated in [`{path}`](https://github.com/libretro/libretro-handy/blob/"
f"{handy['source_commit']}/{path})", gs.version_markdown(handy))
f"{handy['source_commit']}/{path})", emulatorcards.version_markdown(handy))
tagged = {"source": "https://github.com/owner/emu", "source_commit": "a" * 40,
"core_version": "1.2-3-gaaaaaaa",
"version_basis": {"kind": "tag", "tag": "1.2", "distance": 3}}
self.assertEqual(gs.version_markdown(tagged), "1.2-3-gaaaaaaa, 3 commits after tag "
self.assertEqual(emulatorcards.version_markdown(tagged), "1.2-3-gaaaaaaa, 3 commits after tag "
"[`1.2`](https://github.com/owner/emu/tree/1.2)")
# A file no recorded tree confirms stays plain: no link beats a 404.
unread = {**tagged, "version_basis": {"kind": "file", "path": "src/none.h"}}
self.assertEqual(gs.version_markdown(unread), "1.2-3-gaaaaaaa, stated in `src/none.h`")
self.assertEqual(emulatorcards.version_markdown(unread), "1.2-3-gaaaaaaa, stated in `src/none.h`")
def test_the_upstream_pin_says_why_it_is_held(self):
"""mupen64plus showed its core revision and not that AmberELEC
@@ -109,8 +113,8 @@ class ACardKeepsItsAddress(unittest.TestCase):
def test_a_second_version_moves_nothing(self):
one = {"name": "DUKE3D.GRP", "md5": "aaaa1111bbbb"}
two = {"name": "DUKE3D.GRP", "md5": "cccc2222dddd"}
before = gs.emulator_file_anchors([one])
after = gs.emulator_file_anchors([two, one])
before = cards.emulator_file_anchors([one])
after = cards.emulator_file_anchors([two, one])
self.assertEqual(before, ["file-duke3d-grp-aaaa1111"])
self.assertEqual(after[1], before[0])
@@ -121,28 +125,28 @@ class ACardKeepsItsAddress(unittest.TestCase):
self.assertIn('<h3 id="file-duke3d-grp-aaaa1111" class="rb-file-title"', page)
# A card already holding the plain id gives it to no one else.
files = [{"name": "x.bin"}, {"name": "x.bin", "sha1": "ab" * 20}]
anchors = gs.emulator_file_anchors(files)
anchors = cards.emulator_file_anchors(files)
self.assertEqual(anchors, ["file-x-bin", "file-x-bin-abababab"])
self.assertEqual(gs.emulator_file_aliases(files, anchors), ["", ""])
self.assertEqual(structured.emulator_file_aliases(files, anchors), ["", ""])
class WhatASearchSnippetSays(unittest.TestCase):
def test_a_core_loading_no_file_promises_no_hash(self):
"""152 pages of cores that load no file announced paths and hashes."""
rel = Path("emulators/lutro.md")
saved = dict(gs.PAGE_DATA)
self.addCleanup(lambda: (gs.PAGE_DATA.clear(), gs.PAGE_DATA.update(saved)))
gs.PAGE_DATA[rel.as_posix()] = {}
text = gs._page_description("# Lutro\n", rel, "Lutro")
saved = dict(descriptions.PAGE_DATA)
self.addCleanup(lambda: (descriptions.PAGE_DATA.clear(), descriptions.PAGE_DATA.update(saved)))
descriptions.PAGE_DATA[rel.as_posix()] = {}
text = descriptions._page_description("# Lutro\n", rel, "Lutro")
self.assertNotIn("hashes", text)
self.assertIn("It needs no BIOS or firmware file.", text)
gs.PAGE_DATA[rel.as_posix()] = {"hasPart": [{"name": "a.bin"}]}
self.assertNotIn("needs no BIOS", gs._page_description("# Lutro\n", rel, "Lutro"))
descriptions.PAGE_DATA[rel.as_posix()] = {"hasPart": [{"name": "a.bin"}]}
self.assertNotIn("needs no BIOS", descriptions._page_description("# Lutro\n", rel, "Lutro"))
def test_a_long_paragraph_is_cut_at_a_word(self):
plain = ("files/?sha1= is the address that does not move: it opens the card "
"wherever the file is now, " * 4)
text = gs._shorten(plain)
text = descriptions._shorten(plain)
self.assertTrue(text.endswith("..."))
self.assertLessEqual(len(text), 160)
self.assertTrue(plain.startswith(text[:-3]))
@@ -152,13 +156,13 @@ class WhatASearchSnippetSays(unittest.TestCase):
"""The Pioneer meta description published the whole link, anchor
included: the text `[BIOS] ...bin` stopped the pattern at its "]"."""
self.assertEqual(
gs._plain_markdown("**Start with** [`[BIOS] LaserActive PAC-N1 (Japan) (v1.02).bin`]"
descriptions._plain_markdown("**Start with** [`[BIOS] LaserActive PAC-N1 (Japan) (v1.02).bin`]"
"(#sha1-6973e2593e66). ares reads it."),
"Start with [BIOS] LaserActive PAC-N1 (Japan) (v1.02).bin. ares reads it.")
self.assertEqual(gs._plain_markdown("[a [b] c](x) and [d](y)"), "a [b] c and d")
self.assertEqual(descriptions._plain_markdown("[a [b] c](x) and [d](y)"), "a [b] c and d")
def test_code_keeps_its_underscores(self):
self.assertEqual(gs._plain_markdown("only `validate_schemas.py` and _this_"),
self.assertEqual(descriptions._plain_markdown("only `validate_schemas.py` and _this_"),
"only validate_schemas.py and this")
def test_structured_url_is_encoded_like_the_canonical(self):
@@ -171,7 +175,7 @@ class WhatASearchSnippetSays(unittest.TestCase):
page = Path(tmp) / "emulators" / "idtech4a++.md"
page.parent.mkdir()
page.write_text("# idTech4A++\n\nSome text long enough to be a description.\n")
gs.decorate_markdown_pages(Path(tmp))
decorate.decorate_markdown_pages(Path(tmp))
text = page.read_text()
import yaml
+92 -86
View File
@@ -38,6 +38,12 @@ import importlib.util
import json
import generate_site as gs
from sitegen import cards
from sitegen import emulatorcards
from sitegen import emulatorpage
from sitegen import emulatorsindex
from sitegen import install as sitegen_install
from sitegen import lookup
from sitegen import render as siterender
from model import systemnames
from sitegen import validate
@@ -63,7 +69,7 @@ def _profile(name: str) -> dict:
def _page(name: str, profile: dict) -> str:
return gs.generate_emulator_page(name, profile, EMPTY_DB, None, set())
return emulatorpage.generate_emulator_page(name, profile, EMPTY_DB, None, set())
def _files(count: int, **fields: object) -> list[dict]:
@@ -76,7 +82,7 @@ class TheIntroSaysWhatIsNeeded(unittest.TestCase):
# region fills it, and every member is marked required by the loader.
profile = _profile("duckstation")
members = [f for f in profile["files"] if f.get("group") == "ps-bios"]
intro = gs._emulator_intro("DuckStation", profile)
intro = emulatorpage._emulator_intro("DuckStation", profile)
self.assertIn(
f"It needs one BIOS for the game's region, among the {len(members)} it accepts.",
intro)
@@ -84,7 +90,7 @@ class TheIntroSaysWhatIsNeeded(unittest.TestCase):
self.assertIn("DuckStation emulates Sony PlayStation.", intro)
def test_three_required_bios_of_three_regions_read_as_one_choice(self):
intro = gs._emulator_intro("X", {"systems": ["sony-playstation"], "files": [
intro = emulatorpage._emulator_intro("X", {"systems": ["sony-playstation"], "files": [
{"name": "j.bin", "required": True, "region": ["japan"]},
{"name": "u.bin", "required": True, "region": ["north-america"]},
{"name": "e.bin", "required": True, "region": ["europe"]},
@@ -94,16 +100,16 @@ class TheIntroSaysWhatIsNeeded(unittest.TestCase):
self.assertNotIn("3 of them required", intro)
def test_required_files_without_regions_keep_the_count(self):
intro = gs._emulator_intro("X", {"files": [
intro = emulatorpage._emulator_intro("X", {"files": [
{"name": "a.bin", "required": True}, {"name": "b.bin"}]})
self.assertIn("It reads 2 files, 1 of them required", intro)
def test_several_machines_say_who_needs_a_required_file(self):
intro = gs._emulator_intro("X", {
intro = emulatorpage._emulator_intro("X", {
"systems": ["sony-playstation", "sega-saturn"],
"files": [{"name": "a.bin", "required": True}]})
self.assertIn("A required file is needed only by the machines that use it.", intro)
one = gs._emulator_intro("X", {
one = emulatorpage._emulator_intro("X", {
"systems": ["sony-playstation"], "files": [{"name": "a.bin", "required": True}]})
self.assertNotIn("machines that use it", one)
@@ -162,7 +168,7 @@ class RequiredFilesComeFirst(unittest.TestCase):
self.assertGreater(len(re.findall(r"^## ", page, re.M)), 2)
def test_rows_carry_region_and_hash(self):
files = _files(gs.EMULATOR_TABLE_MIN - 1) + [
files = _files(emulatorpage.EMULATOR_TABLE_MIN - 1) + [
{"name": "req.bin", "required": True, "region": ["japan"], "md5": "ab" * 16}]
page = _page("x", {"type": "standalone", "files": files})
required = page[page.index("## Required"):page.index("## Optional")]
@@ -177,11 +183,11 @@ class RequiredFilesComeFirst(unittest.TestCase):
self.assertIn('class="rb-file-entry"', page)
def test_a_split_page_puts_required_on_the_first_part(self):
count = gs.EMULATOR_CARDS_PER_PAGE * 2
count = emulatorpage.EMULATOR_CARDS_PER_PAGE * 2
files = _files(count) + [{"name": "last.bin", "required": True}]
parts = gs.emulator_parts("big", files)
parts = emulatorpage.emulator_parts("big", files)
self.assertIn(count, parts[0][1])
pages = gs.emulator_pages("big", {"emulator": "Big", "type": "standalone",
pages = emulatorpage.emulator_pages("big", {"emulator": "Big", "type": "standalone",
"files": files}, {"files": {}})
main = pages["big"]
self.assertLess(main.index("## Required"), main.index("## Optional"))
@@ -195,14 +201,14 @@ class TheSummaryLineIsProse(unittest.TestCase):
{"name": "a.pak", "category": "game_data"}, {"name": "b.pak", "category": "game_data"}]
for f in files[:164]:
f["required"] = True
text = "\n".join(gs._emulator_file_summary(files))
text = "\n".join(emulatorpage._emulator_file_summary(files))
self.assertNotIn(" | ", text)
self.assertNotIn("1399", text)
self.assertIn("1,401 optional", text)
self.assertIn("By kind: 1,563 BIOS ZIPs and 2 game data.", text)
def test_category_badge_in_words(self):
badges = " ".join(gs._file_badges({"name": "a", "category": "game_data"}, True))
badges = " ".join(emulatorcards._file_badges({"name": "a", "category": "game_data"}, True))
self.assertIn(">game data</span>", badges)
@@ -214,7 +220,7 @@ class TheIndexNamesEmulatorsAndSystems(unittest.TestCase):
saved = dict(siterender._system_page_map)
self.addCleanup(siterender.set_system_page_map, saved)
siterender.set_system_page_map({"sony-playstation": ("sony", "PlayStation")})
page = gs.generate_emulators_index({
page = emulatorsindex.generate_emulators_index({
"duckstation": {"emulator": "DuckStation", "core_classification": "official_port",
"systems": ["sony-playstation"], "files": _files(3)},
})
@@ -232,28 +238,28 @@ DIST = REPO_ROOT / "website" / "dist"
def _emulator_page(name: str, profile: dict | None = None) -> str:
return gs.generate_emulator_page(name, profile or _profile(name), EMPTY_DB, None, set())
return emulatorpage.generate_emulator_page(name, profile or _profile(name), EMPTY_DB, None, set())
class EachArcadePageNamesItsRomset(unittest.TestCase):
def test_the_romset_by_profile(self):
self.assertEqual(gs.emulator_romset(_profile("mame2003")), "MAME 0.78")
self.assertEqual(emulatorcards.emulator_romset(_profile("mame2003")), "MAME 0.78")
# The app's version is 1.38.1, its MAME is 0.289.
self.assertEqual(gs.emulator_romset(_profile("mame4droid-2024")), "MAME 0.289")
self.assertEqual(gs.emulator_romset(_profile("mame2003_plus")), "MAME 0.78 (plus backports)")
self.assertTrue(gs.emulator_romset(_profile("fbneo")).startswith("FinalBurn Neo "))
self.assertTrue(gs.emulator_romset(_profile("fbalpha2012")).startswith("FB Alpha "))
self.assertEqual(gs.emulator_romset(_profile("duckstation")), "")
self.assertEqual(emulatorcards.emulator_romset(_profile("mame4droid-2024")), "MAME 0.289")
self.assertEqual(emulatorcards.emulator_romset(_profile("mame2003_plus")), "MAME 0.78 (plus backports)")
self.assertTrue(emulatorcards.emulator_romset(_profile("fbneo")).startswith("FinalBurn Neo "))
self.assertTrue(emulatorcards.emulator_romset(_profile("fbalpha2012")).startswith("FB Alpha "))
self.assertEqual(emulatorcards.emulator_romset(_profile("duckstation")), "")
# HBMAME publishes no MAME release number.
self.assertEqual(gs.emulator_romset(_profile("hbmame")), "")
self.assertEqual(emulatorcards.emulator_romset(_profile("hbmame")), "")
def test_a_row_and_a_line_under_the_intro(self):
page = _emulator_page("mame2003")
self.assertIn(f"| Romset | [MAME 0.78]({gs.ROMSET_FAQ}) |", page)
self.assertIn(f"| Romset | [MAME 0.78]({cards.ROMSET_FAQ}) |", page)
self.assertNotIn("| MAME version |", _emulator_page("mame2016"))
line = page.index("Its BIOS and game sets must come from the MAME 0.78 romset.")
self.assertLess(line, page.index("About this profile"))
self.assertIn(f"[Which version each core reads]({gs.ROMSET_FAQ})", page)
self.assertIn(f"[Which version each core reads]({cards.ROMSET_FAQ})", page)
def test_the_faq_answer_exists(self):
faq = (REPO_ROOT / "wiki" / "technical-faq.md").read_text(encoding="utf-8")
@@ -270,23 +276,23 @@ class WhatTheAppShipsIsNoFileToGet(unittest.TestCase):
def test_the_badge(self):
font = next(f for f in self.profile["files"] if f["name"] == "Roboto-Regular.ttf")
badges = " ".join(gs._file_badges(font, False))
badges = " ".join(emulatorcards._file_badges(font, False))
self.assertIn(">comes with the app</span>", badges)
self.assertNotIn(">required</span>", badges)
self.assertNotIn(">missing</span>", badges)
# Narrowed to one build, the entry is that build's alone, as verify
# and the pack read it: EightyOne installs its ROMs, and the libretro
# core, which embeds them, reads no entry. Nothing to fetch.
dual = " ".join(gs._file_badges({"name": "a", "bundled": True, "mode": "standalone",
dual = " ".join(emulatorcards._file_badges({"name": "a", "bundled": True, "mode": "standalone",
"required": True}, False))
self.assertNotIn(">required</span>", dual)
self.assertNotIn(">missing</span>", dual)
self.assertIn("installed with the standalone emulator", dual)
rom = next(f for f in _profile("81")["files"] if f["name"] == "jupiterace.rom")
self.assertTrue(gs.comes_with_app(rom))
self.assertTrue(sitegen_install.comes_with_app(rom))
def test_counts_leave_them_out(self):
shipped = sum(1 for f in self.profile["files"] if gs.comes_with_app(f))
shipped = sum(1 for f in self.profile["files"] if sitegen_install.comes_with_app(f))
self.assertGreater(shipped, 0)
summary = self.page[self.page.index("## Files"):]
self.assertIn(f"{shipped} more files come with the app.", summary)
@@ -313,33 +319,33 @@ class WhatTheAppShipsIsNoFileToGet(unittest.TestCase):
class TheSummaryTableFitsItsContent(unittest.TestCase):
def test_an_empty_region_column_goes(self):
rows = gs._summary_table(_files(3, md5="ab" * 16), [0, 1, 2], lambda _i, s: s)
rows = emulatorpage._summary_table(_files(3, md5="ab" * 16), [0, 1, 2], lambda _i, s: s)
self.assertNotIn("Region", rows[0])
def test_a_constant_required_column_goes(self):
rows = gs._summary_table(_files(3, required=True), [0, 1, 2], lambda _i, s: s)
rows = emulatorpage._summary_table(_files(3, required=True), [0, 1, 2], lambda _i, s: s)
self.assertEqual(rows[0], "| File |")
def test_hashes_are_short_with_the_whole_value_in_the_title(self):
md5 = "0123456789abcdef" * 2
cell = gs._hash_short({"md5": md5})
cell = emulatorpage._hash_short({"md5": md5})
self.assertEqual(cell, f'MD5 <code title="{md5}">{md5[:12]}</code>')
def test_the_split_index_holds_each_id_on_its_link(self):
files = _files(gs.EMULATOR_CARDS_PER_PAGE + 1, category="bios_zip")
main = gs.emulator_pages("big", {"emulator": "Big", "type": "standalone",
files = _files(emulatorpage.EMULATOR_CARDS_PER_PAGE + 1, category="bios_zip")
main = emulatorpage.emulator_pages("big", {"emulator": "Big", "type": "standalone",
"files": files}, {"files": {}})["big"]
anchor = gs.emulator_file_anchors(files)[0]
anchor = cards.emulator_file_anchors(files)[0]
self.assertIn(f'<a id="{anchor}" href="/retrobios/emulators/big-files-1/#{anchor}">', main)
self.assertNotIn(f'<span id="{anchor}"></span>', main)
class LongPagesFold(unittest.TestCase):
def test_each_entry_is_listed_once_as_a_row(self):
files = _files(gs.EMULATOR_TABLE_MIN) + [{"name": "req.bin", "required": True}]
files = _files(emulatorpage.EMULATOR_TABLE_MIN) + [{"name": "req.bin", "required": True}]
page = _emulator_page("x", {"type": "standalone", "files": files})
self.assertNotIn("| File |", page)
self.assertNotIn(f"<summary>{gs.EMULATOR_TABLE_MIN} files</summary>", page)
self.assertNotIn(f"<summary>{emulatorpage.EMULATOR_TABLE_MIN} files</summary>", page)
self.assertEqual(page.count('<h3 id="file-'), len(files))
required = page[page.index("## Required"):page.index("## Optional")]
self.assertEqual(required.count('<h3 id="file-'), 1)
@@ -358,12 +364,12 @@ class LongPagesFold(unittest.TestCase):
class DataDirectoryPagesStayOutOfSearch(unittest.TestCase):
def test_front_matter(self):
saved = dict(gs._DATA_MEMBERS), dict(gs._DATA_READERS)
self.addCleanup(lambda: (gs._DATA_MEMBERS.clear(), gs._DATA_MEMBERS.update(saved[0]),
gs._DATA_READERS.clear(), gs._DATA_READERS.update(saved[1])))
gs._DATA_MEMBERS["dolphin-sys"] = {"a.bin": {"sha1": "a" * 40, "size": 1}}
gs._DATA_READERS["dolphin-sys"] = [("dolphin-mmjr", "Dolphin MMJR"), ("dolphin", "Dolphin")]
page = gs._data_tree_page("dolphin-sys", {}, [("data-dolphin-sys", ["a.bin"])], 0)
saved = dict(emulatorcards._DATA_MEMBERS), dict(emulatorpage._DATA_READERS)
self.addCleanup(lambda: (emulatorcards._DATA_MEMBERS.clear(), emulatorcards._DATA_MEMBERS.update(saved[0]),
emulatorpage._DATA_READERS.clear(), emulatorpage._DATA_READERS.update(saved[1])))
emulatorcards._DATA_MEMBERS["dolphin-sys"] = {"a.bin": {"sha1": "a" * 40, "size": 1}}
emulatorpage._DATA_READERS["dolphin-sys"] = [("dolphin-mmjr", "Dolphin MMJR"), ("dolphin", "Dolphin")]
page = emulatorpage._data_tree_page("dolphin-sys", {}, [("data-dolphin-sys", ["a.bin"])], 0)
front = yaml.safe_load(page.split("---\n")[1])
self.assertEqual(front["search"], "exclude")
self.assertEqual(front["parent"], {"label": "Dolphin", "link": "dolphin.md"})
@@ -393,7 +399,7 @@ class AnElementBudget(unittest.TestCase):
def _pages(name: str, profile: dict | None = None) -> dict[str, str]:
return gs.emulator_pages(name, profile or _profile(name), EMPTY_DB, None, set())
return emulatorpage.emulator_pages(name, profile or _profile(name), EMPTY_DB, None, set())
def _front(page: str) -> dict:
@@ -440,13 +446,13 @@ class AnAppThatReadsAnyBios(unittest.TestCase):
def test_only_found_by_content_with_one_bios(self):
# DuckStation picks the BIOS of the game's region: its intro stays.
self.assertIsNone(gs.any_name_bios(_profile("duckstation")))
self.assertIsNone(gs.any_name_bios(_profile("melonds")))
self.assertIsNotNone(gs.any_name_bios(_profile("pcsx2")))
self.assertIsNone(emulatorcards.any_name_bios(_profile("duckstation")))
self.assertIsNone(emulatorcards.any_name_bios(_profile("melonds")))
self.assertIsNotNone(emulatorcards.any_name_bios(_profile("pcsx2")))
def test_the_download_links_the_collection_card(self):
steps = gs._any_name_steps("X", _profile("aethersx2"),
gs.any_name_bios(_profile("aethersx2")),
steps = emulatorpage._any_name_steps("X", _profile("aethersx2"),
emulatorcards.any_name_bios(_profile("aethersx2")),
"../systems/sony.md#sha1-abc")
self.assertIn("1. Download [`ps2-0230a-20080220.bin`](../systems/sony.md#sha1-abc).", steps)
@@ -480,15 +486,15 @@ class PartsKnowWhereTheySit(unittest.TestCase):
def test_data_directory_parts(self):
ref = "x-sys"
members = {f"f{i:05d}": {"size": 1, "sha1": f"{i:040x}"}
for i in range(gs.DATA_TREE_ROWS_PER_PAGE * 2 + 1)}
gs._DATA_MEMBERS[ref] = members
gs._DATA_READERS[ref] = [("x", "X")]
for i in range(lookup.DATA_TREE_ROWS_PER_PAGE * 2 + 1)}
emulatorcards._DATA_MEMBERS[ref] = members
emulatorpage._DATA_READERS[ref] = [("x", "X")]
try:
pages = gs.data_tree_pages(ref, members)
pages = lookup.data_tree_pages(ref, members)
self.assertEqual(len(pages), 3)
middle = _front(gs._data_tree_page(ref, {}, pages, 1))
middle = _front(emulatorpage._data_tree_page(ref, {}, pages, 1))
finally:
del gs._DATA_MEMBERS[ref], gs._DATA_READERS[ref]
del emulatorcards._DATA_MEMBERS[ref], emulatorpage._DATA_READERS[ref]
self.assertEqual(middle["parent"], {"label": "X", "link": "x.md"})
self.assertEqual(middle["prev"]["link"], f"{pages[0][0]}.md")
self.assertEqual(middle["next"]["link"], f"{pages[2][0]}.md")
@@ -513,7 +519,7 @@ class ARequiredFileSaysForWhichSystem(unittest.TestCase):
class TheTemplateIsNoEmulator(unittest.TestCase):
def test_off_the_index_and_the_search(self):
profiles = {"00_example": _profile("00_example"), "melonds": _profile("melonds")}
index = gs.generate_emulators_index(profiles)
index = emulatorsindex.generate_emulators_index(profiles)
self.assertNotIn("00_example", index)
self.assertIn("melonds.md", index)
# A test profile gets no page at all (generate_site's public_profiles).
@@ -596,30 +602,30 @@ class FolderOnlyTable(unittest.TestCase):
def test_every_row_names_a_profile_and_entries_that_exist(self) -> None:
roots = _profiles_with_data_root()
for profile_name, patterns, keys, reason in gs.FOLDER_ONLY:
for profile_name, patterns, keys, reason in sitegen_install.FOLDER_ONLY:
with self.subTest(profile=profile_name, patterns=patterns):
self.assertIn(profile_name, roots, "no profile with data_root by that name")
self.assertTrue(reason.strip())
entries = _entries(roots[profile_name])
for pattern in patterns:
self.assertTrue(
any(gs.folder_only_matches(pattern, f) for f in entries),
any(sitegen_install.folder_only_matches(pattern, f) for f in entries),
f"{pattern!r} names no entry of {profile_name}")
self.assertLessEqual(set(keys), set(roots[profile_name]["data_root"]))
def test_a_listed_entry_is_never_joined_to_the_root(self) -> None:
roots = _profiles_with_data_root()
for profile_name, patterns, keys, _reason in gs.FOLDER_ONLY:
for profile_name, patterns, keys, _reason in sitegen_install.FOLDER_ONLY:
profile = roots[profile_name]
for entry in _entries(profile):
if not any(gs.folder_only_matches(p, entry) for p in patterns):
if not any(sitegen_install.folder_only_matches(p, entry) for p in patterns):
continue
raw = {str(entry.get(k) or "") for k in ("path", "standalone_path")} - {""}
for key in keys or tuple(profile["data_root"]):
with self.subTest(profile=profile_name, entry=entry.get("name"), key=key):
self.assertEqual(gs.standalone_place(profile_name, profile, entry, key), "")
self.assertEqual(gs.standalone_place(profile_name, profile, entry), "")
block = "\n".join(gs.data_folder_block(profile_name, profile))
self.assertEqual(sitegen_install.standalone_place(profile_name, profile, entry, key), "")
self.assertEqual(sitegen_install.standalone_place(profile_name, profile, entry), "")
block = "\n".join(sitegen_install.data_folder_block(profile_name, profile))
for root in _alternatives(str(profile["data_root"][key]["path"])):
for place in raw:
self.assertNotIn(f"{root}/{place}", block)
@@ -628,12 +634,12 @@ class FolderOnlyTable(unittest.TestCase):
if not _generated():
self.skipTest("site pages not generated")
roots = _profiles_with_data_root()
for profile_name, patterns, keys, _reason in gs.FOLDER_ONLY:
for profile_name, patterns, keys, _reason in sitegen_install.FOLDER_ONLY:
profile = roots[profile_name]
pages = [p.read_text(encoding="utf-8")
for p in EMULATORS.glob(f"{profile_name}*.md*")]
for entry in _entries(profile):
if not any(gs.folder_only_matches(p, entry) for p in patterns):
if not any(sitegen_install.folder_only_matches(p, entry) for p in patterns):
continue
for key in keys or tuple(profile["data_root"]):
for root in _alternatives(str(profile["data_root"][key]["path"])):
@@ -658,37 +664,37 @@ class DataFolderPrinted(unittest.TestCase):
self.assertIn(alternative, page)
def test_ryujinx_keys_sit_in_system(self) -> None:
block = "\n".join(gs.data_folder_block("ryujinx", _profile("ryujinx")))
block = "\n".join(sitegen_install.data_folder_block("ryujinx", _profile("ryujinx")))
self.assertIn("`%APPDATA%/Ryujinx/system/`", block)
self.assertIn("`~/Library/Application Support/Ryujinx/system/`", block)
self.assertEqual(_tab_labels(block), {"Windows", "macOS", "Linux"})
def test_aethersx2_step_names_the_android_folder(self) -> None:
profile = _profile("aethersx2")
steps = gs._any_name_steps("AetherSX2", profile, gs.any_name_bios(profile), "", "aethersx2")
steps = emulatorpage._any_name_steps("AetherSX2", profile, emulatorcards.any_name_bios(profile), "", "aethersx2")
self.assertIn("2. Put it in this folder:", steps)
self.assertIn("`Android/data/xyz.aethersx2.android/files/bios/`, on the internal storage.",
steps)
self.assertNotIn("app's own data folder", steps)
def test_one_system_is_a_line_not_a_tab(self) -> None:
block = "\n".join(gs.data_folder_block("mame4droid", _profile("mame4droid")))
block = "\n".join(sitegen_install.data_folder_block("mame4droid", _profile("mame4droid")))
self.assertTrue(block.startswith("On Android: `Android/data/com.seleuco.mame4droid/files/`"))
self.assertNotIn("<Tabs", block)
def test_an_entry_found_by_name_or_shipped_is_not_placed(self) -> None:
profile = {"type": "standalone", "data_root": {"linux": {"path": "~/x", "source_ref": "a"}}}
self.assertEqual(gs.standalone_place("x", profile, {"name": "a.bin"}), "")
self.assertEqual(gs.standalone_place("x", profile, {"name": "a", "path": "a", "bundled": True}),
self.assertEqual(sitegen_install.standalone_place("x", profile, {"name": "a.bin"}), "")
self.assertEqual(sitegen_install.standalone_place("x", profile, {"name": "a", "path": "a", "bundled": True}),
"")
self.assertEqual(gs.standalone_place("x", profile, {"name": "a", "path": "b/a"}), "b/a")
self.assertEqual(sitegen_install.standalone_place("x", profile, {"name": "a", "path": "b/a"}), "b/a")
dual = {**profile, "type": "standalone + libretro"}
self.assertEqual(gs.standalone_place("x", dual, {"name": "a", "path": "core/a"}), "")
self.assertEqual(gs.standalone_place("x", dual, {"name": "a", "path": "c/a",
self.assertEqual(sitegen_install.standalone_place("x", dual, {"name": "a", "path": "core/a"}), "")
self.assertEqual(sitegen_install.standalone_place("x", dual, {"name": "a", "path": "c/a",
"standalone_path": "a"}), "a")
def test_the_metadata_card_has_a_row_per_system(self) -> None:
rows = gs._render_metadata_rows(_profile("cxbx-reloaded"))
rows = emulatorcards._render_metadata_rows(_profile("cxbx-reloaded"))
self.assertIn("| Data folder (Windows) | `%APPDATA%/Cxbx-Reloaded/` |", rows)
self.assertFalse(any("Data folder (Linux)" in row for row in rows))
@@ -731,33 +737,33 @@ class InstallBlockWhereItWorks(unittest.TestCase):
for name, profile in _profiles_with_data_root().items():
allowed = {labels["device"]}
for key in profile["data_root"]:
allowed |= {labels[t] for t in gs._DATA_ROOT_TERMINALS[key]}
allowed |= {labels[t] for t in sitegen_install._DATA_ROOT_TERMINALS[key]}
with self.subTest(profile=name):
self.assertLessEqual(_tab_labels(_install_section(_built_page(name))), allowed)
def test_android_only_app_gets_no_desktop_command(self) -> None:
self.assertEqual(gs._install_block("mame4droid", _profile("mame4droid")), [])
command, setups, oses = gs.emulator_install_route("cxbx-reloaded", _profile("cxbx-reloaded"))
self.assertEqual(sitegen_install._install_block("mame4droid", _profile("mame4droid")), [])
command, setups, oses = sitegen_install.emulator_install_route("cxbx-reloaded", _profile("cxbx-reloaded"))
self.assertEqual(oses, ("windows",))
def test_a_lone_app_is_named_with_the_setup_that_launches_it(self) -> None:
text = "\n".join(gs._install_block("ryujinx", _profile("ryujinx")))
text = "\n".join(sitegen_install._install_block("ryujinx", _profile("ryujinx")))
self.assertRegex(text, r"With [^:]*EmuDeck[^:]*: the installer finds")
self.assertNotIn("Android (Termux)", text)
self.assertNotIn("RetroArch", text)
def test_a_dual_app_says_what_the_command_fills(self) -> None:
text = "\n".join(gs._install_block("duckstation", _profile("duckstation")))
text = "\n".join(sitegen_install._install_block("duckstation", _profile("duckstation")))
self.assertIn("For DuckStation inside RetroArch, Batocera or another setup.", text)
def test_no_files_no_command(self) -> None:
self.assertEqual(gs._install_block("beetle_wswan", _profile("beetle_wswan")), [])
self.assertEqual(sitegen_install._install_block("beetle_wswan", _profile("beetle_wswan")), [])
def test_tabs_follow_the_keys_given(self) -> None:
tabs = "\n".join(gs.install_commands("--emulator x", oses=("linux", "steamdeck")))
tabs = "\n".join(sitegen_install.install_commands("--emulator x", oses=("linux", "steamdeck")))
self.assertEqual(_tab_labels(tabs), {"Linux", "Steam Deck"})
self.assertIn('syncKey="os"', tabs)
blocks = "\n".join(gs.install_commands("--emulator x"))
blocks = "\n".join(sitegen_install.install_commands("--emulator x"))
self.assertIn("Windows (PowerShell):", blocks)
@@ -772,7 +778,7 @@ class SmallFixes(unittest.TestCase):
def test_region_choice_summary(self) -> None:
profile = _profile("duckstation")
members = sum(1 for f in profile["files"] if f.get("group") == "ps-bios")
lines = gs._emulator_file_summary(profile["files"], profile.get("groups"))
lines = emulatorpage._emulator_file_summary(profile["files"], profile.get("groups"))
self.assertIn(f"One of {members} is required, for the games' region.", lines[0])
self.assertNotIn(f"{members} required", lines[0])
@@ -780,7 +786,7 @@ class SmallFixes(unittest.TestCase):
files = [{"name": "a.rom", "required": True, "group": "boot"},
{"name": "b.rom", "required": True, "group": "boot"},
{"name": "c.rom", "required": True}, {"name": "d.rom"}]
line = gs._emulator_file_summary(files, {"boot": {"required": True}})[0]
line = emulatorpage._emulator_file_summary(files, {"boot": {"required": True}})[0]
self.assertIn("2 required, 1 optional. Any one file of a required set fills it.", line)
def test_no_emulator_part_says_where_it_sits(self) -> None:
@@ -805,7 +811,7 @@ class AnEmulatorPageNamesItsSetups(unittest.TestCase):
"c": {"config": {"cores": ["other"]}},
}
profiles = {"handy": {"type": "libretro"}, "other": {"type": "libretro"}}
self.assertEqual(gs.emulator_setups(coverages, profiles)["handy"], ["a", "b"])
self.assertEqual(emulatorcards.emulator_setups(coverages, profiles)["handy"], ["a", "b"])
def test_the_page_names_them(self):
from tests import sitepages
@@ -843,7 +849,7 @@ class ADataDirectoryNamesAFetchableOrigin(unittest.TestCase):
def test_the_url_is_substituted_and_a_commit_is_linked(self):
entry = {"source_url": "https://github.com/PCSX2/pcsx2/archive/{version}.tar.gz",
"version": "6db638dc0373769b4c5d5b5dd7ed6da641b9a18e"}
lines = gs.data_directory_origin(entry, {"sha": entry["version"],
lines = lookup.data_directory_origin(entry, {"sha": entry["version"],
"version": entry["version"]})
self.assertEqual(lines[0], "Fetched from <https://github.com/PCSX2/pcsx2/archive/"
"6db638dc0373769b4c5d5b5dd7ed6da641b9a18e.tar.gz>")
@@ -853,7 +859,7 @@ class ADataDirectoryNamesAFetchableOrigin(unittest.TestCase):
def test_an_etag_is_no_revision(self):
entry = {"source_url": "https://buildbot.libretro.com/assets/system/Dolphin.zip"}
lines = gs.data_directory_origin(entry, {"sha": '"2047720058"', "version": "master"})
lines = lookup.data_directory_origin(entry, {"sha": '"2047720058"', "version": "master"})
self.assertEqual(lines, ["Fetched from <https://buildbot.libretro.com/assets/system/Dolphin.zip>"])
def test_every_registered_url_resolves(self):
@@ -861,7 +867,7 @@ class ADataDirectoryNamesAFetchableOrigin(unittest.TestCase):
for ref, entry in (registry.get("data_directories") or registry).items():
if isinstance(entry, dict):
with self.subTest(ref=ref):
self.assertNotIn("{", " ".join(gs.data_directory_origin(entry, {})))
self.assertNotIn("{", " ".join(lookup.data_directory_origin(entry, {})))
if __name__ == "__main__":
+56 -47
View File
@@ -44,6 +44,15 @@ import yaml
from sitegen import readme as sitegen_readme
import generate_site
from sitegen import config
from sitegen import descriptions
from sitegen import guidepage
from sitegen import home as sitegen_home
from sitegen import install as sitegen_install
from sitegen import nav as sitegen_nav
from sitegen import platformindex
from sitegen import reference
from sitegen import versions
import release_record
from model import guides
from sitegen import markup as sitemarkup
@@ -101,10 +110,10 @@ class TrustItemsSayWhereItWrites(unittest.TestCase):
class NextStepsIsAPlainList(unittest.TestCase):
def test_the_helpers(self):
block = "\n".join(generate_site._next_block(["[A](a.md)", "[B](b.md)"]))
block = "\n".join(sitegen_home._next_block(["[A](a.md)", "[B](b.md)"]))
self.assertEqual(block, "## Next steps\n\n- [A](a.md)\n- [B](b.md)\n")
self.assertIn("## Next steps", generate_site.reference_next())
self.assertNotIn(":::", generate_site.reference_next())
self.assertIn("## Next steps", reference.reference_next())
self.assertNotIn(":::", reference.reference_next())
def test_entry_pages(self):
for name in ("which-pack.md", "contributing.md", "platforms/batocera.md",
@@ -126,7 +135,7 @@ class DatesInWords(unittest.TestCase):
def test_data_as_of(self):
moment = datetime(2026, 10, 22, 22, 43, 8, tzinfo=timezone.utc)
self.assertEqual(
generate_site.data_as_of(moment),
config.data_as_of(moment),
'<time datetime="2026-10-22T22:43:08Z">Data as of 22 October 2026</time>',
)
@@ -223,7 +232,7 @@ class GuideRoutes(unittest.TestCase):
def test_a_device_system_opens_on_the_computer_route(self):
text = _page("platforms/batocera.md")
self.assertLess(text.index("## From a computer"), text.index("## On the device"))
self.assertIn("{ #install }", "\n".join(generate_site._guide_install(
self.assertIn("{ #install }", "\n".join(guidepage._guide_install(
"batocera", guides.GUIDES["batocera"], "## On the device { #install }")))
self.assertIn("Unzip them all into the network folder above", text)
@@ -278,17 +287,17 @@ class DownloadNamesTheRelease(unittest.TestCase):
if not release_record.pack_for("batocera", record):
self.skipTest("release.json has no Batocera pack")
tag = record["tag"]
lines = generate_site.release_line("batocera", record)
lines = versions.release_line("batocera", record)
self.assertTrue(lines[0].startswith(f"Pack {tag}, built "))
self.assertIn(f"/releases/download/{tag}/SHA256SUMS.txt)", lines[0])
self.assertIn(f"/releases/download/{tag}/SHA256SUMS.txt.sig)", lines[0])
self.assertEqual(generate_site._release_date("v2026.10.10"), "10 October 2026")
self.assertEqual(versions._release_date("v2026.10.10"), "10 October 2026")
def test_a_newer_platform_than_the_pack_is_named(self):
record = {"tag": "v2026.10.10", "packs": {"RetroBat_1.0_BIOS_Pack.zip": {
"assets": ["RetroBat_1.0_BIOS_Pack.zip"], "platforms": ["retrobat"]}}}
version = load_platform_config("retrobat", str(REPO_ROOT / "platforms"))["version"]
lines = generate_site.release_line("retrobat", record)
lines = versions.release_line("retrobat", record)
self.assertIn(f"built for RetroBat 1.0. The command installs the files for "
f"RetroBat {version}.", lines[-1])
@@ -308,7 +317,7 @@ class CommandBlocks(unittest.TestCase):
self.assertGreaterEqual(len(commands), 3)
for group in commands:
self.assertIn("/i.ps1", group)
block = "\n".join(generate_site._console_install_block(
block = "\n".join(sitegen_install._console_install_block(
"PlayStation", [("batocera", "psx"), ("recalbox", "psx")]))
# Every setup's options in both forms: the list of every command,
# and the one command under the OS tabs.
@@ -325,7 +334,7 @@ class CommandBlocks(unittest.TestCase):
class ContributingOpensOnTheAction(unittest.TestCase):
def test_both_generators_open_on_the_upload(self):
for text in (sitegen_readme.generate_contributing(), generate_site.generate_contributing()):
for text in (sitegen_readme.generate_contributing(), reference.generate_contributing()):
body = text.split("## Add a BIOS file", 1)[1]
self.assertTrue(body.lstrip().startswith("Have a file the collection lacks?"))
self.assertLess(body.index(sitegen_readme.UPLOAD_URL), body.index("## What happens next"))
@@ -333,9 +342,9 @@ class ContributingOpensOnTheAction(unittest.TestCase):
self.assertLess(body.index("## What happens next"), body.index("CI hashes"))
def test_description_is_a_sentence(self):
text = generate_site._page_description("", Path("contributing.md"), "Contributing")
text = descriptions._page_description("", Path("contributing.md"), "Contributing")
self.assertTrue(text.endswith("."))
fallback = generate_site._page_description(
fallback = descriptions._page_description(
"One file needs no clone and no local setup at all here:\n\n"
"A plain sentence that describes the page well enough.",
Path("other.md"), "Other")
@@ -386,7 +395,7 @@ class HandheldWayIn(unittest.TestCase):
text = _page(GUIDE.path)
for system in GUIDE.systems:
with self.subTest(system=system.name):
self.assertIn(f"| {generate_site.handheld_name(system)} |", text)
self.assertIn(f"| {guidepage.handheld_name(system)} |", text)
def test_a_system_that_stopped_says_so_with_its_source(self):
"""ArkOS was archived on 30 December 2025 and points to dArkOS: the
@@ -437,7 +446,7 @@ class HandheldWayIn(unittest.TestCase):
def test_the_guide_is_in_the_handheld_group_of_the_navigation(self):
coverages = {key: {"platform": _display(key)} for key in REGISTRY}
nav = generate_site.generate_nav(coverages, {}, {}, REGISTRY)
nav = sitegen_nav.generate_nav(coverages, {}, {}, REGISTRY)
setup = next(tab["Setups"] for tab in nav if "Setups" in tab)
groups = {next(iter(item)): next(iter(item.values()))
for item in setup if isinstance(item, dict)}
@@ -455,18 +464,18 @@ class PackNamesItsVersion(unittest.TestCase):
record = release_record.load_record()
if not release_record.pack_for("batocera", record):
self.skipTest("release.json has no Batocera pack")
block = generate_site._pack_buttons("batocera")
block = guidepage._pack_buttons("batocera")
name = release_record.pack_name_for("batocera", record)
version = generate_site._pack_version(name, ["batocera"])
version = versions._pack_version(name, ["batocera"])
self.assertIn(f"Made for Batocera {version}. "
+ generate_site.other_version("batocera"), block)
+ versions.other_version("batocera"), block)
def test_a_version_gap_is_said_once(self):
record = {"tag": "v2026.10.10", "packs": {"RetroBat_1.0_BIOS_Pack.zip": {
"assets": ["RetroBat_1.0_BIOS_Pack.zip"], "platforms": ["retrobat"]}}}
released = generate_site.release_line("retrobat", record)
line = generate_site.version_line("retrobat", record, named=len(released) > 1)
self.assertEqual(line, generate_site.other_version("retrobat"))
released = versions.release_line("retrobat", record)
line = versions.version_line("retrobat", record, named=len(released) > 1)
self.assertEqual(line, versions.other_version("retrobat"))
def test_a_version_with_an_underscore_is_read_whole(self):
"""AmberELEC's prerelease-20261019_1835 read as 1835, and the page
@@ -475,21 +484,21 @@ class PackNamesItsVersion(unittest.TestCase):
version = load_platform_config("amberelec", "platforms")["version"]
name = _platform_pack_stem(["amberelec"], "amberelec", "platforms") + "_BIOS_Pack.zip"
self.assertEqual(generate_site._pack_version(name, ["amberelec"]), version)
self.assertEqual(versions._pack_version(name, ["amberelec"]), version)
record = {"tag": "v2026.10.10", "packs": {name: {
"assets": [name], "platforms": ["amberelec"]}}}
self.assertEqual(len(generate_site.release_line("amberelec", record)), 1)
self.assertEqual(len(versions.release_line("amberelec", record)), 1)
def test_another_version_is_sent_to_the_check_commands(self):
"""A ZIP reader read "Run `--check` after copying." with no command."""
line = generate_site.other_version("emudeck")
line = versions.other_version("emudeck")
self.assertNotIn("Run `--check`", line)
self.assertIn("](../platforms/emudeck.md#how-to-check)", line)
page = _page("platforms/emudeck.md")
self.assertIn("{ #how-to-check }", page)
def test_the_v_prefix_is_dropped(self):
self.assertEqual(generate_site.setup_version("retroarch", {}),
self.assertEqual(versions.setup_version("retroarch", {}),
f"RetroArch {load_platform_config('retroarch', 'platforms')['version'].lstrip('v')}")
def test_every_setup_page_names_a_version(self):
@@ -498,10 +507,10 @@ class PackNamesItsVersion(unittest.TestCase):
for key in REGISTRY:
with self.subTest(platform=key):
text = _plain_guide_part(_page(f"platforms/{key}.md"))
if generate_site.has_release_pack(key):
if sitegen_install.has_release_pack(key):
self.assertRegex(text, r"(?:[Mm]ade for|This pack was built for) \S")
else:
self.assertIn(generate_site.no_zip_line(_display(key)), text)
self.assertIn(guidepage.no_zip_line(_display(key)), text)
class SetupPagesOfferPartOfThePack(unittest.TestCase):
@@ -612,7 +621,7 @@ class YourSetupIndexInPlainWords(unittest.TestCase):
def test_insertion_keeps_next_steps_last(self):
page = "# T\n\nBody.\n\n## Next steps\n\n- [A](a.md)\n"
out = generate_site.with_setup_table(page, {})
out = platformindex.with_setup_table(page, {})
self.assertTrue(out.rstrip().endswith("- [A](a.md)"))
self.assertIn("## Every setup at a glance", out)
@@ -659,7 +668,7 @@ class DownloadLine(unittest.TestCase):
record = release_record.load_record()
if not release_record.pack_for("batocera", record):
self.skipTest("release.json has no Batocera pack")
line = generate_site.release_line("batocera", record)[0]
line = versions.release_line("batocera", record)[0]
self.assertRegex(line, r"\[SHA256SUMS\.txt\]\([^)]+\) and its \[signature\]\([^)]+\)\.$")
@@ -718,22 +727,22 @@ class NoZipNoUnzipText(unittest.TestCase):
def test_a_mac_and_a_linux_desktop_reach_the_share_too(self):
"""The share route was a PowerShell tab alone: a Mac user with Recalbox
on Wi-Fi fell back to SSH or to taking the card out."""
args, how = generate_site._share_tabs("recalbox", "\\\\RECALBOX\\share\\bios")
args, how = guidepage._share_tabs("recalbox", "\\\\RECALBOX\\share\\bios")
self.assertEqual(args["macos"], "--platform recalbox --dest /Volumes/share/bios")
self.assertIn("`smb://recalbox/share`", how["macos"])
self.assertEqual(args["linux"], "--platform recalbox --dest /path/to/share/bios")
self.assertIn("`smb://recalbox/share`", how["linux"])
lines = generate_site._setup_routes("recalbox", "Recalbox")
lines = guidepage._setup_routes("recalbox", "Recalbox")
routes = "\n".join(lines[:lines.index("## On the device { #install }")])
for label in ("Windows", "macOS", "Linux"):
self.assertIn(f'label="{label}"', routes)
# The setup page sends a Mac or Linux reader to those tabs.
lines = generate_site._setup_routes("recalbox", "Recalbox", page_link=True)
lines = guidepage._setup_routes("recalbox", "Recalbox", page_link=True)
self.assertIn("[Mac or Linux](../get/recalbox.md#from-your-computer)", lines)
def test_the_network_route_needs_a_share_and_no_zip(self):
for name in SETUPS:
share = generate_site._network_share(name, guides.GUIDES[name])
share = guidepage._network_share(name, guides.GUIDES[name])
with self.subTest(setup=name):
if _with_zip(name) or guides.GUIDES[name].run != ("device",):
self.assertEqual(share, "")
@@ -752,7 +761,7 @@ class EveryHandheldRowSaysWhere(unittest.TestCase):
folder = row.rstrip(" |").rsplit(" | ", 1)[-1]
with self.subTest(row=row[:40]):
self.assertTrue("([source](https://" in folder
or folder == generate_site.RETROARCH_FOLDER_SETTING, folder)
or folder == guidepage.RETROARCH_FOLDER_SETTING, folder)
def test_the_installer_folders_are_written_with_their_source(self):
systems = {s.name: s for s in HANDHELDS.systems}
@@ -767,7 +776,7 @@ class EveryHandheldRowSaysWhere(unittest.TestCase):
row = next(line for line in text.splitlines()
if line.startswith((f"| {system.name} |", f"| {system.name}, ")))
with self.subTest(system=system.name):
self.assertEqual(generate_site.LINUX_ONLY_HINT in row, system.linux_only)
self.assertEqual(guidepage.LINUX_ONLY_HINT in row, system.linux_only)
self.assertTrue(any(s.linux_only for s in HANDHELDS.systems if s.name == "ArchR"))
self.assertNotIn("Windows and macOS cannot open", text)
@@ -845,7 +854,7 @@ class WhatItAsks(unittest.TestCase):
# line menu showed keys a beginner never sees (owner's note).
text = _plain_page("which-pack.md")
self.assertNotIn('title="What it asks"', text)
for line in generate_site.first_screen_words():
for line in guidepage.first_screen_words():
self.assertIn(line, text)
@@ -889,7 +898,7 @@ class GetPagesGiveTheSetupsOwnRoutes(unittest.TestCase):
guide = guides.GUIDES[name]
allowed = {labels[key] for key in guide.run}
allowed |= {labels[key] for key in guide.card_run or ("windows", "macos", "linux")}
if generate_site._network_share(name, guide):
if guidepage._network_share(name, guide):
# The network folder is reached from any computer.
allowed |= {labels[key] for key in ("windows", "macos", "linux")}
with self.subTest(setup=name):
@@ -913,17 +922,17 @@ class GetPagesGiveTheSetupsOwnRoutes(unittest.TestCase):
class CheckNeedsTheFiles(unittest.TestCase):
def test_the_pass_line_is_what_the_installer_prints_only_when_complete(self):
installer = (REPO_ROOT / "install.py").read_text(encoding="utf-8")
printed = re.search(r"`([^`]+)`", generate_site.check_pass_line())[1]
self.assertEqual(printed, generate_site._installer().EVERYTHING_IN_PLACE)
printed = re.search(r"`([^`]+)`", guidepage.check_pass_line())[1]
self.assertEqual(printed, sitegen_install._installer().EVERYTHING_IN_PLACE)
self.assertIn('print(f"\\n {EVERYTHING_IN_PLACE}")', installer)
self.assertNotIn("wrong hash", generate_site.check_pass_line())
self.assertNotIn("wrong hash", guidepage.check_pass_line())
def test_no_setup_page_passes_an_empty_folder(self):
for name in SETUPS:
text = _plain_page(f"platforms/{name}.md")
with self.subTest(setup=name):
self.assertNotIn("All good when you see `0 wrong hash`", text)
self.assertIn(generate_site.check_pass_line(), text)
self.assertIn(guidepage.check_pass_line(), text)
class ARouteWithoutANetwork(unittest.TestCase):
@@ -1001,7 +1010,7 @@ class GetPagesSayWhatTheyHold(unittest.TestCase):
lists = profile.is_file() and (yaml.safe_load(profile.read_text(encoding="utf-8")) or {}).get("files")
title = f"BIOS {kind} for {display}" if lists else f"{display} BIOS {kind}"
with self.subTest(setup=name):
self.assertEqual(generate_site.get_page_title(name, display), title)
self.assertEqual(guidepage.get_page_title(name, display), title)
self.assertIn(f"title: {title}\n", text)
self.assertNotIn("Download ", text.split("\n---\n", 1)[0].split("title:", 1)[1]
.split("\n", 1)[0])
@@ -1015,7 +1024,7 @@ class GetPagesSayWhatTheyHold(unittest.TestCase):
if REGISTRY[name].get("release_pack") is True:
continue
with self.subTest(setup=name):
title = generate_site.get_page_title(name, _display(name))
title = guidepage.get_page_title(name, _display(name))
self.assertIn(f"Link to share: [{title}](/retrobios/get/{name}/)",
_plain_page(f"platforms/{name}.md"))
@@ -1035,7 +1044,7 @@ class HandheldRowsSayWhere(unittest.TestCase):
self.assertRegex(system.folder_source, r"/wiki/Home/[0-9a-f]{40}$")
row = next(line for line in _plain_page("platforms/linux-handhelds.md").splitlines()
if line.startswith("| RetroOZ |"))
self.assertNotIn(generate_site.RETROARCH_FOLDER_SETTING, row)
self.assertNotIn(guidepage.RETROARCH_FOLDER_SETTING, row)
class GetIndex(unittest.TestCase):
@@ -1071,9 +1080,9 @@ class TheSiteSaysWhatTheInstallerShows(unittest.TestCase):
"c) choose systems, cores and regions")
def test_which_pack_describes_the_screen_in_the_installers_words(self):
installer = generate_site._installer()
installer = sitegen_install._installer()
text = _plain_page("which-pack.md")
for line in generate_site.first_screen_words():
for line in guidepage.first_screen_words():
self.assertIn(line, text)
self.assertIn(f"**{installer.TUI_INSTALL_ROW}**", text)
self.assertIn(f"**{installer.TUI_SYSTEMS_ROW}**", text)
@@ -1082,7 +1091,7 @@ class TheSiteSaysWhatTheInstallerShows(unittest.TestCase):
self.assertNotIn("press **c**", text)
def test_the_plan_rows_are_the_words_the_pages_use(self):
installer = generate_site._installer()
installer = sitegen_install._installer()
state = installer.TuiState(os_type="linux", home=Path("/home/me"))
state.stack = ["plan"]
state.check = {"files": 2, "present": 0, "missing": 2, "wrong_hash": 0, "need": 2,
@@ -1098,7 +1107,7 @@ class TheSiteSaysWhatTheInstallerShows(unittest.TestCase):
self.assertIn(installer.TUI_SYSTEMS_ROW, labels)
def test_the_readme_and_the_wiki_take_the_same_words(self):
installer = generate_site._installer()
installer = sitegen_install._installer()
readme = (REPO_ROOT / "README.md").read_text(encoding="utf-8")
self.assertIn(f"fewer under **{installer.TUI_SYSTEMS_ROW}**", readme)
self.assertNotIn("offers to install everything or to choose systems", readme)
+25 -23
View File
@@ -19,7 +19,9 @@ from pathlib import Path
import yaml
import generate_site as gs
from sitegen import cards
from sitegen import emulatorpage
from sitegen import provenance
from sitegen import entries as siteentries
from sitegen import validate
@@ -45,7 +47,7 @@ class TheEntryTable(unittest.TestCase):
for i in range(count)]
def test_a_long_table_has_its_filter_box_and_stacks(self):
lines = siteentries.entry_table(self._rows(25), gs.ENTRY_HEADS, "rb-entry-filter-x", "Required")
lines = siteentries.entry_table(self._rows(25), emulatorpage.ENTRY_HEADS, "rb-entry-filter-x", "Required")
text = "\n".join(lines)
self.assertRegex(text, r'<div class="rb-table-filter" hidden data-pagefind-ignore>'
r'<label for="rb-entry-filter-x">Filter Required</label> '
@@ -61,7 +63,7 @@ class TheEntryTable(unittest.TestCase):
self.assertNotIn("data-label", text)
def test_a_card_opens_under_its_name_as_markdown(self):
lines = siteentries.entry_table(self._rows(2), gs.ENTRY_HEADS, "x", "Required")
lines = siteentries.entry_table(self._rows(2), emulatorpage.ENTRY_HEADS, "x", "Required")
at = lines.index('<summary><h3 id="file-0" class="rb-file-title">n0</h3></summary>')
# A blank line after the summary: the body is read as Markdown.
self.assertEqual(lines[at + 1:at + 4], ["", "- Size: 0 bytes", ""])
@@ -85,19 +87,19 @@ class TheEntryTable(unittest.TestCase):
class ASplitEmulatorListsItsCardsAsRows(unittest.TestCase):
def setUp(self):
self.files = [_archive(i, members=1 + i % 4) for i in range(gs.EMULATOR_CARDS_PER_PAGE * 2)]
self.pages = gs.emulator_pages(
self.files = [_archive(i, members=1 + i % 4) for i in range(emulatorpage.EMULATOR_CARDS_PER_PAGE * 2)]
self.pages = emulatorpage.emulator_pages(
"big", {"emulator": "Big", "type": "standalone", "files": self.files}, EMPTY_DB)
def test_parts_hold_at_most_a_part_of_cards(self):
parts = gs.emulator_parts("big", self.files)
self.assertEqual(len(parts), -(-len(self.files) // gs.EMULATOR_CARDS_PER_PART))
self.assertLessEqual(max(len(entries) for _, entries in parts), gs.EMULATOR_CARDS_PER_PART)
parts = emulatorpage.emulator_parts("big", self.files)
self.assertEqual(len(parts), -(-len(self.files) // emulatorpage.EMULATOR_CARDS_PER_PART))
self.assertLessEqual(max(len(entries) for _, entries in parts), emulatorpage.EMULATOR_CARDS_PER_PART)
def test_every_name_and_member_hash_is_on_its_part(self):
parts = {stem: page for stem, page in self.pages.items() if stem != "big"}
anchors = gs.emulator_file_anchors(self.files)
for stem, entries in gs.emulator_parts("big", self.files):
anchors = cards.emulator_file_anchors(self.files)
for stem, entries in emulatorpage.emulator_parts("big", self.files):
page = parts[stem]
self.assertIn('<table class="rb-entries" data-rb-stack="true">', page)
self.assertNotIn('class="rb-file-entry"', page)
@@ -127,24 +129,24 @@ class APartIsCutByTheWordsItsRowsShow(unittest.TestCase):
systems = ["nintendo-nes", "sega-mega-drive", "sony-playstation"]
self.files = [_archive(i, members=1, system=systems[i % 3], region="japan",
md5=f"{i:032x}")
for i in range(gs.EMULATOR_CARDS_PER_PART * 2)]
for i in range(emulatorpage.EMULATOR_CARDS_PER_PART * 2)]
self.profile = {"emulator": "Wide", "type": "standalone", "systems": systems,
"files": self.files}
def test_rows_that_say_more_take_more_parts(self):
parts = gs.emulator_parts("wide", self.files, self.profile, lambda _f: False)
self.assertGreater(len(parts), -(-len(self.files) // gs.EMULATOR_CARDS_PER_PART))
words = gs._entry_row_words(self.files, self.profile, lambda _f: False)
parts = emulatorpage.emulator_parts("wide", self.files, self.profile, lambda _f: False)
self.assertGreater(len(parts), -(-len(self.files) // emulatorpage.EMULATOR_CARDS_PER_PART))
words = emulatorpage._entry_row_words(self.files, self.profile, lambda _f: False)
shown = [sum(words[i] for i in entries) for _stem, entries in parts]
self.assertLessEqual(max(shown), gs.EMULATOR_PART_WORDS)
self.assertLessEqual(max(shown), emulatorpage.EMULATOR_PART_WORDS)
# Balanced: no part a remainder of a few rows.
self.assertLess(max(shown) - min(shown), max(words) * 3)
self.assertEqual(sorted(i for _stem, entries in parts for i in entries),
list(range(len(self.files))))
def test_each_part_page_stays_under_the_built_ceiling(self):
pages = gs.emulator_pages("wide", self.profile, EMPTY_DB)
parts = gs.emulator_parts("wide", self.files, self.profile, lambda _f: False)
pages = emulatorpage.emulator_pages("wide", self.profile, EMPTY_DB)
parts = emulatorpage.emulator_parts("wide", self.files, self.profile, lambda _f: False)
self.assertEqual(sorted(pages), sorted(["wide", *(stem for stem, _e in parts)]))
ceiling = VISIBLE_CEILINGS["emulator card parts"][1]
for stem, _entries in parts:
@@ -154,15 +156,15 @@ class APartIsCutByTheWordsItsRowsShow(unittest.TestCase):
self.assertLessEqual(parser.words, ceiling)
def test_the_budget_leaves_room_for_the_frame(self):
self.assertLessEqual(gs.EMULATOR_PART_WORDS + 200,
self.assertLessEqual(emulatorpage.EMULATOR_PART_WORDS + 200,
VISIBLE_CEILINGS["emulator card parts"][1])
class ALongEmulatorPageIsOneTable(unittest.TestCase):
def test_rows_replace_the_index_and_the_cards(self):
files = ([_archive(i) for i in range(gs.EMULATOR_TABLE_MIN)]
files = ([_archive(i) for i in range(emulatorpage.EMULATOR_TABLE_MIN)]
+ [{"name": f"opt{i}.bin", "md5": f"{i:032x}"} for i in range(10)])
page = gs.generate_emulator_page(
page = emulatorpage.generate_emulator_page(
"long", {"emulator": "Long", "type": "standalone", "files": files}, EMPTY_DB, None, set())
self.assertNotIn("| File |", page)
self.assertNotIn('class="rb-file-entry"', page)
@@ -175,8 +177,8 @@ class ALongEmulatorPageIsOneTable(unittest.TestCase):
self.assertRegex(optional, rf'MD5: <code class="rb-hash"[^>]*>{md5}</code>')
def test_a_shorter_page_keeps_its_cards(self):
files = [_archive(i) for i in range(gs.EMULATOR_TABLE_MIN - 1)]
page = gs.generate_emulator_page(
files = [_archive(i) for i in range(emulatorpage.EMULATOR_TABLE_MIN - 1)]
page = emulatorpage.generate_emulator_page(
"short", {"emulator": "Short", "type": "standalone", "files": files}, EMPTY_DB, None, set())
self.assertIn('class="rb-file-entry"', page)
self.assertNotIn('class="rb-entries"', page)
@@ -195,7 +197,7 @@ class TheWantedListIsOneFilteredTable(unittest.TestCase):
{"name": "made.bin", "sha1": "a" * 40, "dat": dats[0]}],
}}
moved: dict[str, str] = {}
self.main = gs.generate_provenance_page(
self.main = provenance.generate_provenance_page(
{"files": {}}, report, {"a" * 40: {"from": ["bios/x.bin"], "transform": "half"}}, moved)
self.page = moved["provenance-redump"]
+85 -83
View File
@@ -15,14 +15,11 @@ from pathlib import Path
import yaml
from generate_site import (
_admonition_body,
_browser_title,
_forge_sources,
_source_ref_markdown,
decorate_markdown_pages,
generate_data_exports,
)
from generate_site import _admonition_body, _source_ref_markdown
from sitegen.sources import _forge_sources
from sitegen.descriptions import _browser_title
from sitegen.decorate import decorate_markdown_pages
from sitegen.dataexports import generate_data_exports
ROOT = Path(__file__).resolve().parent.parent
@@ -187,10 +184,10 @@ class SiteReferenceContracts(unittest.TestCase):
def test_browser_titles_distinguish_emulators_from_system_pages(self):
from unittest import mock
import generate_site
from sitegen import descriptions
pages = {"systems/qemu.md": {}, "emulators/qemu.md": {"hasPart": [{"name": "a"}]}}
with mock.patch.dict(generate_site.PAGE_DATA, pages, clear=True):
with mock.patch.dict(descriptions.PAGE_DATA, pages, clear=True):
self.assertEqual(_browser_title(Path("emulators/qemu.md"), "QEMU"),
"QEMU emulator BIOS files")
self.assertEqual(_browser_title(Path("systems/qemu.md"), "QEMU"), "QEMU BIOS files")
@@ -307,7 +304,7 @@ class AnEmulatorPageNamesItsRevision(unittest.TestCase):
refers to sat in the YAML alone, for 178 profiles."""
def test_each_repository_links_its_pinned_commit(self):
import generate_site
from sitegen import emulatorpage
profile = {
"emulator": "Caprice32", "type": "libretro",
@@ -316,7 +313,7 @@ class AnEmulatorPageNamesItsRevision(unittest.TestCase):
"source_commit": "c" * 40, "upstream_commit": "6" * 40,
"source_branch": "main", "systems": ["amstrad-cpc"], "files": [],
}
page = generate_site.generate_emulator_page("cap32", profile, {"files": {}})
page = emulatorpage.generate_emulator_page("cap32", profile, {"files": {}})
self.assertIn(
"| Revision | [libretro/libretro-cap32@cccccccccccc]"
"(https://github.com/libretro/libretro-cap32/commit/" + "c" * 40 + "), "
@@ -332,13 +329,13 @@ class APlatformPageSaysWhereEachFileGoes(unittest.TestCase):
goes to GC/USA, GC/EUR or GC/JAP."""
def test_same_named_files_show_their_destinations(self):
import generate_site
from sitegen import platformfiles
regions = ("USA", "EUR", "JAP")
declared = [{"name": "IPL.bin", "destination": f"dolphin-emu/Sys/GC/{r}/IPL.bin",
"sha1": str(i) * 40} for i, r in enumerate(regions)]
files = [{"name": "IPL.bin", "status": "ok"} for _ in regions]
lines = generate_site._render_platform_systems(
lines = platformfiles._render_platform_systems(
{"nintendo-gamecube": files}, {("nintendo-gamecube", "IPL.bin"): declared}, {})
for region in regions:
# The folder: the name is before it in the row.
@@ -354,7 +351,7 @@ class AVariantShowsWhoPinsIt(unittest.TestCase):
def test_the_variant_card_names_its_readers(self):
import types
import generate_site
from sitegen import systempages
primary = {"name": "advision.zip", "path": "bios/Entex/Adventure Vision/advision.zip",
"sha1": "a" * 40, "md5": "b" * 32, "size": 3000}
@@ -364,7 +361,7 @@ class AVariantShowsWhoPinsIt(unittest.TestCase):
"provenance": {"tosec": {"name": "x"}}}
consumers = types.SimpleNamespace(
platforms={"c" * 40: {"batocera", "retrobat"}}, emulators={"a" * 40: {"mame"}})
page = generate_site.generate_system_page(
page = systempages.generate_system_page(
"Entex", {"Adventure Vision": [primary, variant]}, consumers)
# Another revision of a set sits open beside it.
block = page[page.index('id="sha1-' + "c" * 12 + '"'):]
@@ -382,7 +379,7 @@ class AFlaggedDumpIsNotVerified(unittest.TestCase):
attribute, outside the search and invisible on a touch screen."""
def test_flags_and_name(self):
from generate_site import _provenance_lines
from sitegen.cards import _provenance_lines
lines = _provenance_lines({
"tosec": {"name": "Sony PlayStation BIOS (v2.2)(Sony)(JP)[b].bin"},
@@ -397,7 +394,7 @@ class AFlaggedDumpIsNotVerified(unittest.TestCase):
self.assertIn("SCPH-5000 BIOS v2.2", redump)
def test_an_alternate_is_not_a_flag(self):
from generate_site import _dump_flags
from sitegen.cards import _dump_flags
self.assertEqual(_dump_flags("tosec", {"name": "x (JP)[a].bin"}), [])
self.assertEqual(_dump_flags("tosec", {"name": "x [o][b].bin"}), ["overdump", "bad dump"])
@@ -410,7 +407,7 @@ class EmulatorPagesPrintWholeHashes(unittest.TestCase):
whole found nothing."""
def test_full_and_split(self):
from generate_site import _hash_spans
from sitegen.fields import _hash_spans
sha1 = "0c3de403b524107809fa9308b730d60e8e41ba93"
self.assertIn(f">{sha1}</code>", _hash_spans(sha1))
@@ -427,7 +424,7 @@ class TheGapsSayWhatToSupplyAndWhere(unittest.TestCase):
the emulator page only, and Data.rsdk's three rows looked identical."""
def test_export_rows(self):
from generate_site import _gap_export_rows
from sitegen.dataexports import _gap_export_rows
report = {"bstone": {"emulator": "BStone", "systems": ["blake-stone"], "gap_details": [
{"name": "EANIM.BS6", "path": "AOG/EANIM.BS6", "source": "missing",
@@ -443,13 +440,13 @@ class AGoneSourceIsSaid(unittest.TestCase):
owned by someone else, and the page said nothing."""
def test_the_status_row(self):
import generate_site
from sitegen import emulatorpage
profile = {"emulator": "Citron", "type": "standalone", "systems": [],
"source": "https://git.citron-emu.org/citron-emu/Citron",
"upstream_gone": "git.citron-emu.org no longer resolves. Observed 2026-09-04.",
"source_mirror": "https://example.org/mirror/Citron", "files": []}
page = generate_site.generate_emulator_page(
page = emulatorpage.generate_emulator_page(
"citron", profile, {"files": {}, "indexes": {}}, {})
self.assertIn("| Source status | gone: git.citron-emu.org no longer resolves", page)
self.assertIn("| Mirror | [https://example.org/mirror/Citron]", page)
@@ -463,7 +460,7 @@ class ASystemCardLandsOnThePlatformsSection(unittest.TestCase):
def test_section_and_destination(self):
import types
from generate_site import _platform_links
from sitegen.cards import _platform_links
consumers = types.SimpleNamespace(
platforms={"s": {"retrodeck"}},
@@ -483,7 +480,7 @@ class ArchiveMembersAreAcceptedHashes(unittest.TestCase):
calls the one to ask."""
def test_member_rows(self):
from generate_site import _accepted_hash_rows
from sitegen.dataexports import _accepted_hash_rows
item = {"id": "fbalpha2019", "profile": {"files": [
{"name": "nmk004.zip", "system": "arcade",
@@ -501,7 +498,7 @@ class PlatformPagesCarryTheirDeclarations(unittest.TestCase):
5,640 md5 and 2,047 sha1 the platforms declare lived in the prose only."""
def test_parts_and_version(self):
from generate_site import platform_structured_data
from sitegen.structured import platform_structured_data
data = platform_structured_data("batocera", {"platform": "Batocera", "config": {
"version": "43.1", "systems": {"sony-playstation": {"files": [
@@ -513,7 +510,7 @@ class PlatformPagesCarryTheirDeclarations(unittest.TestCase):
def test_a_declared_sha256_is_published(self):
"""RetroDECK's dsifirmware.bin sha256 lived in the CSV exports only."""
from generate_site import platform_structured_data
from sitegen.structured import platform_structured_data
data = platform_structured_data("retrodeck", {"platform": "RetroDECK", "config": {
"systems": {"nds": {"files": [
@@ -527,9 +524,9 @@ class AnEmulatorPageLinksItsProfile(unittest.TestCase):
guessing its path or filtering the 5.9 MB emulators.json."""
def test_links(self):
import generate_site
from sitegen import emulatorpage
page = generate_site.generate_emulator_page(
page = emulatorpage.generate_emulator_page(
"raze", {"emulator": "Raze", "type": "standalone", "systems": [], "files": []},
{"files": {}, "indexes": {}}, {})
self.assertIn("/blob/main/emulators/raze.yml", page)
@@ -540,7 +537,7 @@ class AVersionPerBuildReadsAsVersions(unittest.TestCase):
"""MesenCE's page showed {'standalone': '2.2.1', 'libretro': '2.0.0'}."""
def test_each_build_is_named(self):
from generate_site import generate_emulator_page
from sitegen.emulatorpage import generate_emulator_page
page = generate_emulator_page(
"mesence",
@@ -558,7 +555,8 @@ class EmulatorPartsCarryTheirIdentity(unittest.TestCase):
no part the url of its card."""
def test_identifiers_members_and_url(self):
from generate_site import emulator_file_anchors, emulator_structured_data
from sitegen.cards import emulator_file_anchors
from sitegen.structured import emulator_structured_data
files = [
{"name": "BS-X.bin", "sha256": "aa,bb"},
@@ -582,15 +580,15 @@ class OnlyAPinnedProfileClaimsAPin(unittest.TestCase):
def test_the_description_follows_the_pin(self):
from unittest import mock
import generate_site
from sitegen import descriptions
pages = {
"emulators/pinned.md": {"about": {"version": "a" * 40}},
"emulators/redream.md": {},
}
with mock.patch.dict(generate_site.PAGE_DATA, pages, clear=True):
pinned = generate_site._page_description("", Path("emulators/pinned.md"), "P")
loose = generate_site._page_description("", Path("emulators/redream.md"), "R")
with mock.patch.dict(descriptions.PAGE_DATA, pages, clear=True):
pinned = descriptions._page_description("", Path("emulators/pinned.md"), "P")
loose = descriptions._page_description("", Path("emulators/redream.md"), "R")
# A search snippet is level 0: the pin is on the page, not in it.
self.assertNotIn("source-pinned", pinned)
self.assertNotIn("source-pinned", loose)
@@ -601,7 +599,7 @@ class ADataDirectorySaysWhatItIs(unittest.TestCase):
@mock.patch("sitegen.sources.tree_holds", lambda *_args: True) # a path the record confirms
def test_description_origin_mode_and_source(self):
from generate_site import generate_emulator_page
from sitegen.emulatorpage import generate_emulator_page
profile = {
"emulator": "Cemu", "type": "standalone + libretro", "systems": [],
@@ -625,13 +623,13 @@ class APlatformPageNamesTheFileItTranscribes(unittest.TestCase):
batocera-systems revision every md5 on it comes from."""
def test_pinned_and_moving_sources(self):
import generate_site
from sitegen import platformpage
def page(source: str) -> str:
cov = {"platform": "P", "config": {"source": source, "systems": {}},
"details": [], "total": 0, "verified": 0, "present": 0,
"missing": 0, "untested": 0, "mode": "md5"}
return generate_site.generate_platform_page("p", cov)
return platformpage.generate_platform_page("p", cov)
tag = "https://raw.githubusercontent.com/o/r/batocera-43.1/x/batocera-systems"
self.assertIn(
@@ -677,7 +675,7 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
and 335 of its 337 zipped_file entries were unreachable that way."""
import json as _json
import generate_site
from sitegen import lookup
from model.platforms import load_platform_config
from packs.crossref import FileConsumers
from core.ziptools import build_zip_contents_index
@@ -697,7 +695,7 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
if archive is None:
self.skipTest("no copy of naomi2.zip holding the pinned ROM")
coverages = {"batocera": {"config": {"systems": {"sega-naomi2": {"files": [entry]}}}}}
records = generate_site.file_lookup_records(db, coverages, {}, [], None, consumers)
records = lookup.file_lookup_records(db, coverages, {}, [], None, consumers)
found = {(r["owner"], r["value"]) for r in records if r["layer"] == "platform"}
self.assertIn(("batocera", archive), found)
pinned = next(r for r in records if r["layer"] == "platform" and r["algorithm"] == "md5")
@@ -710,7 +708,7 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
import tempfile
import zlib
import generate_site
from sitegen import lookup
body = b"approved inis\n"
sha1 = hashlib.sha1(body).hexdigest()
@@ -723,13 +721,13 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
members = {"dolphin-sys": {"ApprovedInis.json": {"sha1": sha1},
"Stale.json": {"sha1": "ef" * 20}}}
registry = {"dolphin-sys": {"local_cache": "data/dolphin-sys"}}
digests = generate_site._data_member_digests(members, registry, Path(tmp))
digests = lookup._data_member_digests(members, registry, Path(tmp))
self.assertEqual(digests, {sha1: {
"sha1": sha1, "md5": hashlib.md5(body).hexdigest(),
"sha256": hashlib.sha256(body).hexdigest(),
"crc32": f"{zlib.crc32(body):08x}"}})
with mock.patch.object(generate_site, "_data_member_digests", return_value=digests):
records = generate_site.file_lookup_records(
with mock.patch.object(lookup, "_data_member_digests", return_value=digests):
records = lookup.file_lookup_records(
{"files": {}}, {}, {}, [{"sha1": sha1, "url": "u"}],
{"dolphin-sys": {"ApprovedInis.json": {"sha1": sha1}}})
self.assertEqual({r["algorithm"]: r["value"] for r in records}, digests[sha1])
@@ -738,7 +736,7 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
import json as _json
import tempfile
import generate_site
from sitegen import lookup
sha1 = "ab" * 20
md5 = "490f666e1afb15b7362b406ed1cea246"
@@ -754,10 +752,10 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
{"name": "m.rom", "crc32": "11223344"}]}]},
"an-alias": {"type": "alias", "files": [{"name": "x", "md5": md5}]},
}
locations = generate_site.file_location_items(db) + [
locations = lookup.file_location_items(db) + [
{"sha1": "cd" * 20, "url": "emulators/dolphin/#sha1-" + "cd" * 6}]
members = {"dolphin-sys": {"Sys/GC/font.bin": {"sha1": "cd" * 20}}}
records = generate_site.file_lookup_records(db, coverages, profiles, locations, members)
records = lookup.file_lookup_records(db, coverages, profiles, locations, members)
found = {(r["layer"], r.get("owner", ""), r["algorithm"], r["value"]): r for r in records}
self.assertEqual(found[("collection", "", "md5", md5)]["url"],
"/retrobios/systems/sony/#sha1-" + "ab" * 6)
@@ -772,7 +770,7 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
self.assertNotIn(("emulator", "an-alias", "md5", md5), found)
with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as tmp:
shards = generate_site.write_lookup_shards(Path(tmp), records, "2026-01-01T00:00:00Z")
shards = lookup.write_lookup_shards(Path(tmp), records, "2026-01-01T00:00:00Z")
folder = Path(tmp) / "lookup"
names = sorted(path.name for path in folder.glob("*.json"))
self.assertEqual(len(names), shards)
@@ -794,7 +792,7 @@ class AnArchiveMemberIsFoundByItsCrc(unittest.TestCase):
def test_each_member_is_a_record_leading_to_its_archive(self):
import zipfile
import generate_site
from sitegen import lookup
with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as tmp:
root = Path(tmp)
@@ -804,8 +802,8 @@ class AnArchiveMemberIsFoundByItsCrc(unittest.TestCase):
handle.writestr("logica2.u2", b"rom")
handle.writestr("sub/kick.rom", b"kick")
entry = {"name": "a500.zip", "path": "bios/Arcade/Arcade/a500.zip"}
records = generate_site._archive_member_records(entry, "ab" * 20, "/retrobios/x/", root)
plain = generate_site._archive_member_records(
records = lookup._archive_member_records(entry, "ab" * 20, "/retrobios/x/", root)
plain = lookup._archive_member_records(
{"name": "a.bin", "path": "bios/a.bin"}, "cd" * 20, "/retrobios/y/", root)
self.assertEqual(plain, [])
import zlib
@@ -838,12 +836,12 @@ class AWantedDumpIsFoundByItsHash(unittest.TestCase):
the site knows has it."""
def test_each_hash_of_a_wanted_row_is_a_record(self):
import generate_site
from sitegen import lookup
row = {"catalog": "redump", "dat": "Sony - PlayStation 2 - BIOS Images",
"name": "ps2-dvd-212k.bin", "description": "", "size": "4194304",
"crc32": "1A2B3C4D", "md5": "", "sha1": "5b346eb9258d710609a9855befd35cab8f3a334a"}
records = generate_site.file_lookup_records(
records = lookup.file_lookup_records(
{"files": {}, "indexes": {}}, {}, {}, [], wanted=[row, {**row, "dat": "other"}])
self.assertEqual(records, [
{"value": "1a2b3c4d", "algorithm": "crc32", "layer": "wanted", "owner": "Redump",
@@ -875,14 +873,14 @@ class AMovedPartCardReachesItsPage(unittest.TestCase):
def test_a_part_page_sends_a_missing_card_to_the_emulator_page(self):
import re as _re
import generate_site
from sitegen import emulatorpage
script = (Path(__file__).resolve().parents[1] / "website" / "src" / "scripts"
/ "site.ts").read_text(encoding="utf-8")
body = script.split("const followMovedCard = () => {", 1)[1].split("\n};", 1)[0]
pattern = _re.search(r"const part = /(.+?)/\.exec\(location\.pathname\)", body).group(1)
files = [{"name": f"f{i}.bin", "path": f"f{i}.bin", "required": True} for i in range(600)]
stem = generate_site.emulator_parts("mame", files)[1][0]
stem = emulatorpage.emulator_parts("mame", files)[1][0]
found = _re.search(pattern.replace("\\/", "/"), f"/retrobios/emulators/{stem}/")
self.assertEqual(found.group(1), "mame")
self.assertIn("emulators/${part[1]}/#", body)
@@ -897,24 +895,25 @@ class AFileHasAnAddressByContent(unittest.TestCase):
was not."""
def test_index_page_and_resolver(self):
import generate_site
from sitegen import cards
from sitegen import lookup
db = {"files": {
"ab" * 20: {"path": "bios/Roland/mt32-roms/mt32_control.rom"},
"cd" * 20: {"path": "data/elsewhere.bin"},
}}
self.assertEqual(
generate_site.file_location_items(db),
lookup.file_location_items(db),
[{"sha1": "ab" * 20, "url": "/retrobios/systems/roland/#sha1-" + "ab" * 6}],
)
self.assertIn('id="rb-file-lookup-status"', generate_site.generate_files_page())
self.assertIn('id="rb-file-lookup-status"', lookup.generate_files_page())
script = (Path(__file__).resolve().parents[1] / "website" / "src" / "scripts"
/ "site.ts").read_text()
self.assertIn("api/v1/lookup/", script)
self.assertIn("params.has('sha1')", script)
from packs.crossref import FileConsumers
card = "\n".join(generate_site._system_file_card(
card = "\n".join(cards._system_file_card(
{"name": "x.rom", "sha1": "ab" * 20, "size": 1}, FileConsumers({"files": {}}),
))
self.assertIn("/retrobios/files/?sha1=" + "ab" * 20, card)
@@ -929,7 +928,7 @@ class ACardNamesThePacksThatInstallIt(unittest.TestCase):
import json as _json
from packs.crossref import FileConsumers
from generate_site import _installed_places
from sitegen.cards import _installed_places
with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp:
Path(tmp, "retrobat.json").write_text(_json.dumps({
@@ -1029,7 +1028,7 @@ class EveryAcceptedHashIsItsOwnWord(unittest.TestCase):
search made one token of it and found none but the first."""
def test_a_list_is_split(self):
from generate_site import _hash_spans
from sitegen.fields import _hash_spans
md5s = ["96cf" + "0" * 28, "d5af" + "0" * 28]
text = _hash_spans(",".join(md5s))
@@ -1042,7 +1041,7 @@ class AMismatchNamesTheDumpTheCollectionHolds(unittest.TestCase):
the collection held that exact dump for every row."""
def test_the_held_copy_is_named(self):
from generate_site import _held_accepted
from sitegen.gaps import _held_accepted
db = {"files": {"s1": {"path": "bios/Microsoft/MSX/CLK/msx-japanese.rom"}},
"indexes": {"by_sha256": {"ab" * 32: "s1"}, "by_crc32": {"84f68bf9": "s1"}}}
@@ -1061,7 +1060,7 @@ class ADataDirectoryFileCanBeLookedUp(unittest.TestCase):
def test_a_member_resolves_to_its_emulator_page(self):
import json as _json
from generate_site import data_directory_members, file_location_items
from sitegen.lookup import data_directory_members, file_location_items
with tempfile.TemporaryDirectory(dir=ROOT / "tmp") as tmp:
Path(tmp, "retroarch.json").write_text(_json.dumps({"data_directories": [
@@ -1079,7 +1078,7 @@ class ACardSaysWhyAFileIsLeftOut(unittest.TestCase):
could not tell why a RetroArch pack carried PPSSPP's assets."""
def test_the_build_and_the_platforms_are_named(self):
from generate_site import _file_badges
from sitegen.emulatorcards import _file_badges
badges = " ".join(_file_badges({"name": "a", "bundled": True, "mode": "standalone"}, True))
self.assertIn("installed with the standalone emulator", badges)
@@ -1090,7 +1089,7 @@ class AnEmulatorPageOffersItsInstall(unittest.TestCase):
install them together."""
def test_the_command_names_the_emulator(self):
from generate_site import _install_block
from sitegen.install import _install_block
profile = yaml.safe_load((ROOT / "emulators" / "pcem.yml").read_text(encoding="utf-8"))
text = "\n".join(_install_block("pcem", profile))
@@ -1130,9 +1129,9 @@ class NestedProfileBlocksRenderAsLists(unittest.TestCase):
self.assertIn("<code>a.c:1</code>", html)
def test_platform_details_are_a_list(self):
import generate_site
from sitegen import fields
lines = generate_site._render_platform_details(
lines = fields._render_platform_details(
{"platform_details": {"megacd": {"root": "x"}, "note": "y"}}
)
try:
@@ -1157,33 +1156,34 @@ class TheOneLinerIsWhereUsersLand(unittest.TestCase):
options, and the platform and system pages offered only ZIP parts."""
def test_download_page(self):
import generate_site
from sitegen import whichpack
page = generate_site.generate_which_pack()
page = whichpack.generate_which_pack()
self.assertIn("Android (Termux", page)
self.assertIn("/i.ps1))) --check", page)
self.assertIn("--platform retroarch --dest", page)
def test_platform_and_system_pages(self):
import generate_site
from sitegen import platformpage
from sitegen import systempages
from packs.crossref import FileConsumers
cov = {"platform": "Batocera", "mode": "md5", "present": 0, "total": 0,
"verified": 0, "missing": 0, "details": [], "config": {"systems": {}}}
page = generate_site.generate_platform_page("batocera", cov)
page = platformpage.generate_platform_page("batocera", cov)
self.assertIn("/i | sh -s -- --platform batocera", page)
# Batocera runs the command on the device itself, so its page opens on
# the computer route. A platform detected on Windows gets the
# PowerShell form, and its command comes before the ZIP.
cov = dict(cov, platform="RetroArch", mode="existence")
page = generate_site.generate_platform_page("retroarch", cov)
page = platformpage.generate_platform_page("retroarch", cov)
self.assertIn("/i.ps1))) --platform retroarch", page)
self.assertIn("/i | sh -s -- --platform retroarch", page)
self.assertLess(page.index("--platform retroarch"), page.index("rb-button"))
entry = {"name": "a.bin", "sha1": "a" * 40, "md5": "b" * 32, "size": 3,
"path": "bios/Recalbox/MSX/a.bin"}
page = generate_site.generate_system_page(
page = systempages.generate_system_page(
"Microsoft", {"MSX": [entry]}, FileConsumers({"files": {}}),
{"MSX": [("recalbox", "msx1,msx2,msxturbor"), ("batocera", "msx1")]})
# The whole system id, up to the end of the command.
@@ -1191,7 +1191,7 @@ class TheOneLinerIsWhereUsersLand(unittest.TestCase):
self.assertIn("--platform batocera --system msx1", page)
def test_a_system_is_offered_only_where_the_manifest_records_it(self):
import generate_site
from sitegen import cards
from sitegen import render as siterender
saved = dict(siterender._system_page_map)
@@ -1199,7 +1199,7 @@ class TheOneLinerIsWhereUsersLand(unittest.TestCase):
siterender.set_system_page_map({"sony-playstation": ("sony", "PlayStation"),
"nowhere": ("sony", "PlayStation")})
cov = {"retroarch": {"config": {"systems": {"sony-playstation": {}, "nowhere": {}}}}}
choices = generate_site.system_install_choices(cov)
choices = cards.system_install_choices(cov)
self.assertEqual(choices["sony"]["PlayStation"], [("retroarch", "sony-playstation")])
@@ -1208,9 +1208,9 @@ class TheGapPageOpensOnCounts(unittest.TestCase):
for 5,437 of 5,438 files and "Missing 0", above a table of red cells."""
def test_every_count_is_said(self):
import generate_site
from sitegen import gaps
text = generate_site._platform_lists_sentence(5438, 5437, 1, 0)
text = gaps._platform_lists_sentence(5438, 5437, 1, 0)
self.assertIn("Of the 5,438 files", text)
self.assertIn("5,437 are held", text)
self.assertIn("1 is held but not verified", text)
@@ -1229,9 +1229,9 @@ class WhichPackDescribesNoPlatformByOpinion(unittest.TestCase):
def test_no_ranking_words(self):
import re
import generate_site
from sitegen import whichpack
page = generate_site.generate_which_pack()
page = whichpack.generate_which_pack()
rows = [line for line in page.splitlines() if line.startswith("| ")]
found = [
row for row in rows
@@ -1248,26 +1248,28 @@ class EveryPageLinksItsOwnData(unittest.TestCase):
it. A system page linked nothing either."""
def test_platform_and_system_documents(self):
import generate_site
from sitegen import dataexports
from sitegen import platformpage
from sitegen import systempages
from packs.crossref import FileConsumers
cov = {"platform": "Batocera", "mode": "md5", "present": 0, "total": 0,
"verified": 0, "missing": 0, "details": [], "config": {"systems": {}}}
page = generate_site.generate_platform_page("batocera", cov)
page = platformpage.generate_platform_page("batocera", cov)
self.assertIn("[JSON](../api/v1/platforms/batocera.json)", page)
self.assertIn("/blob/main/platforms/batocera.yml)", page)
entry = {"name": "a.bin", "sha1": "a" * 40, "md5": "b" * 32, "size": 3,
"path": "bios/Sony/PlayStation/a.bin"}
page = generate_site.generate_system_page(
page = systempages.generate_system_page(
"Sony", {"PlayStation": [entry]}, FileConsumers({"files": {}}))
self.assertIn(" as JSON](../api/v1/systems/sony.json)", page)
item = generate_site.system_export_item("sony", "Sony", {"PlayStation": [entry]})
item = dataexports.system_export_item("sony", "Sony", {"PlayStation": [entry]})
self.assertEqual(item["consoles"]["PlayStation"][0]["sha1"], "a" * 40)
with tempfile.TemporaryDirectory(dir=Path(__file__).resolve().parents[1] / "tmp") as tmp:
path = Path(tmp) / "sony.json"
generate_site.write_single_item(path, "systems", item, "2026-10-21T00:00:00Z")
dataexports.write_single_item(path, "systems", item, "2026-10-21T00:00:00Z")
document = json.loads(path.read_text())
self.assertEqual(document["count"], 1)
try:
+20 -17
View File
@@ -15,7 +15,10 @@ import tempfile
import unittest
from pathlib import Path
import generate_site
from sitegen import decorate
from sitegen import guidepage
from sitegen import nav as sitegen_nav
from sitegen import whichpack
from tests import sitepages
from model.registry import list_registered_platforms, load_platform_registry
from model.platforms import load_platform_config
@@ -24,7 +27,7 @@ from model.guides import DEVICE_GROUPS, GROUP_ANCHORS, GUIDES
REPO_ROOT = Path(__file__).resolve().parent.parent
DOCS = sitepages.CONTENT
ORDER = list(generate_site.LEVELS)
ORDER = list(decorate.LEVELS)
# Pages link to site addresses once written for the site.
LINK = re.compile(r"\[[^\]]*\]\((/retrobios/[^)\s#?]*)(?:[#?][^)]*)?\)")
FENCED = re.compile(r"^\s*```.*?^\s*```", re.S | re.M)
@@ -36,7 +39,7 @@ def _registered() -> list[str]:
def _which_pack() -> str:
with contextlib.chdir(REPO_ROOT):
return generate_site.generate_which_pack()
return whichpack.generate_which_pack()
def _docs_pages() -> list[Path]:
@@ -44,21 +47,21 @@ def _docs_pages() -> list[Path]:
def _level(page: Path) -> str:
return str(generate_site._front_matter(page.read_text(encoding="utf-8")).get("level") or "")
return str(decorate._front_matter(page.read_text(encoding="utf-8")).get("level") or "")
class FiveTabs(unittest.TestCase):
"""Twelve tabs put the walkthrough at position eleven, under "Wiki"."""
def test_the_tabs_in_reading_order(self):
nav = generate_site.generate_nav({}, {}, {}, {})
nav = sitegen_nav.generate_nav({}, {}, {}, {})
self.assertEqual(
[next(iter(tab)) for tab in nav],
["Start here", "Setups", "Explore", "Reference", "Contribute"],
)
def test_each_tab_opens_on_an_index_or_a_first_page(self):
nav = generate_site.generate_nav({}, {}, {}, {})
nav = sitegen_nav.generate_nav({}, {}, {}, {})
tabs = {next(iter(tab)): next(iter(tab.values())) for tab in nav}
self.assertEqual(tabs["Start here"][0], "index.md")
self.assertEqual(tabs["Setups"][0], "platforms/index.md")
@@ -107,7 +110,7 @@ class EveryPlatformOnThePicker(unittest.TestCase):
found += targets(value) if isinstance(value, list) else [value]
return found
nav = " ".join(targets(generate_site.generate_nav({}, {}, {}, {})))
nav = " ".join(targets(sitegen_nav.generate_nav({}, {}, {}, {})))
kept_out: set[str] = set()
wiki = Path(__file__).resolve().parents[1] / "wiki"
missing = sorted(
@@ -122,7 +125,7 @@ class EveryPlatformOnThePicker(unittest.TestCase):
key: {"platform": load_platform_config(key, str(REPO_ROOT / "platforms"))["platform"]}
for key in _registered()
}
nav = generate_site.generate_nav(coverages, {}, {}, registry)
nav = sitegen_nav.generate_nav(coverages, {}, {}, registry)
setup = next(tab["Setups"] for tab in nav if "Setups" in tab)
groups = {next(iter(item)): next(iter(item.values()))
for item in setup if isinstance(item, dict)}
@@ -136,7 +139,7 @@ class EveryPlatformOnThePicker(unittest.TestCase):
installer and were named on no page a user reads."""
from model.guides import HANDHELD_GUIDE
page = generate_site.generate_handheld_guide(HANDHELD_GUIDE)
page = guidepage.generate_handheld_guide(HANDHELD_GUIDE)
self.assertIn("| muOS |", page)
self.assertIn("`MUOS/bios` on the card", page)
self.assertNotIn("| TrimUI |", page)
@@ -153,7 +156,7 @@ class SampleCoresLeaveTheNavigation(unittest.TestCase):
"systems": ["sony-playstation"], "files": [{"name": "a.bin"}]},
"zx": {"emulator": "zx81", "type": "libretro", "systems": ["sinclair-zx81"]},
}
nav = generate_site._emulator_nav(profiles)
nav = sitegen_nav._emulator_nav(profiles)
self.assertEqual(nav[0], "emulators/index.md")
groups = {next(iter(group)): next(iter(group.values())) for group in nav[1:]}
self.assertEqual(groups, {
@@ -165,20 +168,20 @@ class SampleCoresLeaveTheNavigation(unittest.TestCase):
class EveryPageHasALevel(unittest.TestCase):
def test_wiki_sources_declare_one(self):
for page in sorted((REPO_ROOT / "wiki").glob("*.md")):
level = generate_site._front_matter(page.read_text(encoding="utf-8")).get("level")
level = decorate._front_matter(page.read_text(encoding="utf-8")).get("level")
with self.subTest(page=page.name):
self.assertIn(level, generate_site.LEVELS)
self.assertIn(level, decorate.LEVELS)
def test_every_generated_page_has_one_and_its_label(self):
for page in _docs_pages():
text = page.read_text(encoding="utf-8")
level = _level(page)
with self.subTest(page=str(page.relative_to(DOCS))):
self.assertIn(level, generate_site.LEVELS)
self.assertIn(level, decorate.LEVELS)
self.assertIn(f"\nlevel: {level}\n", text)
# The label above each title comes from the page's level.
component = (REPO_ROOT / "website" / "src" / "components" / "PageTitle.astro").read_text()
for level, label in generate_site.LEVELS.items():
for level, label in decorate.LEVELS.items():
with self.subTest(level=level):
self.assertIn(f"{level}: '{label}'", component)
@@ -187,8 +190,8 @@ class EveryPageHasALevel(unittest.TestCase):
page = Path(tmp) / "wiki" / "faq.md"
page.parent.mkdir()
page.write_text("---\nlevel: start\n---\n\n# FAQ\n\nQuestions people ask first.\n")
generate_site.decorate_markdown_pages(Path(tmp))
generate_site.decorate_markdown_pages(Path(tmp))
decorate.decorate_markdown_pages(Path(tmp))
decorate.decorate_markdown_pages(Path(tmp))
text = page.read_text()
self.assertEqual(text.count("level: start"), 1)
self.assertIn("searchWeight: 10\n", text)
@@ -239,7 +242,7 @@ class DeepLinksCarryALabel(unittest.TestCase):
continue
if any(f"]({answer})" in match.group(0) for answer in self.ANSWERS):
continue
label = f"{generate_site.LEVELS[deeper]}:"
label = f"{decorate.LEVELS[deeper]}:"
if line[: match.start()].rstrip().endswith("?"):
continue
if label not in line[: match.start()] and not any(
+6 -4
View File
@@ -31,10 +31,10 @@ PLATFORMS = str(REPO_ROOT / "platforms")
def _pages() -> dict[str, str]:
"""Every page that carries a launcher, by site path."""
import generate_site
from sitegen import getpages
with contextlib.chdir(REPO_ROOT):
pages = {f"get/{key}.md": generate_site.generate_get_page(key)
pages = {f"get/{key}.md": getpages.generate_get_page(key)
for key in sorted(set(sitehandheld.PLATFORM_OF.values()))}
pages[f"get/{sitehandheld.GROUP_PAGE}.md"] = sitehandheld.group_page(REPO_ROOT)
return pages
@@ -104,13 +104,15 @@ class WhereEachSystemFindsItsFile(unittest.TestCase):
"""It shares the guide's name, so the sidebar files it with it, and
the guide a muOS or ArkOS owner lands on links it."""
import generate_site
from sitegen import getpages
from sitegen import guidepage
guide = generate_site.HANDHELD_GUIDE
self.assertEqual(sitehandheld.GROUP_PAGE, guide.page)
with contextlib.chdir(REPO_ROOT):
self.assertIn(f"(../get/{sitehandheld.GROUP_PAGE}.md)",
generate_site.generate_handheld_guide(guide))
self.assertIn(f"]({sitehandheld.GROUP_PAGE}.md)", generate_site.generate_get_index())
guidepage.generate_handheld_guide(guide))
self.assertIn(f"]({sitehandheld.GROUP_PAGE}.md)", getpages.generate_get_index())
def test_every_system_has_its_launchers_on_its_page(self):
pages = _pages()
+11 -7
View File
@@ -20,6 +20,10 @@ import unittest
from pathlib import Path
import generate_site
from sitegen import decorate
from sitegen import guidepage
from sitegen import install
from sitegen import platformfiles
from sitegen import diagrams
from model import siteinputs
@@ -43,12 +47,12 @@ class TheGivenDatabase(_Inputs):
def test_a_card_held_elsewhere_resolves_in_the_given_collection(self) -> None:
self.use(db=self.db)
page = generate_site._cards_elsewhere("[x](#sha1-0123456789ab) ")
page = decorate._cards_elsewhere("[x](#sha1-0123456789ab) ")
self.assertIn(f"files/?sha1={SHA1}", page)
def test_paths_are_read_from_the_given_collection(self) -> None:
self.use(db=self.db)
self.assertEqual(generate_site._collection_sha1_by_path(), {"bios/X/only-here.bin": SHA1})
self.assertEqual(platformfiles._collection_sha1_by_path(), {"bios/X/only-here.bin": SHA1})
class TheGivenProfilesAndPlatforms(_Inputs):
@@ -65,23 +69,23 @@ class TheGivenProfilesAndPlatforms(_Inputs):
def test_emulator_names_come_from_the_given_profiles(self) -> None:
self.use(emulators=self.emulators)
self.assertEqual(set(generate_site._profiles_on_disk()), {"fixturecore"})
self.assertEqual(generate_site._emulator_named_link("fixturecore"),
self.assertEqual(platformfiles._emulator_named_link("fixturecore"),
"[Fixture Core](emulators/fixturecore.md)")
def test_release_pack_does_not_depend_on_the_working_directory(self) -> None:
released = generate_site._release_pack_platforms()
released = install._release_pack_platforms()
self.assertIn("retroarch", released)
here = os.getcwd()
os.chdir(REPO_ROOT / "scripts")
self.addCleanup(os.chdir, here)
self.assertTrue(generate_site.has_release_pack("retroarch"))
self.assertEqual(generate_site.get_page_title("retroarch", "RetroArch"), "RetroArch BIOS pack")
self.assertTrue(install.has_release_pack("retroarch"))
self.assertEqual(guidepage.get_page_title("retroarch", "RetroArch"), "RetroArch BIOS pack")
def test_the_registry_comes_from_the_given_platforms(self) -> None:
registry = self.platforms / "_registry.yml"
registry.write_text(registry.read_text().replace("release_pack: true", "release_pack: false"))
self.use(platforms=self.platforms)
self.assertFalse(generate_site.has_release_pack("retroarch"))
self.assertFalse(install.has_release_pack("retroarch"))
self.assertEqual(diagrams.registry()["retroarch"].get("release_pack"), False)
+11 -9
View File
@@ -22,7 +22,9 @@ from unittest import mock
import yaml
import check_freshness
import generate_site as gs
from sitegen import emulatorcards
from sitegen import emulatorpage
from sitegen import startwith
from sitegen import diagrams
from model import collection
@@ -38,12 +40,12 @@ def _profile(name: str) -> dict:
class DataTreeReaders(unittest.TestCase):
def test_read_by_names_the_emulators(self):
ref = "y-sys"
gs._DATA_MEMBERS[ref] = {"a.bin": {"size": 1, "sha1": "0" * 40}}
gs._DATA_READERS[ref] = [("dolphin", "Dolphin"), ("ishiiruka", "Ishiiruka")]
emulatorcards._DATA_MEMBERS[ref] = {"a.bin": {"size": 1, "sha1": "0" * 40}}
emulatorpage._DATA_READERS[ref] = [("dolphin", "Dolphin"), ("ishiiruka", "Ishiiruka")]
try:
page = gs._data_tree_page(ref, {}, [("y-sys", ["a.bin"])], 0)
page = emulatorpage._data_tree_page(ref, {}, [("y-sys", ["a.bin"])], 0)
finally:
del gs._DATA_MEMBERS[ref], gs._DATA_READERS[ref]
del emulatorcards._DATA_MEMBERS[ref], emulatorpage._DATA_READERS[ref]
self.assertIn("Read by [Dolphin](dolphin.md#data-directories) and "
"[Ishiiruka](ishiiruka.md#data-directories).", page)
self.assertNotIn("('dolphin'", page)
@@ -57,16 +59,16 @@ class EngineIntros(unittest.TestCase):
continue
name = Path(path).stem
with self.subTest(profile=name):
intro = gs._emulator_intro(str(profile.get("emulator") or name), profile)
intro = emulatorpage._emulator_intro(str(profile.get("emulator") or name), profile)
self.assertNotRegex(intro, r"emulates\s*(?:\.|game\b|and\b|,)")
self.assertNotIn(" ", intro)
class SectionNames(unittest.TestCase):
def test_fba2012_is_headed_by_its_program(self):
self.assertEqual(gs._section_label("Arcade", "fba2012"), "FB Alpha 2012")
self.assertEqual(gs._section_label("Arcade", "Arcade"), gs.OTHER_ARCADE_LABEL)
self.assertEqual(gs._section_label("Sony", "PlayStation"), "PlayStation")
self.assertEqual(startwith._section_label("Arcade", "fba2012"), "FB Alpha 2012")
self.assertEqual(startwith._section_label("Arcade", "Arcade"), startwith.OTHER_ARCADE_LABEL)
self.assertEqual(startwith._section_label("Sony", "PlayStation"), "PlayStation")
self.assertEqual(collection.SECTION_LABELS[("Arcade", "fba2012")],
_profile("fbalpha2012")["emulator"])
+19 -15
View File
@@ -34,6 +34,10 @@ import ast
from html import unescape
import generate_site
from sitegen import decorate
from sitegen import emulatorsindex
from sitegen import nav as sitegen_nav
from sitegen import parts
from sitegen import starlight as sitestarlight
from core import anchors as core_anchors
from model.registry import list_registered_platforms, load_platform_registry
@@ -60,7 +64,7 @@ def _nav() -> list:
"dolphin": {"emulator": "Dolphin", "systems": ["nintendo-gamecube"]},
"mame": {"emulator": "MAME", "systems": ["arcade"]},
}
return generate_site.generate_nav(coverages, manufacturers, profiles, registry)
return sitegen_nav.generate_nav(coverages, manufacturers, profiles, registry)
def _targets(value: object) -> set[str]:
if isinstance(value, str):
return {value}
@@ -80,7 +84,7 @@ def _index_anchors(markdown: str) -> set[str]:
ANCHORS = {
"platforms/index.md": {core_anchors.toc_slug(label) for label, _ in DEVICE_GROUPS.values()},
"systems/index.md": {"consoles-and-computers"},
"emulators/index.md": _index_anchors(generate_site.generate_emulators_index({
"emulators/index.md": _index_anchors(emulatorsindex.generate_emulators_index({
"duckstation": {"emulator": "DuckStation", "systems": ["sony-playstation"]},
"dolphin": {"emulator": "Dolphin", "systems": ["nintendo-gamecube"]},
"mame": {"emulator": "MAME", "systems": ["arcade"]},
@@ -107,7 +111,7 @@ class NotFoundPage(unittest.TestCase):
terms={},
),
)
front = generate_site._front_matter(text)
front = decorate._front_matter(text)
self.assertIs(front["tableOfContents"], False)
self.assertIs(front["prev"], False)
self.assertIs(front["next"], False)
@@ -158,7 +162,7 @@ class GroupsAreGroups(unittest.TestCase):
class EmulatorsOneLevelDeep(unittest.TestCase):
def test_initials_hold_pages_not_groups(self):
nav = generate_site._emulator_nav({
nav = sitegen_nav._emulator_nav({
"duckstation": {"emulator": "DuckStation", "systems": ["s"]},
"dolphin": {"emulator": "Dolphin", "systems": ["s"]},
})
@@ -170,8 +174,8 @@ class EmulatorsOneLevelDeep(unittest.TestCase):
from model.profiles import load_emulator_profiles
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
anchors = _index_anchors(generate_site.generate_emulators_index(profiles))
for group in generate_site._emulator_nav(profiles)[1:]:
anchors = _index_anchors(emulatorsindex.generate_emulators_index(profiles))
for group in sitegen_nav._emulator_nav(profiles)[1:]:
(label, _pages), = group.items()
with self.subTest(initial=label):
self.assertIn(core_anchors.toc_slug(label), anchors)
@@ -179,7 +183,7 @@ class EmulatorsOneLevelDeep(unittest.TestCase):
def test_every_initial_holds_pages(self):
from model.profiles import load_emulator_profiles
nav = generate_site._emulator_nav(load_emulator_profiles(str(REPO_ROOT / "emulators")))
nav = sitegen_nav._emulator_nav(load_emulator_profiles(str(REPO_ROOT / "emulators")))
for group in nav[1:]:
(label, pages), = group.items()
with self.subTest(initial=label):
@@ -217,7 +221,7 @@ class OneNextPerPage(unittest.TestCase):
def test_card_pages_turn_pagination_off(self):
for rel in ("systems/sony.md", "emulators/duckstation.md", "platforms/batocera.md"):
_target, text = sitestarlight.render_page(rel, "# T\n\nBody.\n", sitestarlight.PageMeta(level="explore", weight=None, browser_title="T", description="d", structured={}, terms={}))
front = generate_site._front_matter(text)
front = decorate._front_matter(text)
with self.subTest(page=rel):
self.assertIs(front["prev"], False)
self.assertIs(front["next"], False)
@@ -226,17 +230,17 @@ class OneNextPerPage(unittest.TestCase):
body = ("# Troubleshooting\n\nText.\n\n## Next steps\n\n"
"- [Common questions](faq.md)\n- [Glossary](glossary.md)\n")
_target, text = sitestarlight.render_page("wiki/troubleshooting.md", body, sitestarlight.PageMeta(level="start", weight=None, browser_title="Troubleshooting", description="d", structured={}, terms={}))
front = generate_site._front_matter(text)
front = decorate._front_matter(text)
self.assertEqual(front["next"], {"link": "/retrobios/wiki/faq/", "label": "Common questions"})
def test_a_page_without_next_steps_keeps_the_reading_order(self):
_target, text = sitestarlight.render_page("wiki/faq.md", "# FAQ\n\nText.\n", sitestarlight.PageMeta(level="start", weight=None, browser_title="FAQ", description="d", structured={}, terms={}))
self.assertNotIn("next", generate_site._front_matter(text))
self.assertNotIn("next", decorate._front_matter(text))
class ReferenceGrouped(unittest.TestCase):
def _reference(self, wiki: Path | None = None) -> list:
nav = generate_site.generate_nav({}, {}, {}, {}, wiki)
nav = sitegen_nav.generate_nav({}, {}, {}, {}, wiki)
return next(tab["Reference"] for tab in nav if "Reference" in tab)
def test_checking_files_opens_on_find_a_file(self):
@@ -304,13 +308,13 @@ class Redirects(unittest.TestCase):
(docs / "gaps-files-to-source-7.md").write_text(part, encoding="utf-8")
(docs / "gaps.md").write_text("# Gaps\n", encoding="utf-8")
kept = {"platforms/b-atari-st.md": "platforms/b.md#atari-st"}
published = generate_site.record_parts(
published = parts.record_parts(
docs, {"gaps-files-to-source-7.md", "gaps.md"}, kept)
self.assertEqual(published, {"gaps-files-to-source-7.md": "gaps.md", **kept})
# An emulator part names its parent with the site's base.
self.assertEqual(generate_site._parent_page("/retrobios/emulators/amiberry/"),
self.assertEqual(parts._parent_page("/retrobios/emulators/amiberry/"),
"emulators/amiberry.md")
self.assertEqual(generate_site._parent_page("/platforms/b/#atari-st"),
self.assertEqual(parts._parent_page("/platforms/b/#atari-st"),
"platforms/b.md#atari-st")
# The next run made six parts.
self.assertEqual(
@@ -573,7 +577,7 @@ class MovedPlatformPages(unittest.TestCase):
class ArcadeGroup(unittest.TestCase):
def test_arcade_is_not_a_console_or_computer(self) -> None:
nav = generate_site._system_nav({"Sony": {}, "Arcade": {}, "Sega": {}})
nav = sitegen_nav._system_nav({"Sony": {}, "Arcade": {}, "Sega": {}})
groups = {next(iter(entry)): entry[next(iter(entry))] for entry in nav if isinstance(entry, dict)}
self.assertEqual(groups["Arcade"], [{"Arcade": "systems/arcade.md"}])
self.assertNotIn({"Arcade": "systems/arcade.md"}, groups["Consoles and computers"])
+17 -14
View File
@@ -19,6 +19,9 @@ from html.parser import HTMLParser
from pathlib import Path
import generate_site
from sitegen import cards
from sitegen import platformfiles
from sitegen import platformpage
REPO_ROOT = Path(__file__).resolve().parents[1]
@@ -87,7 +90,7 @@ class VisibleWordsAreCounted(unittest.TestCase):
class ARowPerFile(unittest.TestCase):
def _row(self, f: dict, entry: dict, hash_type: str = "md5") -> str:
return generate_site._platform_file_row(f, entry, hash_type)
return platformfiles._platform_file_row(f, entry, hash_type)
def test_the_row_at_a_glance(self):
md5, sha1 = "a" * 32, "b" * 40
@@ -102,7 +105,7 @@ class ARowPerFile(unittest.TestCase):
details, button = row.split("</details>")
self.assertNotIn("<button", details)
self.assertEqual(button, f'<button class="rb-copy" data-copy="{md5}" '
f'aria-label="Copy MD5 {md5[:generate_site.SHORT_HASH]}">{md5[:generate_site.SHORT_HASH]}</button>')
f'aria-label="Copy MD5 {md5[:cards.SHORT_HASH]}">{md5[:cards.SHORT_HASH]}</button>')
# Every hash whole in the details, with the size.
for value in (md5, sha1, "0badf00d"):
self.assertIn(value, details)
@@ -117,10 +120,10 @@ class ARowPerFile(unittest.TestCase):
files = [{"name": "a.bin", "status": "ok"}, {"name": "b.bin", "status": "ok"}]
system = "nintendo-gamecube"
config = {(system, "a.bin"): [{"destination": "a.bin"}], (system, "b.bin"): [{}]}
text = "\n".join(generate_site._render_platform_systems({system: files}, config, {}))
text = "\n".join(platformfiles._render_platform_systems({system: files}, config, {}))
self.assertIn('<div class="rb-files">', text)
config[(system, "b.bin")] = [{"destination": "sub/b.bin"}]
text = "\n".join(generate_site._render_platform_systems({system: files}, config, {}))
text = "\n".join(platformfiles._render_platform_systems({system: files}, config, {}))
self.assertIn('<div class="rb-files rb-files-path">', text)
def test_status_words(self):
@@ -140,7 +143,7 @@ class ARowPerFile(unittest.TestCase):
values = ["1" * 32, "2" * 32, "3" * 32]
row = self._row({"name": "x", "status": "ok"}, {"md5": ",".join(values)})
self.assertIn(f'data-copy="{values[0]}"', row)
self.assertIn(f">{values[0][:generate_site.SHORT_HASH]} +2</button>", row)
self.assertIn(f">{values[0][:cards.SHORT_HASH]} +2</button>", row)
for value in values:
self.assertIn(f'<code class="rb-hash">{value}</code>', row)
@@ -149,12 +152,12 @@ class ARowPerFile(unittest.TestCase):
self.assertIn("&#42;a&#95;b&#42;&#91;1&#93;.bin", row)
def test_a_long_list_gets_a_filter(self):
rows = ["<details></details>"] * generate_site.FILTER_ROWS
block = generate_site._platform_file_list(rows, False, "arcade")
rows = ["<details></details>"] * platformfiles.FILTER_ROWS
block = platformfiles._platform_file_list(rows, False, "arcade")
self.assertTrue(block[0].startswith('<div class="rb-table-filter" hidden data-pagefind-ignore>'
'<label for="rb-files-filter-arcade">Filter files</label>'))
self.assertNotIn("rb-table-filter", "".join(
generate_site._platform_file_list(rows[1:], False, "arcade")))
platformfiles._platform_file_list(rows[1:], False, "arcade")))
class ReferencesNameTheirRoleOnce(unittest.TestCase):
@@ -163,11 +166,11 @@ class ReferencesNameTheirRoleOnce(unittest.TestCase):
REFS = "source libretro/libretro.c:1, source src/a.c:2, source src/b.c:3, upstream src/c.c:4"
def test_grouped_by_role(self):
text = generate_site._refs_by_role(self.PROFILE, self.REFS)
text = platformfiles._refs_by_role(self.PROFILE, self.REFS)
self.assertEqual(text, "glue `libretro/libretro.c:1` and port `src/a.c:2`, `src/b.c:3` "
"and upstream `src/c.c:4`")
for word in generate_site.ROLE_WORDS.values():
self.assertIn(f"**{word}**", generate_site.ROLE_LEGEND)
for word in platformfiles.ROLE_WORDS.values():
self.assertIn(f"**{word}**", platformfiles.ROLE_LEGEND)
def test_other_pages_keep_the_role_after_each_reference(self):
text = generate_site._source_ref_markdown(self.PROFILE, self.REFS)
@@ -194,7 +197,7 @@ class NothingIsLost(unittest.TestCase):
for name in ("batocera", "retroarch"):
cov = compute_coverage(name, str(REPO_ROOT / "platforms"), db)
moved: dict[str, str] = {}
page = generate_site.generate_platform_page(name, cov, {}, {}, moved)
page = platformpage.generate_platform_page(name, cov, {}, {}, moved)
cls.pages[name] = (cov, page, moved)
def test_every_fact_is_there(self):
@@ -218,7 +221,7 @@ class NothingIsLost(unittest.TestCase):
# cited, when a core of this system reads the file.
running = [reader for reader in readers if reader.get("runs_system")]
for reader in running or readers:
for url in re.findall(r"\]\((https://[^)]+)\)", generate_site._category_evidence_md(
for url in re.findall(r"\]\((https://[^)]+)\)", platformfiles._category_evidence_md(
{"read_by": [reader]})):
self.assertIn(url, text, (name, detail["name"], reader["emulator"]))
@@ -226,7 +229,7 @@ class NothingIsLost(unittest.TestCase):
for name, (_cov, page, moved) in self.pages.items():
for text in (page, *moved.values()):
self.assertNotIn("(emulator code, libretro port)", text, name)
self.assertEqual(text.count(generate_site.ROLE_LEGEND), 1, name)
self.assertEqual(text.count(platformfiles.ROLE_LEGEND), 1, name)
# Visible words (outside closed details) measured on the built site,
+4 -4
View File
@@ -14,7 +14,7 @@ import unittest
from unittest import mock
from model import systemnames
from generate_site import _render_platform_systems
from sitegen.platformfiles import _render_platform_systems
A, B, C = "a" * 32, "b" * 32, "c" * 32
@@ -51,7 +51,7 @@ class AnUntestedRowNamesBothHashes(unittest.TestCase):
nor the one the collection holds."""
def test_declared_and_held(self):
import generate_site as gs
from sitegen import gaps
path = "bios/Nintendo/Nintendo DS/dsifirmware.bin"
declared, held = "1" * 64, "2" * 64
@@ -61,10 +61,10 @@ class AnUntestedRowNamesBothHashes(unittest.TestCase):
problem = {
"platform": "RetroDECK", "name": "dsifirmware.bin", "status": "untested",
"required": True, "reason": "declared hash contradicted by the local file",
"declared": gs._declared_hashes(config, detail), "path": path,
"declared": gaps._declared_hashes(config, detail), "path": path,
}
db = {"files": {"f" * 40: {"path": path, "sha256": held}}}
table = "\n".join(gs._render_problem_files([problem], db=db))
table = "\n".join(gaps._render_problem_files([problem], db=db))
row = next(line for line in table.splitlines() if "dsifirmware" in line)
# Cut to 12 characters in the cell, the whole value in its title.
self.assertIn(f'sha256 <code title="{declared}">{declared[:12]}</code>', row)
+97 -84
View File
@@ -52,6 +52,19 @@ import runpy
import urllib.error
import generate_site
from sitegen import apiitems
from sitegen import config as sitegen_config
from sitegen import crossref
from sitegen import dataexports
from sitegen import datapage
from sitegen import gaps
from sitegen import lookup
from sitegen import parts as sitegen_parts
from sitegen import platformfiles
from sitegen import platformindex
from sitegen import platformpage
from sitegen import provenance
from sitegen import publish
from sitegen import wanted as sitewanted
from model import systemnames
from model.registry import list_registered_platforms, list_release_pack_platforms
@@ -156,7 +169,7 @@ class EvidenceLinksItsSource(unittest.TestCase):
"entries": [{"name": "scph1001.bin", "by": "name",
"source_ref": "source frontend/libretro.c:3864-3867 (listed_bios[6])"}],
}]}
text = generate_site._category_evidence_md(evidence)
text = platformfiles._category_evidence_md(evidence)
self.assertRegex(text, r"\[`frontend/libretro\.c:3864-3867`\]\(https://github\.com/"
r"libretro/pcsx_rearmed/blob/[0-9a-f]{40}/frontend/libretro\.c"
r"#L3864-L3867\)")
@@ -167,8 +180,8 @@ class EvidenceLinksItsSource(unittest.TestCase):
evidence = {"read_by": [{"emulator": "launcher", "proof": "launcher",
"entries": [], "runs_system": True}]}
config = load_platform_config("batocera", PLATFORMS)
launched = generate_site._launcher_refs(config)["scph1001.bin"]
text = generate_site._category_evidence_md(evidence, launched)
launched = platformfiles._launcher_refs(config)["scph1001.bin"]
text = platformfiles._category_evidence_md(evidence, launched)
self.assertNotIn("(by launcher)", text)
self.assertIn("https://github.com/batocera-linux/batocera.linux/blob/batocera-43.1/"
"package/batocera/core/batocera-configgen/", text)
@@ -186,7 +199,7 @@ class EvidenceLinksItsSource(unittest.TestCase):
if not config.get("launchers"):
continue
with self.subTest(platform=path.stem):
rendered = [text for texts in generate_site._launcher_refs(config).values()
rendered = [text for texts in platformfiles._launcher_refs(config).values()
for text in texts]
self.assertTrue(rendered)
self.assertFalse([t for t in rendered if " at `" in t])
@@ -203,28 +216,28 @@ class EvidenceLinksItsSource(unittest.TestCase):
class EachEntryNamesItsFile(unittest.TestCase):
def test_served_held_and_missing(self):
path, digest = next(
(p, d) for p, d in generate_site._collection_sha1_by_path().items()
(p, d) for p, d in platformfiles._collection_sha1_by_path().items()
if p.startswith("bios/") and p.count("/") >= 3)
served = generate_site._served_line({"status": "ok", "path": path})
served = platformfiles._served_line({"status": "ok", "path": path})
self.assertRegex(served, rf"\]\(\.\./systems/[^)]+\.md#sha1-{digest[:12]}\)")
self.assertTrue(served.startswith("Served by: "))
self.assertIn(f"`{digest[:8]}`", served)
# The row already shows the declared sha1: repeating it said nothing.
quiet = generate_site._served_line({"status": "ok", "path": path}, f"aaaa, {digest.upper()}")
quiet = platformfiles._served_line({"status": "ok", "path": path}, f"aaaa, {digest.upper()}")
self.assertNotIn(digest[:8], quiet.split(")", 1)[1])
self.assertIn(f"`{digest[:8]}`", generate_site._served_line(
self.assertIn(f"`{digest[:8]}`", platformfiles._served_line(
{"status": "ok", "path": path}, "a" * 40))
self.assertEqual(generate_site._served_line({"status": "missing"}), "Not held")
self.assertTrue(generate_site._served_line(
self.assertEqual(platformfiles._served_line({"status": "missing"}), "Not held")
self.assertTrue(platformfiles._served_line(
{"status": "untested", "path": path}).startswith("Held, not the declared hash"))
# Existence mode reports no path: nothing is claimed, held or not.
self.assertEqual(generate_site._served_line({"status": "ok"}), "")
self.assertEqual(platformfiles._served_line({"status": "ok"}), "")
def test_a_long_system_list_is_cut_between_rows_by_elements(self):
rows = [[f'<details class="rb-file"><summary>f{n}.bin</summary>x<br>y</details>']
for n in range(4)]
# Three elements a row: two rows fit in a budget of seven.
runs = generate_site._blocks_in_runs(rows, 7, generate_site._element_weight)
runs = sitegen_parts._blocks_in_runs(rows, 7, platformfiles._element_weight)
self.assertEqual([len(run) for run in runs], [2, 2])
self.assertEqual(sum(runs, []), sum(rows, []))
@@ -237,7 +250,7 @@ class AlsoNamedIsNotCited(unittest.TestCase):
{"emulator": "mame", "proof": "name", "runs_system": False,
"entries": [{"name": "x.zip", "source_ref": "src/mame/x.cpp:1", "by": "name"}]},
]}
text = generate_site._category_evidence_md(evidence)
text = platformfiles._category_evidence_md(evidence)
also = text.split(", also named by ", 1)[1]
self.assertNotIn("x.cpp", also)
self.assertIn("mame", also)
@@ -251,7 +264,7 @@ class PlatformReferenceInWords(unittest.TestCase):
"present": 1, "missing": 0, "untested": 0, "mode": mode,
"config": {"hash_type": hash_type, "systems": systems or {},
"source": "https://github.com/o/r/tree/" + "a" * 40}}
return generate_site.generate_platform_page("p", cov, registry or {})
return platformpage.generate_platform_page("p", cov, registry or {})
def test_hash_type_only_when_it_differs(self):
self.assertNotIn("Hash type", self._page("md5", "md5"))
@@ -273,10 +286,10 @@ class PlatformReferenceInWords(unittest.TestCase):
"config": {"hash_type": "md5", "hash_rule": "size_and_any_hash",
"systems": {"sony-playstation": {"files": [{"name": "f.bin"}]}},
"source": "https://github.com/o/r/tree/" + "a" * 40}}
page = generate_site.generate_platform_page("romm", cov, {})
page = platformpage.generate_platform_page("romm", cov, {})
self.assertIn(">size, then any hash</span>", page)
self.assertNotIn(">MD5</span>", page)
table = "\n".join(generate_site.setup_table({"romm": cov}))
table = "\n".join(platformindex.setup_table({"romm": cov}))
self.assertIn("| size, then any hash |", table)
def test_systems_by_name_with_the_id_in_small_text(self):
@@ -297,16 +310,16 @@ class PlatformReferenceInWords(unittest.TestCase):
class GapsPageNumbers(unittest.TestCase):
def test_badge_only_for_missing_required_firmware(self):
self.assertNotIn("rb-badge", generate_site._ratio_cell(99, 100))
self.assertIn('class="rb-bar"', generate_site._ratio_cell(99, 100))
self.assertIn("rb-badge-danger", generate_site._ratio_cell(99, 100, 1))
self.assertNotIn("rb-badge", gaps._ratio_cell(99, 100))
self.assertIn('class="rb-bar"', gaps._ratio_cell(99, 100))
self.assertIn("rb-badge-danger", gaps._ratio_cell(99, 100, 1))
cov = {"details": [
{"name": "a", "system": "s", "status": "missing", "required": True, "category": "bios"},
{"name": "b", "system": "s", "status": "missing", "required": True,
"category": "game_data"},
{"name": "c", "system": "s", "status": "missing", "required": False},
]}
self.assertEqual(generate_site._missing_required_firmware(cov), 1)
self.assertEqual(gaps._missing_required_firmware(cov), 1)
def test_headings_and_header(self):
source = Path(generate_site.__file__).read_text(encoding="utf-8")
@@ -320,17 +333,17 @@ class GapsPageNumbers(unittest.TestCase):
class UpstreamsGrouped(unittest.TestCase):
def test_mame_trees_are_one_project(self):
keys = {generate_site.upstream_project(u)[0] for u in (
keys = {crossref.upstream_project(u)[0] for u in (
"https://github.com/mamedev/mame",
"https://github.com/mamedev/mame/tree/mame0289",
"https://github.com/mamedev/mame/tree/mame0135u4",
)}
self.assertEqual(keys, {"github.com/mamedev/mame"})
self.assertEqual(generate_site.upstream_project(
self.assertEqual(crossref.upstream_project(
"https://github.com/mamedev/mame/tree/mame0289")[1], "mame0289")
def test_nested_groups_notes_and_archives(self):
project = generate_site.upstream_project
project = crossref.upstream_project
self.assertEqual(
project("https://gitlab.com/recalbox/packages/recalbox-cores/libretro-exel-hence"),
("gitlab.com/recalbox/packages/recalbox-cores/libretro-exel-hence", ""))
@@ -341,7 +354,7 @@ class UpstreamsGrouped(unittest.TestCase):
("git.9front.org/plan9front/plan9front", "sys/src/games/nes/"))
key, _ = project("https://archive.softwareheritage.org/browse/revision/"
"dc20a615275f66bee20a4fd851ef0231daca4f14/")
self.assertEqual(generate_site._upstream_label(key),
self.assertEqual(crossref._upstream_label(key),
"Software Heritage revision dc20a615275f")
def test_overview_and_a_page_per_platform(self):
@@ -351,7 +364,7 @@ class UpstreamsGrouped(unittest.TestCase):
config = load_platform_config(name, PLATFORMS)
coverages[name] = {"platform": config.get("platform", name), "config": config}
moved: dict[str, str] = {}
page = generate_site.generate_cross_reference(coverages, profiles, moved)
page = crossref.generate_cross_reference(coverages, profiles, moved)
self.assertEqual(set(moved), {"cross-reference-batocera", "cross-reference-retroarch"})
self.assertNotIn("<details", page)
upstream = page[page.index("## By upstream emulator"):]
@@ -362,18 +375,18 @@ class UpstreamsGrouped(unittest.TestCase):
class ExportsComplete(unittest.TestCase):
def test_gap_rows_once_with_their_outcome(self):
path = next(iter(generate_site._collection_sha1_by_path()))
path = next(iter(platformfiles._collection_sha1_by_path()))
detail = {"name": "x.bin", "system": "s", "status": "untested", "path": path,
"category": "bios"}
coverages = {"p": {"platform": "P", "details": [
{"name": "h.xml", "system": "s", "status": "missing"},
{"name": "h.xml", "system": "s", "status": "missing"}, detail]}}
db = json.loads((REPO_ROOT / "database.json").read_text(encoding="utf-8"))
rows = generate_site._gap_export_rows(coverages, {}, db)
rows = dataexports._gap_export_rows(coverages, {}, db)
self.assertEqual([r["name"] for r in rows], ["h.xml", "x.bin"])
held = rows[1]
self.assertEqual(held["collection_path"], path)
self.assertEqual(held["resolved_sha1"], generate_site._collection_sha1_by_path()[path])
self.assertEqual(held["resolved_sha1"], platformfiles._collection_sha1_by_path()[path])
self.assertEqual(held["category"], "bios")
def test_platform_rows_carry_status_and_file(self):
@@ -384,33 +397,33 @@ class ExportsComplete(unittest.TestCase):
{"name": "a.bin", "system": "s", "status": "ok", "path": entry["path"],
"category": "bios"},
{"name": "b.bin", "system": "s", "status": "missing", "category": "game_data"}]}}
_items, rows = generate_site._platform_export_rows(coverages, db)
_items, rows = dataexports._platform_export_rows(coverages, db)
self.assertEqual((rows[0]["status"], rows[0]["resolved_sha1"]), ("ok", sha1))
self.assertEqual(rows[0]["collection_path"], entry["path"])
self.assertEqual((rows[1]["status"], rows[1]["category"], rows[1]["collection_path"]),
("missing", "game_data", ""))
def test_commit_and_wanted_list(self):
commit = generate_site._source_commit()
commit = dataexports._source_commit()
self.assertRegex(commit, r"^[0-9a-f]{40}$")
schema = json.loads((REPO_ROOT / "schemas" / "site-api-envelope.schema.json")
.read_text(encoding="utf-8"))
self.assertIn("commit", schema["properties"])
db = json.loads((REPO_ROOT / "database.json").read_text(encoding="utf-8"))
rows = generate_site._provenance_wanted_rows(db)
rows = dataexports._provenance_wanted_rows(db)
self.assertTrue(rows)
self.assertTrue(all(r["catalog"] and r["name"] for r in rows))
text = generate_site._csv_document(list(generate_site.WANTED_FIELDS), rows)
self.assertEqual(next(csv.reader(io.StringIO(text))), list(generate_site.WANTED_FIELDS))
text = dataexports._csv_document(list(dataexports.WANTED_FIELDS), rows)
self.assertEqual(next(csv.reader(io.StringIO(text))), list(dataexports.WANTED_FIELDS))
class DatesAndNames(unittest.TestCase):
def test_snapshot_date_in_words(self):
self.assertEqual(generate_site._date_in_words("2026-08-07T10:00:00Z"),
self.assertEqual(provenance._date_in_words("2026-08-07T10:00:00Z"),
'<time datetime="2026-08-07">7 August 2026</time>')
def test_data_page_title(self):
self.assertIn("\n---\n\n# Data and API\n", generate_site.generate_data_page([]))
self.assertIn("\n---\n\n# Data and API\n", datapage.generate_data_page([]))
@unittest.skipUnless((DIST / "platforms" / "batocera" / "index.html").is_file(),
@@ -478,7 +491,7 @@ class TheExportsKeepWhatACheckNeeds(unittest.TestCase):
}}
def test_rows_carry_the_member_and_the_flags(self):
_items, rows = generate_site._platform_export_rows(self.COVERAGE)
_items, rows = dataexports._platform_export_rows(self.COVERAGE)
zipped, flagged = rows
self.assertEqual(zipped["zipped_file"], "basic1.rom")
self.assertIs(flagged["hash_match_mandatory"], True)
@@ -489,10 +502,10 @@ class TheExportsKeepWhatACheckNeeds(unittest.TestCase):
def test_the_csv_header_and_the_table_name_them(self):
source = Path(generate_site.__file__).read_text(encoding="utf-8")
self.assertIn('"collection_path", "resolved_sha1", *ENTRY_EXPORT_FIELDS,', source)
for field in generate_site.ENTRY_EXPORT_FIELDS:
for field in dataexports.ENTRY_EXPORT_FIELDS:
self.assertIn(f":{field}", source)
for field in ("zipped_file", "hash_match_mandatory", "mandatory_declared", "curated"):
self.assertIn(field, generate_site.ENTRY_EXPORT_FIELDS)
self.assertIn(field, dataexports.ENTRY_EXPORT_FIELDS)
def test_the_built_csv_has_the_column(self):
text = _built(PUBLIC / "downloads" / "platform-files.csv").read_text(encoding="utf-8")
@@ -504,7 +517,7 @@ class TheExportsKeepWhatACheckNeeds(unittest.TestCase):
"WHERE platform_id = 'batocera' AND zipped_file != ''").fetchone()[0]
license_row = db.execute("SELECT value FROM metadata WHERE key = 'license'").fetchone()
self.assertGreater(count, 300)
self.assertEqual(license_row[0], generate_site.DATA_LICENSE)
self.assertEqual(license_row[0], sitegen_config.DATA_LICENSE)
class AFolderCheckAgreesWithTheVerifier(unittest.TestCase):
@@ -592,7 +605,7 @@ class AFolderCheckAgreesWithTheVerifier(unittest.TestCase):
def test_the_data_page_shows_the_script_itself(self):
script = (REPO_ROOT / "scripts" / "check_platform_folder.py").read_text(encoding="utf-8")
page = generate_site.generate_data_page([])
page = datapage.generate_data_page([])
self.assertIn("```python\n" + script.rstrip("\n") + "\n```", page)
self.assertLess(len(script.splitlines()), 70)
self.assertIn("## Check a folder for one platform", page)
@@ -615,7 +628,7 @@ class TheContractsValidate(unittest.TestCase):
platforms = str(REPO_ROOT / "platforms")
for name in list_registered_platforms(platforms):
config = load_platform_config(name, platforms)
contract, registry = generate_site._split_contract(config)
contract, registry = dataexports._split_contract(config)
with self.subTest(platform=name):
errors = [error.message for error in validator.iter_errors(contract)]
self.assertEqual(errors, [])
@@ -684,7 +697,7 @@ class EveryEnvelopeCarriesTheCommit(unittest.TestCase):
def test_every_built_envelope_has_it(self):
_built(API / "catalog.json")
if not generate_site._source_commit():
if not dataexports._source_commit():
raise unittest.SkipTest("not a git checkout")
lacking = [
path.relative_to(API).as_posix() for path in sorted(API.rglob("*.json"))
@@ -707,10 +720,10 @@ class ManifestsArePublished(unittest.TestCase):
self.assertEqual(item["sha256"], hashlib.sha256(source.read_bytes()).hexdigest())
self.assertEqual(item["schema"], "schemas/install-manifest.schema.json")
self.assertIn("release.json", listed)
self.assertEqual(catalog["license"], generate_site.DATA_LICENSE)
self.assertEqual(catalog["license"], sitegen_config.DATA_LICENSE)
def test_the_data_page_explains_the_fields_from_the_schema(self):
page = generate_site.generate_data_page([])
page = datapage.generate_data_page([])
schema = json.loads((REPO_ROOT / "schemas" / "install-manifest.schema.json").read_text())
for field in ("dest", "repo_path", "release_asset", "cores"):
description = schema["$defs"]["file"]["properties"][field]["description"]
@@ -731,9 +744,9 @@ class TheLookupRecipeSaysWhatASha1Misses(unittest.TestCase):
def test_the_page_and_the_records_agree(self):
record = {"layer": "platform", "algorithm": "md5", "value": "0" * 32,
"name": "dmg_boot.bin", "owner": "recalbox"}
self.assertEqual(generate_site._held_under_every_hash([record], {}, {}), [])
self.assertEqual(lookup._held_under_every_hash([record], {}, {}), [])
self.assertNotIn("sha1", record)
page = " ".join(generate_site.generate_data_page([]).split())
page = " ".join(datapage.generate_data_page([]).split())
self.assertNotIn("none is needed", page)
self.assertIn("A list naming a file the collection lacks is filed under its MD5 "
"or CRC32 alone", page)
@@ -750,7 +763,7 @@ class AnIdLeadsToItsData(unittest.TestCase):
"mednafen_psx_alias": {"type": "alias", "alias_of": "beetle_psx"},
"probe": {"type": "libretro", "role": "test", "cores": ["probe_core"]},
}
items = generate_site.core_index_items(profiles)
items = apiitems.core_index_items(profiles)
by_name: dict[str, list[tuple[str, bool]]] = {}
for item in items:
by_name.setdefault(item["name"], []).append((item["profile"], item["preferred"]))
@@ -775,7 +788,7 @@ class LookupUrlsResolve(unittest.TestCase):
def test_site_absolute(self):
db = {"files": {"ab" * 20: {"path": "bios/Sony/PlayStation/scph5501.bin"}}}
[item] = generate_site.file_location_items(db)
[item] = lookup.file_location_items(db)
self.assertTrue(item["url"].startswith("/retrobios/systems/"), item["url"])
shard = SITE + "api/v1/lookup/ab.json"
self.assertTrue(urllib.parse.urljoin(shard, item["url"]).startswith(SITE + "systems/"))
@@ -791,8 +804,8 @@ class LookupUrlsResolve(unittest.TestCase):
"sony-playstation": {"files": [{"name": "scph5501.bin", "md5": "490f666e1afb15b7362b406ed1cea246"}]}}}}}
profiles = {"duckstation": {"systems": ["sony-playstation"], "files": [
{"name": "scph5501.bin", "md5": "490f666e1afb15b7362b406ed1cea246"}]}}
records = generate_site.file_lookup_records(
db, coverages, profiles, generate_site.file_location_items(db))
records = lookup.file_lookup_records(
db, coverages, profiles, lookup.file_location_items(db))
expected = system_name("sony-playstation")
by_layer = {r["layer"]: r for r in records if r["algorithm"] == "md5"}
for layer in ("collection", "platform", "emulator"):
@@ -819,7 +832,7 @@ class PlatformPagesLinkTheirSystemsAndEmulators(unittest.TestCase):
"""8.9: the overview named emulators as ids, none of 1,463 linked."""
def test_an_emulator_is_named_and_linked(self):
link = generate_site._emulator_named_link("beetle_psx", "../")
link = platformfiles._emulator_named_link("beetle_psx", "../")
self.assertRegex(link, r"^\[[^\]]+\]\(\.\./emulators/beetle_psx\.md\)$")
self.assertNotEqual(link, "[beetle_psx](../emulators/beetle_psx.md)")
@@ -833,7 +846,7 @@ class PlatformPagesLinkTheirSystemsAndEmulators(unittest.TestCase):
# Past PLATFORM_SECTION_BUDGET, so the list leaves for a page of its own.
files = [{"name": f"{'f' * 200}{i}.bin", "status": "ok"} for i in range(2000)]
moved: dict[str, str] = {}
generate_site._render_platform_systems(
platformfiles._render_platform_systems(
{"sony-playstation": files}, {}, {}, ("retroarch", "RetroArch"), moved, {})
self.assertTrue(moved)
page = next(iter(moved.values()))
@@ -843,7 +856,7 @@ class PlatformPagesLinkTheirSystemsAndEmulators(unittest.TestCase):
def test_part_pages_of_gaps_and_cross_reference_name_their_parent(self):
moved: dict[str, str] = {}
generate_site._list_pages("gaps-x", "T", "intro", [], [["| a |"]], moved,
sitegen_parts._list_pages("gaps-x", "T", "intro", [], [["| a |"]], moved,
parent=("What the packs do not hold", "/gaps/"))
self.assertIn('parent:\n label: "What the packs do not hold"\n link: "/gaps/"', moved["gaps-x"])
source = Path(generate_site.__file__).read_text(encoding="utf-8")
@@ -857,7 +870,7 @@ class TablesFitTheirColumn(unittest.TestCase):
def test_the_downloads_table(self):
item = {"title": "SQLite snapshot", "url": "downloads/retrobios.sqlite",
"media_type": "application/vnd.sqlite3", "bytes": 10, "sha256": "a" * 64}
page = generate_site.generate_data_page([item])
page = datapage.generate_data_page([item])
row = next(line for line in page.splitlines() if "SQLite snapshot" in line and "|" in line)
self.assertIn(f'<code title="{"a" * 64}">{"a" * 12}</code>', row)
self.assertNotIn("a" * 13, row.replace(f'title="{"a" * 64}"', ""))
@@ -865,7 +878,7 @@ class TablesFitTheirColumn(unittest.TestCase):
def test_the_gaps_tables(self):
problem = {"platform": "Batocera", "name": "x.bin", "status": "untested", "required": True,
"reason": "expected md5 differs", "declared": {"md5": ["b" * 32]}, "path": ""}
table = "\n".join(generate_site._render_problem_files([problem], db={"files": {}}))
table = "\n".join(gaps._render_problem_files([problem], db={"files": {}}))
row = next(line for line in table.splitlines() if "x.bin" in line)
self.assertIn(f'<code title="{"b" * 32}">{"b" * 12}</code>', row)
self.assertIn('<span class="rb-reason">expected md5 differs</span>', row)
@@ -965,10 +978,10 @@ class LookupRecordsUnderEveryHash(unittest.TestCase):
{"name": "bios.bin", "md5": "b" * 32}]}}}}}
profiles = {"core": {"type": "libretro", "systems": ["sony-playstation"],
"files": [{"name": "bios.bin", "crc32": "c" * 8}]}}
with mock.patch.object(generate_site, "_console_system_names", return_value={}), \
mock.patch.object(generate_site, "_lookup_system_name", return_value=None), \
with mock.patch.object(lookup, "_console_system_names", return_value={}), \
mock.patch.object(lookup, "_lookup_system_name", return_value=None), \
mock.patch.object(generate_site, "emulator_card_page", side_effect=lambda k, a: k):
return generate_site.file_lookup_records(
return lookup.file_lookup_records(
db, coverages, profiles, [{"sha1": self.SHA1, "url": "/x"}])
def test_each_hash_names_the_setup_and_the_emulator(self):
@@ -1042,7 +1055,7 @@ class TheFolderCheckReadsEmuDecksWhitelist(unittest.TestCase):
self.assertEqual(found, [("sony-playstation: any file", "missing")])
def test_the_data_page_states_the_rule(self):
page = generate_site.generate_data_page([])
page = datapage.generate_data_page([])
self.assertIn("An entry with no `destination` (EmuDeck) names no file", page)
self.assertLess(len((REPO_ROOT / "scripts" / "check_platform_folder.py")
.read_text().splitlines()), 70)
@@ -1054,15 +1067,15 @@ class ManifestFieldsAreComplete(unittest.TestCase):
SCHEMA = json.loads((REPO_ROOT / "schemas" / "install-manifest.schema.json").read_text())
def test_a_url_template_is_code(self):
rows = generate_site._schema_field_rows(self.SCHEMA["$defs"]["file"], ("repo_path",))
rows = datapage._schema_field_rows(self.SCHEMA["$defs"]["file"], ("repo_path",))
self.assertIn("`https://raw.githubusercontent.com/Abdess/retrobios/<ref>/<repo_path>`",
rows[0])
rows = generate_site._schema_field_rows(
rows = datapage._schema_field_rows(
{"properties": {"a": {"description": "From https://x.test/<asset>, then."}}}, ("a",))
self.assertEqual(rows, ["| `a` | From `https://x.test/<asset>`, then. |"])
def test_every_field_is_described_and_shown(self):
page = generate_site.generate_data_page([])
page = datapage.generate_data_page([])
for schema in (self.SCHEMA, self.SCHEMA["$defs"]["file"]):
for key, spec in schema["properties"].items():
self.assertTrue(spec.get("description"), key)
@@ -1085,10 +1098,10 @@ class EverySystemIdWithFilesHasAPage(unittest.TestCase):
def test_first_file_then_emulator(self):
files = {"f" * 40: {"path": "bios/DOS/DOS/a.bin"}}
with mock.patch("sitegen.render._card_pages", {}):
place = generate_site._first_file_place(
place = apiitems._first_file_place(
"dos", ["f" * 40], files, {}, lambda path, sha1: "dos")
self.assertEqual(place, ("DOS", "/retrobios/systems/dos/#sha1-ffffffffffff"))
place = generate_site._first_file_place(
place = apiitems._first_file_place(
"tyrian", [], files, {"opentyrian": {"systems": ["tyrian"]}}, None)
self.assertEqual(place, ("", "/retrobios/emulators/opentyrian/"))
@@ -1182,7 +1195,7 @@ class TheReferencePagesAnswerTheirWords(unittest.TestCase):
"""8.7, 8.8, 8.10 and 8.13."""
def test_find_or_check_a_file(self):
page = generate_site.generate_files_page()
page = lookup.generate_files_page()
self.assertTrue(page.startswith(
"---\nterms: check my dump, md5 check, verify bios file, check hash, "
"is my bios correct, is my bios right\n---\n"))
@@ -1190,7 +1203,7 @@ class TheReferencePagesAnswerTheirWords(unittest.TestCase):
"or choose the file.\n", page)
def test_the_data_page(self):
page = generate_site.generate_data_page([])
page = datapage.generate_data_page([])
self.assertTrue(page.startswith(
"---\nterms: manifest, schema, json schema, license, check a folder, "
"check bios folder script, rate limit, api\n---\n"))
@@ -1229,15 +1242,15 @@ class NoEmptyCoreTable(unittest.TestCase):
def test_own_list_platforms_get_a_sentence(self):
coverages = {"misterfpga": {"platform": "MiSTer FPGA", "config": {"cores": [], "systems": {}}}}
moved: dict[str, str] = {}
page = generate_site.generate_cross_reference(coverages, {}, moved)
page = crossref.generate_cross_reference(coverages, {}, moved)
self.assertEqual(moved, {})
self.assertIn(generate_site.OWN_LIST_ONLY, page)
self.assertIn(platformpage.OWN_LIST_ONLY, page)
def test_built_pages(self):
_built(DOCS / "cross-reference.md")
for name in ("misterfpga", "bizhawk"):
self.assertFalse((DOCS / f"cross-reference-{name}.md").exists())
self.assertIn(generate_site.OWN_LIST_ONLY, _page(f"platforms/{name}"))
self.assertIn(platformpage.OWN_LIST_ONLY, _page(f"platforms/{name}"))
redirects = json.loads((REPO_ROOT / "website" / "src" / "generated" /
"redirects.json").read_text())
self.assertEqual(redirects.get("/cross-reference-misterfpga/"), "/platforms/misterfpga/")
@@ -1253,9 +1266,9 @@ class FilesToSourceOnAPhone(unittest.TestCase):
for part in parts:
rows = [line for line in part.read_text(encoding="utf-8").splitlines()
if line.startswith("| `")]
self.assertLessEqual(len(rows), generate_site.FILES_TO_SOURCE_PART, part.name)
self.assertLessEqual(len(rows), gaps.FILES_TO_SOURCE_PART, part.name)
for row in rows:
self.assertIn(f"[Have it? Upload]({generate_site.UPLOAD_URL}", row)
self.assertIn(f"[Have it? Upload]({gaps.UPLOAD_URL}", row)
def test_the_upload_lands_in_the_folder_the_review_asks_for(self):
"""The link read the profile's first system: Raze's Duke Nukem 3D
@@ -1283,12 +1296,12 @@ class OneAnswerOnReleasePacks(unittest.TestCase):
"""8.1: the API, the picker's data and the pages read the registry."""
def test_a_child_does_not_inherit_its_parents_pack(self):
_contract, registry = generate_site._split_contract(
_contract, registry = dataexports._split_contract(
{"_key": "lakka", "inherits": "retroarch", "release_pack": True})
self.assertIs(registry["release_pack"], "lakka" in _released())
_contract, registry = generate_site._split_contract({"_key": "minui"})
_contract, registry = dataexports._split_contract({"_key": "minui"})
self.assertNotIn("release_pack", registry)
_contract, registry = generate_site._split_contract({"_key": "retroarch"})
_contract, registry = dataexports._split_contract({"_key": "retroarch"})
self.assertIs(registry["release_pack"], "retroarch" in _released())
def test_api_release_pack_set_equals_the_registry(self):
@@ -1302,7 +1315,7 @@ class OneAnswerOnReleasePacks(unittest.TestCase):
def test_the_picker_file_is_the_advertised_record(self):
with tempfile.TemporaryDirectory(dir=REPO_ROOT / "tmp" if (REPO_ROOT / "tmp").is_dir()
else None) as folder:
generate_site.write_release_advertised(Path(folder))
publish.write_release_advertised(Path(folder))
written = json.loads((Path(folder) / "release-advertised.json").read_text())
self.assertEqual(written, release_record.load_advertised())
served = {p for pack in written.get("packs", {}).values() for p in pack["platforms"]}
@@ -1338,7 +1351,7 @@ class EveryManifestFieldIsDescribed(unittest.TestCase):
self.assertEqual(missing, [])
def test_each_reason_code_has_a_line(self):
page = generate_site.generate_data_page([])
page = datapage.generate_data_page([])
for path, spec in _properties(SCHEMA):
if path.endswith(".reason"):
self.assertEqual(len(spec["enumDescriptions"]), len(spec["enum"]), path)
@@ -1346,7 +1359,7 @@ class EveryManifestFieldIsDescribed(unittest.TestCase):
self.assertRegex(page, rf"\n- `{code}`: \S")
def test_nested_tables_are_on_the_page(self):
page = generate_site.generate_data_page([])
page = datapage.generate_data_page([])
for label in ("Each entry of `omitted_files`:", "Each entry of `data_directories`:",
"Each value of `data_directories[].files`:", "Fields of `save_directory`:",
"Each entry of `files[].alternatives`:",
@@ -1376,10 +1389,10 @@ class LookupCountsEmulatorsLikeTheCard(unittest.TestCase):
"indexes": {"by_md5": {"b" * 32: self.SHA1}}}
coverages = {"setup": {"config": {"systems": {"sony-playstation": {"files": [
{"name": "bios.bin", "md5": "b" * 32}]}}}}}
with mock.patch.object(generate_site, "_console_system_names", return_value={}), \
mock.patch.object(generate_site, "_lookup_system_name", return_value=None), \
with mock.patch.object(lookup, "_console_system_names", return_value={}), \
mock.patch.object(lookup, "_lookup_system_name", return_value=None), \
mock.patch.object(generate_site, "emulator_card_page", side_effect=lambda k, a: k):
return generate_site.file_lookup_records(
return lookup.file_lookup_records(
db, coverages, {}, [{"sha1": self.SHA1, "url": "/x"}], None,
FakeConsumers(self.SHA1))
@@ -1411,7 +1424,7 @@ class TheDataPageListsWhatIsServed(unittest.TestCase):
"""8.4 and 8.6."""
def test_every_schema_is_listed(self):
page = generate_site.generate_data_page([])
page = datapage.generate_data_page([])
for path in (REPO_ROOT / "schemas").glob("*.schema.json"):
self.assertIn(f"- [`{path.name}`](api/v1/schemas/{path.name}): ", page)
@@ -1423,13 +1436,13 @@ class TheDataPageListsWhatIsServed(unittest.TestCase):
self.assertEqual((API / "targets" / source.name).read_bytes(), source.read_bytes())
def test_declared_only_and_search_words(self):
page = generate_site.generate_data_page([])
page = datapage.generate_data_page([])
self.assertIn("With `--declared-only`, or from the `declared` event, "
"`install.py --check` answers it too.", page)
terms = page.split("\n", 2)[1]
for word in ("json schema", "license", "check bios folder script"):
self.assertIn(word, terms)
files_terms = generate_site.generate_files_page().split("---\n", 2)[1]
files_terms = lookup.generate_files_page().split("---\n", 2)[1]
for word in ("is my bios correct", "is my bios right"):
self.assertIn(word, files_terms)
@@ -1504,7 +1517,7 @@ class TheFolderCheckExitCode(unittest.TestCase):
def test_the_page_shows_the_script(self):
script = Path(self.SCRIPT).read_text(encoding="utf-8")
self.assertIn("```python\n" + script.rstrip("\n") + "\n```",
generate_site.generate_data_page([]))
datapage.generate_data_page([]))
class SystemItemsCarryTheirApi(unittest.TestCase):
+35 -35
View File
@@ -83,7 +83,7 @@ class BundledFilesAreNotToSource(unittest.TestCase):
Classic, whose 13 missing files all come with its own package."""
def test_the_summary_and_the_row_count_only_what_must_be_found(self):
import generate_site
from sitegen import gaps
gap = {"required": True, "source_ref": "x", "in_repo": False}
report = {"zq": {
@@ -96,7 +96,7 @@ class BundledFilesAreNotToSource(unittest.TestCase):
{**gap, "name": "d.bin", "source": "bios", "in_repo": True},
],
}}
page = generate_site.generate_gap_analysis(
page = gaps.generate_gap_analysis(
{"zq": {"emulator": "ZQuest Classic", "files": []}}, {},
{"files": {}, "indexes": {}}, gap_report=report)
self.assertIn("2 installed with their emulator, 1 to source.", page)
@@ -107,7 +107,7 @@ class BundledFilesAreNotToSource(unittest.TestCase):
def test_a_row_names_only_the_platforms_that_read_it(self):
"""cdbios.bin, read by standalone BlastEm only and never on RetroBat,
was badged retroarch, lakka and retrobat."""
import generate_site
from sitegen import gaps
from model.platforms import load_platform_config
from resolve.cores import resolve_platform_cores
@@ -120,7 +120,7 @@ class BundledFilesAreNotToSource(unittest.TestCase):
configs[name] = config
self.assertIn("retroarch", configs)
self.assertIn("retrobat", configs)
found = generate_site.reading_platforms("blastem", profile, "cdbios.bin", configs)
found = gaps.reading_platforms("blastem", profile, "cdbios.bin", configs)
self.assertFalse(found & {"retroarch", "lakka", "retrobat"}, found)
@@ -132,9 +132,9 @@ class StructuredBlocks(unittest.TestCase):
"source_commit": self.PIN, block: value}
def render(self, profile: dict) -> str:
import generate_site
from sitegen import fields
return "\n".join(generate_site._render_structured_blocks(profile))
return "\n".join(fields._render_structured_blocks(profile))
@mock.patch("sitegen.sources.tree_holds", lambda *_args: True) # a path the record confirms
def test_a_source_ref_in_a_block_is_a_pinned_link(self):
@@ -173,7 +173,7 @@ class FileCardsLinkTheReadingEntry(unittest.TestCase):
def test_an_emulator_link_lands_on_its_entry(self):
"""The platform links landed on their section, the emulator links on
the top of a page of a hundred entries."""
import generate_site
from sitegen import cards
from packs.crossref import FileConsumers
consumers = FileConsumers({"files": {}})
@@ -183,11 +183,11 @@ class FileCardsLinkTheReadingEntry(unittest.TestCase):
consumers.emulators = {"s": {"duckstation", "other"}, "t": {"blastem"}}
consumers.emulator_entries = {"s": {"duckstation": 1}, "t": {"blastem": 2}}
consumers.emulator_files = {"duckstation": files, "blastem": files}
self.assertEqual(generate_site._emulator_links("s", consumers), [
self.assertEqual(cards._emulator_links("s", consumers), [
"[DuckStation](../emulators/duckstation.md#file-scph5501-bin)",
"[other](../emulators/other.md)",
])
self.assertEqual(generate_site._emulator_links("t", consumers),
self.assertEqual(cards._emulator_links("t", consumers),
["[BlastEm](../emulators/blastem.md#file-tmss-md-d0fd0c16)"])
@@ -213,20 +213,20 @@ class DirectoryMembersNameTheirEmulator(unittest.TestCase):
cls.consumers.add_emulators({"alephone": cls.profile})
def test_a_member_names_the_emulator_and_its_directory_entry(self):
import generate_site
from sitegen import cards
files = self.profile["files"]
index = self.consumers.emulator_entries[self.SHA1]["alephone"]
self.assertEqual(files[index].get("type"), "directory")
self.assertEqual(generate_site._emulator_links(self.SHA1, self.consumers),
self.assertEqual(cards._emulator_links(self.SHA1, self.consumers),
["[Aleph One](../emulators/alephone.md#file-marathon-plugins)"])
def test_the_directory_card_points_at_its_copies(self):
import generate_site
from sitegen import emulatorcards
entry = next(f for f in self.profile["files"]
if f.get("type") == "directory" and f.get("path") == "Marathon/Plugins/")
line = generate_site._directory_copies(entry, self.consumers)[0]
line = emulatorcards._directory_copies(entry, self.consumers)[0]
self.assertRegex(line, r"^Collection copies: \d+ files under "
r"\[`bios/Bungie/Marathon/Plugins/`\]\(\.\./systems/bungie\.md#")
@@ -245,17 +245,17 @@ class AnAliasTreeIsListedOnItsParentsPage(unittest.TestCase):
}
def test_the_permalink_goes_to_a_page_that_exists(self):
import generate_site
from sitegen import lookup
members = {"freeintv-overlays": {"a.png": {"sha1": "02" * 20}}}
items = generate_site.file_location_items({"files": {}}, self.PROFILES, members)
items = lookup.file_location_items({"files": {}}, self.PROFILES, members)
self.assertEqual(items, [{"sha1": "02" * 20,
"url": "/retrobios/emulators/freeintv/#sha1-020202020202"}])
def test_the_parent_page_lists_the_tree(self):
import generate_site
from sitegen import lookup
trees = generate_site.page_data_directories("freeintv", self.PROFILES)
trees = lookup.page_data_directories("freeintv", self.PROFILES)
self.assertEqual([t["ref"] for t in trees], ["freeintv-overlays"])
@@ -347,7 +347,7 @@ class TheDatHoldsEveryCopy(unittest.TestCase):
filed under two consoles) as unknown, and a fix moved them away."""
def test_a_second_copy_is_a_rom_of_its_own_folder(self):
import generate_site
from sitegen import structured
sha1 = "9526ef63" + "0" * 32
with tempfile.TemporaryDirectory() as tmp:
@@ -363,7 +363,7 @@ class TheDatHoldsEveryCopy(unittest.TestCase):
"Atari/ST/tos104uk.img": [sha1], "ST/tos104uk.img": [sha1],
}},
}
dat = generate_site.collection_dat(db, "2026-10-21T00:00:00Z")
dat = structured.collection_dat(db, "2026-10-21T00:00:00Z")
self.assertIn('<rom name="tos104.img" size="1"', dat)
self.assertIn('<rom name="tos104uk.img" size="1"', dat)
self.assertEqual(dat.count("<rom "), 2)
@@ -376,13 +376,13 @@ class TheSearchLandsOnTheCard(unittest.TestCase):
overview of a 100-block page."""
def test_a_platform_system_is_a_heading(self):
import generate_site
from sitegen import platformfiles
by_system = {f"system-{i:02d}": [{"name": f"f{i}.bin", "status": "ok"}]
for i in range(11)}
names = {sys_id: f"System {sys_id[-2:]}" for sys_id in by_system}
with mock.patch.dict(systemnames.SYSTEM_NAMES, names):
lines = generate_site._render_platform_systems(by_system, {}, {})
lines = platformfiles._render_platform_systems(by_system, {}, {})
headings = [line for line in lines if line.startswith("### ")]
self.assertEqual(len(headings), 11)
self.assertTrue(headings[0].endswith("{ #system-00 }"))
@@ -390,20 +390,20 @@ class TheSearchLandsOnTheCard(unittest.TestCase):
self.assertIn("<summary>1 file (OK)</summary>", lines)
def test_an_emulator_card_is_a_heading_with_its_anchor(self):
import generate_site
from sitegen import emulatorcards
entry = {"name": "scph5501.bin", "required": True}
lines = generate_site._render_emulator_file(
lines = emulatorcards._render_emulator_file(
entry, {"files": [entry]}, None, [entry], lambda f: True, "file-scph5501-bin")
self.assertTrue(lines[2].startswith('<h3 id="file-scph5501-bin" class="rb-file-title"'))
self.assertIn("<code>scph5501.bin</code>", lines[2])
def test_a_system_card_is_a_heading_with_its_anchor(self):
import generate_site
from sitegen import cards
from packs.crossref import FileConsumers
entry = {"name": "a.bin", "sha1": "a" * 40, "md5": "b" * 32, "size": 3}
lines = generate_site._system_file_card(entry, FileConsumers({"files": {}}))
lines = cards._system_file_card(entry, FileConsumers({"files": {}}))
self.assertTrue(lines[2].startswith('<h3 id="sha1-aaaaaaaaaaaa" class="rb-file-title"'))
self.assertIn("<code>a.bin</code>", lines[2])
@@ -415,7 +415,7 @@ class TheSearchSkipsLinkLists(unittest.TestCase):
hashes 4 MB more: files/?hash= finds those."""
def test_a_system_card_keeps_its_name_and_skips_its_body(self):
import generate_site
from sitegen import cards
from packs.crossref import FileConsumers
consumers = FileConsumers({"files": {}})
@@ -424,7 +424,7 @@ class TheSearchSkipsLinkLists(unittest.TestCase):
consumers.installed = {sha1: {"batocera": {"bios/a.bin"}}}
consumers.emulators = {sha1: {"duckstation"}}
entry = {"name": "a.bin", "sha1": sha1, "md5": "b" * 32, "size": 3}
lines = generate_site._system_file_card(entry, consumers)
lines = cards._system_file_card(entry, consumers)
self.assertIn("<code>a.bin</code>", lines[2])
text = "\n".join(lines)
searched, _sep, skipped = text.partition('<dl class="rb-facts" data-pagefind-ignore>')
@@ -436,22 +436,22 @@ class TheSearchSkipsLinkLists(unittest.TestCase):
self.assertNotIn('<dl class="rb-facts">', searched)
def test_a_game_data_card_skips_its_name_too(self):
import generate_site
from sitegen import cards
from packs.crossref import FileConsumers
entry = {"name": "0.ogg", "sha1": "a" * 40, "size": 3}
lines = generate_site._system_file_card(
lines = cards._system_file_card(
entry, FileConsumers({"files": {}}), searchable=False)
self.assertIn("data-pagefind-ignore", lines[2])
self.assertNotIn("data-pagefind-weight", lines[2])
def test_runs_alternate_in_card_order(self):
import generate_site
from sitegen import cards
lines = ["- Path: `p`", "- SHA1: x", "- Source: `a.c:1`", "- Platforms: p",
"- Destination: `d`", "- Contents (1 members):", " - `m`",
"- Note"]
out = [line for line in generate_site._search_skipped_apart(lines) if line]
out = [line for line in cards._search_skipped_apart(lines) if line]
self.assertEqual(out, [
"- Path: `p`",
'<div class="rb-search-skip" data-pagefind-ignore>',
@@ -463,11 +463,11 @@ class TheSearchSkipsLinkLists(unittest.TestCase):
])
def test_long_tables_leave_the_search(self):
import generate_site
from sitegen import cards
short = "| a |\n|---|\n| 1 |"
long = " | a |\n |---|\n" + "\n".join(f" | {'x' * 50} |" for _ in range(80))
text = generate_site.tables_out_of_search(f"# T\n\n{short}\n\n{long}\n")
text = cards.tables_out_of_search(f"# T\n\n{short}\n\n{long}\n")
self.assertEqual(text.count("data-pagefind-ignore"), 1)
self.assertIn(" <section data-pagefind-ignore>\n\n | a |", text)
self.assertIn(short, text)
@@ -507,7 +507,7 @@ class AMemberIsReadInItsArchive(unittest.TestCase):
def test_the_archive_is_credited_and_named_on_the_card(self):
import json
import generate_site as gs
from sitegen import emulatorcards
from resolve.archives import archive_entry
from resolve.localfile import resolve_local_file
from packs.crossref import FileConsumers
@@ -523,7 +523,7 @@ class AMemberIsReadInItsArchive(unittest.TestCase):
self.assertIn(shipped, credited)
self.assertFalse([p for p in credited if p.endswith("/sm1.sm1")])
sm1 = next(f for f in files if f["name"] == "sm1.sm1")
rows = "\n".join(gs._render_emulator_file(sm1, profile, consumers, files,
rows = "\n".join(emulatorcards._render_emulator_file(sm1, profile, consumers, files,
lambda _f: True, owner="fbneo"))
self.assertIn("Collection copy: member `sm1.sm1` of", rows)
self.assertIn(shipped, rows)
+54 -50
View File
@@ -30,10 +30,14 @@ import yaml
import json
from html.parser import HTMLParser
import generate_site as gs
from sitegen import decorate
from sitegen import descriptions
from sitegen import emulatorcards
from sitegen import getpages
from sitegen import structured
from sitegen import starlight as sitestarlight
from sitegen import validate
import generate_site
from sitegen import structured
from model.registry import list_registered_platforms
from model.profiles import load_emulator_profiles
from tests.test_site_nav import ANCHORS, _nav, _present
@@ -165,7 +169,7 @@ class FindOrCheckAFile(unittest.TestCase):
def test_the_page_weighs_two(self) -> None:
rel = Path("files/index.md")
self.assertEqual(gs.search_weight(rel, gs.page_level(rel)), 2)
self.assertEqual(decorate.search_weight(rel, decorate.page_level(rel)), 2)
def test_its_terms_become_a_field(self) -> None:
text = _finalize("files/index.md", "# Find or check a file\n\nBody.\n",
@@ -180,8 +184,8 @@ class FindOrCheckAFile(unittest.TestCase):
class PartPages(unittest.TestCase):
def test_part_weight(self) -> None:
self.assertEqual(gs.SEARCH_WEIGHT["part"], 0.5)
self.assertEqual(gs.search_weight(Path("systems/arcade-mame-5.md"), "part"), 0.5)
self.assertEqual(decorate.SEARCH_WEIGHT["part"], 0.5)
self.assertEqual(decorate.search_weight(Path("systems/arcade-mame-5.md"), "part"), 0.5)
def test_a_part_keeps_its_own_weight_and_neighbours(self) -> None:
"""The MAME card parts write prev, next and searchWeight: the build
@@ -191,7 +195,7 @@ class PartPages(unittest.TestCase):
"parent:\n label: MAME\n link: mame.md\n"
"prev:\n label: MAME files, part 2 of 8\n link: mame-files-2.md\n"
"next:\n label: MAME files, part 4 of 8\n link: mame-files-4.md\n"
f"searchWeight: {gs.search_weight(Path('emulators/mame-files-3.md'), 'part')}\n"
f"searchWeight: {decorate.search_weight(Path('emulators/mame-files-3.md'), 'part')}\n"
"---\n\n# MAME files, part 3 of 8\n\nPart of [MAME](mame.md). "
"This part holds 196 entries, `a.zip` to `b.zip`.\n"
)
@@ -199,9 +203,9 @@ class PartPages(unittest.TestCase):
path = Path(tmp) / "emulators" / "mame-files-3.md"
path.parent.mkdir()
path.write_text(page, encoding="utf-8")
gs.PART_PAGES.add("emulators/mame-files-3.md")
self.addCleanup(gs.PART_PAGES.discard, "emulators/mame-files-3.md")
gs.decorate_markdown_pages(Path(tmp))
descriptions.PART_PAGES.add("emulators/mame-files-3.md")
self.addCleanup(descriptions.PART_PAGES.discard, "emulators/mame-files-3.md")
decorate.decorate_markdown_pages(Path(tmp))
front = _front(path.read_text(encoding="utf-8"))
self.assertEqual(front["searchWeight"], 0.5)
self.assertEqual(front["prev"], {"label": "MAME files, part 2 of 8",
@@ -223,71 +227,71 @@ class PartPages(unittest.TestCase):
class Descriptions(unittest.TestCase):
def test_titles_say_bios_files(self) -> None:
saved = dict(gs.PAGE_DATA)
self.addCleanup(lambda: (gs.PAGE_DATA.clear(), gs.PAGE_DATA.update(saved)))
gs.PAGE_DATA["emulators/duckstation.md"] = {"hasPart": [{"name": "scph5501.bin"}]}
self.assertEqual(gs._browser_title(Path("emulators/duckstation.md"), "DuckStation"),
saved = dict(descriptions.PAGE_DATA)
self.addCleanup(lambda: (descriptions.PAGE_DATA.clear(), descriptions.PAGE_DATA.update(saved)))
descriptions.PAGE_DATA["emulators/duckstation.md"] = {"hasPart": [{"name": "scph5501.bin"}]}
self.assertEqual(descriptions._browser_title(Path("emulators/duckstation.md"), "DuckStation"),
"DuckStation BIOS files")
self.assertEqual(gs._browser_title(Path("systems/sega.md"), "Sega"), "Sega BIOS files")
self.assertEqual(gs._browser_title(Path("systems/sega-dreamcast.md"), "Sega: Dreamcast"),
self.assertEqual(descriptions._browser_title(Path("systems/sega.md"), "Sega"), "Sega BIOS files")
self.assertEqual(descriptions._browser_title(Path("systems/sega-dreamcast.md"), "Sega: Dreamcast"),
"Dreamcast BIOS files (Sega)")
def test_an_emulator_page_is_described_by_its_intro(self) -> None:
saved = dict(gs.PAGE_DATA)
self.addCleanup(lambda: (gs.PAGE_DATA.clear(), gs.PAGE_DATA.update(saved)))
gs.PAGE_DATA["emulators/duckstation.md"] = {"hasPart": [{"name": "scph5501.bin"}]}
saved = dict(descriptions.PAGE_DATA)
self.addCleanup(lambda: (descriptions.PAGE_DATA.clear(), descriptions.PAGE_DATA.update(saved)))
descriptions.PAGE_DATA["emulators/duckstation.md"] = {"hasPart": [{"name": "scph5501.bin"}]}
body = ("# DuckStation\n\nDuckStation emulates Sony PlayStation. It picks the BIOS for "
"the game's region.\n\n<details>\n\nThe installer finds the platform.\n")
text = gs._page_description(body, Path("emulators/duckstation.md"), "DuckStation")
text = descriptions._page_description(body, Path("emulators/duckstation.md"), "DuckStation")
self.assertTrue(text.startswith("DuckStation emulates Sony PlayStation."))
self.assertNotIn("source-pinned", text)
def test_a_page_whose_files_come_with_the_app_promises_none(self) -> None:
"""DaedalusX64's three files come with the app. The result read
"DaedalusX64 BIOS files" over "DaedalusX64 emulates Nintendo 64."."""
saved, shipped = dict(gs.PAGE_DATA), set(gs.NOTHING_TO_FETCH)
self.addCleanup(lambda: (gs.PAGE_DATA.clear(), gs.PAGE_DATA.update(saved),
gs.NOTHING_TO_FETCH.clear(), gs.NOTHING_TO_FETCH.update(shipped)))
saved, shipped = dict(descriptions.PAGE_DATA), set(descriptions.NOTHING_TO_FETCH)
self.addCleanup(lambda: (descriptions.PAGE_DATA.clear(), descriptions.PAGE_DATA.update(saved),
descriptions.NOTHING_TO_FETCH.clear(), descriptions.NOTHING_TO_FETCH.update(shipped)))
with open(REPO_ROOT / "emulators" / "daedalusx64.yml", encoding="utf-8") as handle:
gs.record_emulator_page("daedalusx64", yaml.safe_load(handle))
structured.record_emulator_page("daedalusx64", yaml.safe_load(handle))
key = Path("emulators/daedalusx64.md")
self.assertEqual(gs._browser_title(key, "DaedalusX64"), "DaedalusX64 emulator")
self.assertEqual(descriptions._browser_title(key, "DaedalusX64"), "DaedalusX64 emulator")
body = "# DaedalusX64\n\nDaedalusX64 emulates Nintendo 64.\n"
self.assertEqual(gs._page_description(body, key, "DaedalusX64"),
self.assertEqual(descriptions._page_description(body, key, "DaedalusX64"),
"DaedalusX64 emulates Nintendo 64. Every file it reads comes with the app.")
def test_an_emulator_snippet_names_the_files_searched_for(self) -> None:
""""gba_bios.bin" and "dreamcast bios" landed on pages described as
"It reads 4 files, none of them required": fewer than 1 in 70 clicked."""
saved, snippets = dict(gs.PAGE_DATA), dict(gs.EMULATOR_SNIPPETS)
self.addCleanup(lambda: (gs.PAGE_DATA.clear(), gs.PAGE_DATA.update(saved),
gs.EMULATOR_SNIPPETS.clear(),
gs.EMULATOR_SNIPPETS.update(snippets)))
saved, snippets = dict(descriptions.PAGE_DATA), dict(descriptions.EMULATOR_SNIPPETS)
self.addCleanup(lambda: (descriptions.PAGE_DATA.clear(), descriptions.PAGE_DATA.update(saved),
descriptions.EMULATOR_SNIPPETS.clear(),
descriptions.EMULATOR_SNIPPETS.update(snippets)))
with open(REPO_ROOT / "emulators" / "flycast.yml", encoding="utf-8") as handle:
gs.record_emulator_page("flycast", yaml.safe_load(handle))
structured.record_emulator_page("flycast", yaml.safe_load(handle))
key = Path("emulators/flycast.md")
body = ("# Flycast\n\nFlycast emulates Sega Dreamcast. It reads 10 files, 4 of them "
"required: without a required file it does not start games.\n")
text = gs._page_description(body, key, "Flycast")
text = descriptions._page_description(body, key, "Flycast")
self.assertTrue(text.startswith("Sega Dreamcast BIOS for Flycast: dc_boot.bin, "), text)
self.assertLessEqual(len(text), 155)
self.assertFalse(text.endswith("..."), text)
def test_a_switch_emulator_reads_keys(self) -> None:
self.assertEqual(gs._snippet_noun(["prod.keys", "dev.keys", "title.keys", "key_retail.bin"], 4, 4), "keys")
self.assertEqual(gs._snippet_noun(["prod.keys", "title.keys", "<firmware>.zip", "a.txt"], 3, 4),
self.assertEqual(emulatorcards._snippet_noun(["prod.keys", "dev.keys", "title.keys", "key_retail.bin"], 4, 4), "keys")
self.assertEqual(emulatorcards._snippet_noun(["prod.keys", "title.keys", "<firmware>.zip", "a.txt"], 3, 4),
"keys and firmware")
self.assertEqual(gs._snippet_noun(["gba_bios.bin", "gb_bios.bin"], 2, 2), "BIOS")
self.assertEqual(gs._snippet_noun(["oot.z64", "oot-mq.z64", "font.bin"], 1, 3), "files")
self.assertEqual(emulatorcards._snippet_noun(["gba_bios.bin", "gb_bios.bin"], 2, 2), "BIOS")
self.assertEqual(emulatorcards._snippet_noun(["oot.z64", "oot-mq.z64", "font.bin"], 1, 3), "files")
def test_an_any_name_snippet_says_what_to_do(self) -> None:
saved = dict(gs.PAGE_DATA)
self.addCleanup(lambda: (gs.PAGE_DATA.clear(), gs.PAGE_DATA.update(saved)))
gs.PAGE_DATA["emulators/aethersx2.md"] = {"hasPart": [{"name": "ps2.bin"}]}
saved = dict(descriptions.PAGE_DATA)
self.addCleanup(lambda: (descriptions.PAGE_DATA.clear(), descriptions.PAGE_DATA.update(saved)))
descriptions.PAGE_DATA["emulators/aethersx2.md"] = {"hasPart": [{"name": "ps2.bin"}]}
body = ("# AetherSX2\n\nAetherSX2 needs one Sony PlayStation 2 BIOS file, any region."
"\n\n1. Download [`ps2.bin`](../x/).\n2. Put it in this folder:\n")
self.assertEqual(
gs._page_description(body, Path("emulators/aethersx2.md"), "AetherSX2"),
descriptions._page_description(body, Path("emulators/aethersx2.md"), "AetherSX2"),
"AetherSX2 needs one Sony PlayStation 2 BIOS file, any region. Download one "
"from this page and put it in the folder it shows. Any file name works.")
@@ -296,7 +300,7 @@ class Descriptions(unittest.TestCase):
body = ("# Hydra Castle Labyrinth\n\n<details>\n<summary>Technical notes</summary>\n\n"
"Open-source port of E. Hashimoto's 2008 freeware Metroidvania. It reads "
"its data folder.\n\n</details>\n")
text = gs._emulator_description(body, "emulators/hcl.md", "Hydra Castle Labyrinth", "")
text = descriptions._emulator_description(body, "emulators/hcl.md", "Hydra Castle Labyrinth", "")
self.assertTrue(text.startswith("Hydra Castle Labyrinth: open-source port of E. "
"Hashimoto's 2008 freeware Metroidvania."), text)
self.assertNotIn("It reads", text)
@@ -307,19 +311,19 @@ class Descriptions(unittest.TestCase):
body = ("# ROCKNIX\n\nA system for handhelds. [ROCKNIX website](https://rocknix.org).\n\n"
"## On the device { #install }\n")
self.assertEqual(
gs._page_description(body, Path("platforms/rocknix.md"), "ROCKNIX"),
descriptions._page_description(body, Path("platforms/rocknix.md"), "ROCKNIX"),
"The BIOS files for ROCKNIX, the folder they go in and the command that installs "
"them. A system for handhelds.")
def test_a_console_page_is_described_by_its_start_line(self) -> None:
body = "# Sega: Dreamcast\n\nPart of Sega.\n\n**Start with**: `dc_boot.bin`, `dc_flash.bin`.\n"
text = gs._page_description(body, Path("systems/sega-dreamcast.md"), "Sega: Dreamcast")
text = descriptions._page_description(body, Path("systems/sega-dreamcast.md"), "Sega: Dreamcast")
self.assertEqual(text, "Dreamcast BIOS files (Sega). Start with dc_boot.bin, dc_flash.bin.")
def test_the_faq_is_described_by_its_questions(self) -> None:
body = ("# Common questions\n\n## Are BIOS files needed?\n\nYes.\n\n## Which one?\n\n"
"Run the command with --dry-run.\n\n## Zip or not?\n\nZip.\n")
text = gs._page_description(body, Path("wiki/faq.md"), "Common questions")
text = descriptions._page_description(body, Path("wiki/faq.md"), "Common questions")
self.assertTrue(text.startswith("Common questions: Are BIOS files needed?"))
def test_a_written_description_wins(self) -> None:
@@ -375,12 +379,12 @@ class GetPagesSitInYourSetup(unittest.TestCase):
def test_a_get_page_is_dated_by_its_release(self):
"""The sitemap gave no date to the pages that change only with a release."""
saved = dict(gs.PAGE_DATA)
self.addCleanup(lambda: (gs.PAGE_DATA.clear(), gs.PAGE_DATA.update(saved)))
saved = dict(descriptions.PAGE_DATA)
self.addCleanup(lambda: (descriptions.PAGE_DATA.clear(), descriptions.PAGE_DATA.update(saved)))
record = json.loads((REPO_ROOT / "release.json").read_text(encoding="utf-8"))
tag = re.fullmatch(r"v(\d{4})\.(\d{2})\.(\d{2})", record["tag"])
gs.generate_get_page("retroarch")
self.assertEqual(gs.PAGE_DATA["get/retroarch.md"], {"dateModified": "-".join(tag.groups())})
getpages.generate_get_page("retroarch")
self.assertEqual(descriptions.PAGE_DATA["get/retroarch.md"], {"dateModified": "-".join(tag.groups())})
def test_no_page_is_left_out_of_every_tab(self):
nav = _nav()
@@ -573,7 +577,7 @@ class StructuredData(unittest.TestCase):
release, never a commit id, and no placeholder description."""
def test_versions_name_releases_only(self):
release = generate_site.release_versions
release = structured.release_versions
self.assertEqual(release({"core_version": "v0.1-12070"}), {"": "v0.1-12070"})
self.assertEqual(release({"core_version": "1.5.85"}), {"": "1.5.85"})
self.assertEqual(release({"core_version": "8dc77b0"}), {})
@@ -592,7 +596,7 @@ class StructuredData(unittest.TestCase):
{"": "20200712"})
def test_the_pin_is_never_a_version(self):
data = generate_site.emulator_structured_data({
data = structured.emulator_structured_data({
"emulator": "Redream", "source": "https://github.com/x/redream",
"source_commit": "0123abcd",
})
@@ -688,7 +692,7 @@ class BuiltSearchSidebarAndHead(unittest.TestCase):
self.assertNotIn("description", entry)
runs = re.findall(r"[0-9a-f]{7,40}", str(entry.get("version", "")).casefold())
self.assertFalse([run for run in runs if run[:7] in pins])
self.assertFalse(generate_site._COMMIT_ID.search(str(entry.get("version", ""))))
self.assertFalse(structured._COMMIT_ID.search(str(entry.get("version", ""))))
self.assertTrue(seen)
+24 -18
View File
@@ -18,6 +18,12 @@ import unittest
from pathlib import Path
import generate_site as gs
from sitegen import places
from sitegen import platformfiles
from sitegen import startwith
from sitegen import systempages
from sitegen import systemsindex
from sitegen import whichpack
from sitegen import render as siterender
from model import systemnames
@@ -28,11 +34,11 @@ class LinksFollowContent(unittest.TestCase):
def test_an_ambiguous_name_places_nothing(self):
names = {"boot.rom": {("VideoBrain", "VideoBrain"), ("Bandai", "WonderSwan")}}
files = [{"name": "boot.rom", "sha1": "0" * 40}]
self.assertIsNone(gs._system_folder(files, {"files": {}, "indexes": {}}, names))
self.assertIsNone(places._system_folder(files, {"files": {}, "indexes": {}}, names))
names["only.rom"] = {("Bandai", "WonderSwan")}
files.append({"name": "only.rom"})
self.assertEqual(
gs._system_folder(files, {"files": {}, "indexes": {}}, names),
places._system_folder(files, {"files": {}, "indexes": {}}, names),
("Bandai", "WonderSwan"),
)
@@ -58,7 +64,7 @@ class LinksFollowContent(unittest.TestCase):
if system is None:
continue
with self.subTest(system=sys_id):
place = gs._system_folder(system.get("files", []), db, names)
place = places._system_folder(system.get("files", []), db, names)
self.assertEqual(place and place[1], console)
@@ -68,12 +74,12 @@ class OtherSpellingsOfOneSystem(unittest.TestCase):
sega-megadrive, and 2,057 of 4,215 emulator system lines had no link."""
def test_a_platform_system_finds_its_emulators(self):
index = gs._build_emulator_file_index({
index = whichpack._build_emulator_file_index({
"genesis_plus_gx": {"systems": ["sega-megadrive"]},
"np2kai": {"systems": ["pc-98"]},
})
self.assertEqual(gs._system_emulators("sega-mega-drive", index), ["genesis_plus_gx"])
self.assertEqual(gs._system_emulators("nintendo-snes", index), [])
self.assertEqual(platformfiles._system_emulators("sega-mega-drive", index), ["genesis_plus_gx"])
self.assertEqual(platformfiles._system_emulators("nintendo-snes", index), [])
def _install(self, mapping: dict) -> None:
from sitegen import render as siterender
@@ -105,7 +111,7 @@ class OtherSpellingsOfOneSystem(unittest.TestCase):
manufacturers = {"Commodore": {"PET": [{"name": "basic4.bin"}]}}
profiles = {"vice_xpet": {"systems": ["commodore-pet"],
"files": [{"name": "basic4.bin"}]}}
pages = gs._system_pages_from_data(
pages = places._system_pages_from_data(
manufacturers, {}, {"files": {}, "indexes": {}}, profiles)
self.assertEqual(pages["commodore-pet"], ("commodore", "PET"))
@@ -134,7 +140,7 @@ class ACopyIsOnItsOwnFoldersPage(unittest.TestCase):
self.assertEqual(sorted(groups), ["Arcade", "Fairchild"])
self.assertEqual(list(groups["Fairchild"]), ["Channel F"])
# The copy is listed twice and counted once.
self.assertRegex(gs.generate_systems_index(groups), r"2 consoles, 1 files? ")
self.assertRegex(systemsindex.generate_systems_index(groups), r"2 consoles, 1 files? ")
class AnIdNamesOneCardPerPage(unittest.TestCase):
@@ -146,7 +152,7 @@ class AnIdNamesOneCardPerPage(unittest.TestCase):
entry = {"name": "a.bin", "sha1": "a" * 40, "md5": "b" * 32, "size": 3,
"path": "bios/Nintendo/DS/a.bin"}
page = gs.generate_system_page(
page = systempages.generate_system_page(
"Nintendo", {"DS": [entry], "DSi": [entry]}, FileConsumers({"files": {}}))
self.assertEqual(page.count('id="sha1-aaaaaaaaaaaa" class="rb-file-title"'), 1)
self.assertEqual(page.count("rb-sys-file"), 2)
@@ -188,14 +194,14 @@ class ACopyFiledByEmulatorDoesNotMoveAMachine(unittest.TestCase):
db = self._db(tmp)
files = [{"name": "disksys.rom", "sha1": "d" * 40}]
self.assertEqual(
gs._system_folder(files, db, {}, "nintendo-fds"),
places._system_folder(files, db, {}, "nintendo-fds"),
("Nintendo", "Famicom Disk System"),
)
# A file named otherwise still finds the maker's copy before the
# emulator's folder.
files = [{"name": "FDS_disksys-nintendo.rom", "sha1": "d" * 40}]
self.assertEqual(
gs._system_folder(files, db, {}, "fds"),
places._system_folder(files, db, {}, "fds"),
("Nintendo", "Famicom Disk System"),
)
@@ -207,7 +213,7 @@ class ACopyFiledByEmulatorDoesNotMoveAMachine(unittest.TestCase):
manufacturers = gs._group_by_manufacturer(db)
config = {"systems": {"nintendo-nes": {"files": [
{"name": "FDS_disksys-nintendo.rom", "sha1": "d" * 40}]}}}
pages = gs._system_pages_from_data(
pages = places._system_pages_from_data(
manufacturers, {"p": {"config": config}}, db)
self.assertEqual(pages["nintendo-nes"], ("nintendo", "NES"))
@@ -222,7 +228,7 @@ class ACopyFiledByEmulatorDoesNotMoveAMachine(unittest.TestCase):
db = load_database("database.json")
manufacturers = gs._group_by_manufacturer(db)
pages = gs._system_pages_from_data(
pages = places._system_pages_from_data(
manufacturers, {}, db, load_emulator_profiles("emulators", skip_aliases=False))
expected = {
"nintendo-nes": ("nintendo", "NES"),
@@ -242,7 +248,7 @@ class SystemEmulatorsWhenNoIdMatches(unittest.TestCase):
of both rows was empty on every platform page."""
def setUp(self):
self.index = gs._build_emulator_file_index({
self.index = whichpack._build_emulator_file_index({
"flycast": {"systems": ["sega-naomi"], "files": [{"name": "airlbios.zip"}]},
"fbneo": {"systems": ["arcade"], "files": [
{"name": "boot.bin", "archive": "bubsys.zip"}]},
@@ -251,18 +257,18 @@ class SystemEmulatorsWhenNoIdMatches(unittest.TestCase):
def test_a_file_the_system_lists_names_its_emulator(self):
self.assertEqual(
gs._system_emulators("sega-dreamcast-arcade", self.index, [{"name": "airlbios.zip"}]),
platformfiles._system_emulators("sega-dreamcast-arcade", self.index, [{"name": "airlbios.zip"}]),
["flycast"],
)
def test_an_archive_member_is_not_a_file_by_that_name(self):
self.assertEqual(
gs._system_emulators("sega-dreamcast", self.index, [{"name": "boot.bin"}]), []
platformfiles._system_emulators("sega-dreamcast", self.index, [{"name": "boot.bin"}]), []
)
def test_an_id_match_is_kept_alone(self):
self.assertEqual(
gs._system_emulators("sega-megadrive", self.index, [{"name": "airlbios.zip"}]),
platformfiles._system_emulators("sega-megadrive", self.index, [{"name": "airlbios.zip"}]),
["genesis"],
)
@@ -325,7 +331,7 @@ class EverySystemLinkLandsOnItsSection(unittest.TestCase):
# The Arcade folder of sets no board claims is headed by
# what it holds, its id staying the folder's.
if slug == "arcade":
console = gs._section_label("Arcade", console)
console = startwith._section_label("Arcade", console)
self.assertEqual(self.headings[page][match["anchor"]], console)
self.assertGreater(linked, 200)
+2 -2
View File
@@ -123,9 +123,9 @@ class SectionsComeBeforeThePlan(unittest.TestCase):
import ast
import inspect
import generate_site
from sitegen import build
tree = ast.parse(inspect.getsource(generate_site._generate))
tree = ast.parse(inspect.getsource(build._generate))
lines = {}
for node in ast.walk(tree):
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
+7 -6
View File
@@ -151,7 +151,8 @@ class SystemLinks(unittest.TestCase):
from model.registry import list_registered_platforms
from model.profiles import load_emulator_profiles
from model.platforms import load_platform_config
from generate_site import _group_by_manufacturer, arcade_board_sections
from generate_site import _group_by_manufacturer
from sitegen.systempages import arcade_board_sections
with open("database.json", encoding="utf-8") as handle:
db = json.load(handle)
@@ -280,7 +281,7 @@ class SystemLinks(unittest.TestCase):
self.assertNotIn(sys_id, systemnames.SYSTEM_PARENTS)
def test_emulator_rows_link_the_variant(self) -> None:
from generate_site import _named_system_link
from sitegen.emulatorcards import _named_system_link
self.assertEqual(
_named_system_link("wonderswan-color", "../"),
@@ -321,15 +322,15 @@ class AnEntryListingSystemsIsFiledUnderEach(unittest.TestCase):
under neither Arcade nor NEC PC-88, and kept on pages it does not serve."""
def test_the_site_reads_the_common_rule(self):
import generate_site as gs
from sitegen import consolecards
from model.profiles import entry_system_ids
entry = {"name": "ym2608.zip", "systems": ["arcade", "pc80"]}
self.assertEqual(gs._entry_systems("mame", entry), ["arcade", "pc80"])
self.assertEqual(consolecards._entry_systems("mame", entry), ["arcade", "pc80"])
self.assertEqual(
gs._entry_systems("mame", entry), entry_system_ids(entry, {"systems": []})
consolecards._entry_systems("mame", entry), entry_system_ids(entry, {"systems": []})
)
self.assertEqual(gs._entry_systems("mame", {"name": "a", "system": "pc80"}), ["pc80"])
self.assertEqual(consolecards._entry_systems("mame", {"name": "a", "system": "pc80"}), ["pc80"])
if __name__ == "__main__":
+83 -75
View File
@@ -41,6 +41,14 @@ import zipfile
import json
import generate_site as gs
from sitegen import cards as sitegen_cards
from sitegen import consolecards
from sitegen import decorate
from sitegen import install as sitegen_install
from sitegen import lookup
from sitegen import startwith
from sitegen import systempages
from sitegen import systemsindex
from sitegen import render as siterender
from model import systemnames
from packs.crossref import FileConsumers
@@ -100,7 +108,7 @@ class TheConsoleBiosComesFirst(unittest.TestCase):
}, platforms={"6" * 40: {"a", "b"}, "3" * 40: {"a", "b", "c"}})
def names(self) -> list[str]:
cards = gs._console_cards("Sony", self.files, self.consumers, set())
cards = consolecards._console_cards("Sony", self.files, self.consumers, set())
return [re.search(r"<code>(.*?)</code>", card[2])[1] for _v, card, _s in cards]
def test_required_then_priority_then_setups_then_name(self):
@@ -112,7 +120,7 @@ class TheConsoleBiosComesFirst(unittest.TestCase):
])
def test_a_console_cut_in_parts_goes_by_name(self):
cards = gs._console_cards("Sony", self.files, self.consumers, set(), by_name=True)
cards = consolecards._console_cards("Sony", self.files, self.consumers, set(), by_name=True)
names = [re.search(r"<code>(.*?)</code>", card[2])[1] for _v, card, _s in cards]
self.assertEqual(names, sorted(names, key=str.casefold))
@@ -127,7 +135,7 @@ class TheConsoleBiosComesFirst(unittest.TestCase):
})
def test_the_section_opens_on_the_bios_by_region(self):
lines = gs._start_with(self.files, self.required_only())
lines = startwith._start_with(self.files, self.required_only())
self.assertEqual(lines[0], "**Start with** the BIOS for the region of the games:")
self.assertIn("- **North America**: [`scph5501.bin`](#sha1-444444444444)", lines)
self.assertIn("- **Japan**: [`scph5500.bin`](#sha1-555555555555)", lines)
@@ -137,7 +145,7 @@ class TheConsoleBiosComesFirst(unittest.TestCase):
def test_regions_needing_the_same_file_share_a_line(self):
consumers = _one_reader_each({"4" * 40: [
{"required": True, "region": ["north-america", "latin-america", "brazil"]}]})
lines = gs._start_with([_sony_file("scph5501.bin", "4")], consumers)
lines = startwith._start_with([_sony_file("scph5501.bin", "4")], consumers)
# Brazil says nothing Latin America does not.
self.assertIn("- **North America, Latin America**: [`scph5501.bin`](#sha1-444444444444)", lines)
@@ -148,17 +156,17 @@ class TheConsoleBiosComesFirst(unittest.TestCase):
consumers = _one_reader_each({f["sha1"]: [{"required": True}] for f in files})
consumers.emulator_files = {"emu": [{"required": True}] * len(files)}
consumers.emulator_entries = {f["sha1"]: {"emu": i} for i, f in enumerate(files)}
self.assertEqual(gs._start_with(files, consumers)[0],
self.assertEqual(startwith._start_with(files, consumers)[0],
"**Start with**: [`rom0.bin`](#sha1-aaaaaaaaaaaa), [`rom1.bin`](#sha1-bbbbbbbbbbbb), "
"[`rom2.bin`](#sha1-cccccccccccc) and 5 more files. "
"They come first below.")
def test_no_required_file_no_line(self):
self.assertEqual(gs._start_with([_sony_file("a.bin", "a")], _one_reader_each({})), [])
self.assertEqual(startwith._start_with([_sony_file("a.bin", "a")], _one_reader_each({})), [])
def test_the_page_carries_the_line_under_the_console(self):
# Sega keeps its consoles as sections. Sony gives each a page.
page = gs.generate_system_page("Sega", {"Saturn": self.files}, self.required_only())
page = systempages.generate_system_page("Sega", {"Saturn": self.files}, self.required_only())
heading = page.index("## Saturn")
self.assertLess(heading, page.index("**Start with**"))
self.assertLess(page.index("**Start with**"), page.index('class="rb-sys-file"'))
@@ -169,7 +177,7 @@ class ThePermalinkIsAnIcon(unittest.TestCase):
search showed "scph5501.bin permalink" and screen readers read it."""
def test_no_word_and_out_of_the_search(self):
lines = gs._system_file_card(_sony_file("scph5501.bin", "4"), FileConsumers({"files": {}}))
lines = sitegen_cards._system_file_card(_sony_file("scph5501.bin", "4"), FileConsumers({"files": {}}))
title = lines[2]
link = re.search(r'<a class="rb-permalink"[^>]*>(.*?)</a>', title)
self.assertNotIn("permalink", re.sub(r"<[^>]+>", "", title))
@@ -178,7 +186,7 @@ class ThePermalinkIsAnIcon(unittest.TestCase):
self.assertIn('<use href="#rb-link-icon"/>', link[1])
def test_the_page_draws_the_icon_once(self):
page = gs.generate_system_page(
page = systempages.generate_system_page(
"Sega", {"Saturn": [_sony_file("a.bin", "a"), _sony_file("b.bin", "b")]},
FileConsumers({"files": {}}))
self.assertEqual(page.count('<symbol id="rb-link-icon"'), 1)
@@ -194,7 +202,7 @@ class TheCardGivesTheSizeInBytes(unittest.TestCase):
(2 * 1024 * 1024, "2 MB"), (2304, "2,304 B"), (10, "10 B")):
with self.subTest(size=size):
card = {**_sony_file("scph5501.bin", "4"), "size": size}
title = gs._system_file_card(card, FileConsumers({"files": {}}))[2]
title = sitegen_cards._system_file_card(card, FileConsumers({"files": {}}))[2]
self.assertIn(f'<span class="rb-badge rb-badge-muted">{shown}</span>', title)
@@ -210,7 +218,7 @@ class TheCardLinesSayWhatTheyMean(unittest.TestCase):
platform_destinations={sha1: {"batocera": {"scph5501.bin"}}},
installed={sha1: {"retrobat": {"bios/scph5501.bin"}}},
)
self.lines = gs._system_file_card(_sony_file("scph5501.bin", "4"), self.consumers)
self.lines = sitegen_cards._system_file_card(_sony_file("scph5501.bin", "4"), self.consumers)
def test_labels_and_display_names(self):
text = "\n".join(self.lines)
@@ -235,14 +243,14 @@ class TheCardLinesSayWhatTheyMean(unittest.TestCase):
self.assertEqual(folds, ["<details data-pagefind-ignore>"])
def test_the_page_defines_both_lines(self):
page = gs.generate_system_page("Sega", {"Saturn": [_sony_file("scph5501.bin", "4")]},
page = systempages.generate_system_page("Sega", {"Saturn": [_sony_file("scph5501.bin", "4")]},
self.consumers)
key = page.index("**On the setup's list** names")
self.assertLess(key, page.index('class="rb-sys-file"'))
self.assertIn("**Packed for its emulators by** names", page)
def test_a_file_nothing_reads_says_so(self):
title = gs._system_file_card(_sony_file("GameIndex.yaml", "9"), FileConsumers({"files": {}}))[2]
title = sitegen_cards._system_file_card(_sony_file("GameIndex.yaml", "9"), FileConsumers({"files": {}}))[2]
self.assertIn(">No reader</span>", title)
self.assertNotIn("No reader", self.lines[2])
@@ -254,7 +262,7 @@ class FileFactsAreAGrid(unittest.TestCase):
entry = {**_sony_file("scph5501.bin", "4"), "crc32": "8d8cb7e4",
"provenance": {"redump": {"name": "ps-30a.bin"},
"tosec": {"name": "SCPH-5501 (1996).bin"}}}
lines = gs._system_file_card(entry, FileConsumers({"files": {}}))
lines = sitegen_cards._system_file_card(entry, FileConsumers({"files": {}}))
text = "\n".join(lines)
# One value cell after each label, in the open list and in the fold.
facts = re.findall(r"<dt>[^<]*</dt><dd[^>]*>.*?</dd>", text)
@@ -270,7 +278,7 @@ class FileFactsAreAGrid(unittest.TestCase):
self.assertNotRegex(text, r"(?m)^- ")
def test_collection_path_keeps_its_chip(self):
text = "\n".join(gs._system_file_card(_sony_file("a.bin", "a"), FileConsumers({"files": {}})))
text = "\n".join(sitegen_cards._system_file_card(_sony_file("a.bin", "a"), FileConsumers({"files": {}})))
self.assertIn("<dt>Collection path</dt><dd><code>bios/Sony/PlayStation/a.bin</code>", text)
@@ -282,13 +290,13 @@ class ConsoleHeadingsStartWithTheName(unittest.TestCase):
def test_no_icon_even_when_one_exists(self):
icon = siterender._icon_name("Sony", "PlayStation")
with mock.patch.dict(siterender._icon_available, {icon: True}):
self.assertEqual(gs._console_heading("Sony", "PlayStation"),
self.assertEqual(startwith._console_heading("Sony", "PlayStation"),
"## PlayStation { #playstation }")
def test_no_icon_no_image(self):
icon = siterender._icon_name("Nobody", "Nothing")
with mock.patch.dict(siterender._icon_available, {icon: False}):
self.assertEqual(gs._console_heading("Nobody", "Nothing"), "## Nothing { #nothing }")
self.assertEqual(startwith._console_heading("Nobody", "Nothing"), "## Nothing { #nothing }")
class TheSystemsIndexListsConsoles(unittest.TestCase):
@@ -303,7 +311,7 @@ class TheSystemsIndexListsConsoles(unittest.TestCase):
"Other": {"ScummVM": [_sony_file("c.bin", "c")]},
"Game Engines": {"TheXTech": [_sony_file("d.png", "d")]},
}
page = gs.generate_systems_index(groups)
page = systemsindex.generate_systems_index(groups)
self.assertIn("| [Sony PlayStation](sony.md#playstation) | 1 | [Sony](sony.md) |", page)
self.assertIn("| [Sony PlayStation 2](sony.md#playstation-2) | 1 | [Sony](sony.md) |",
page)
@@ -318,14 +326,14 @@ class TheSystemsIndexListsConsoles(unittest.TestCase):
def test_rows_go_by_name_not_by_maker(self):
groups = {"Sega": {"Saturn": [_sony_file("a.bin", "a")]},
"Atari": {"Lynx": [_sony_file("b.bin", "b")]}}
page = gs.generate_systems_index(groups)
page = systemsindex.generate_systems_index(groups)
self.assertLess(page.index("Atari Lynx"), page.index("Sega Saturn"))
class FindAFileSaysWhatAHashIs(unittest.TestCase):
def test_the_sentence_above_the_box(self):
page = gs.generate_files_page()
page = lookup.generate_files_page()
intro = page.split('<form class="rb-file-lookup"')[0]
self.assertIn("A hash is a fingerprint of a file's contents", intro)
self.assertIn("(../wiki/glossary.md)", intro)
@@ -415,29 +423,29 @@ class TheSectionStartsWithItsOwnConsole(unittest.TestCase):
})
def test_no_dsi_file_on_the_ds_line(self) -> None:
text = "\n".join(gs._start_with(self.files, self.consumers, section=DS))
text = "\n".join(startwith._start_with(self.files, self.consumers, section=DS))
self.assertNotIn("dsi", text)
def test_a_console_its_emulators_run_without_says_so(self) -> None:
self.assertEqual(gs._start_with(self.files, self.consumers, section=DS), [
self.assertEqual(startwith._start_with(self.files, self.consumers, section=DS), [
"**No file needed** with emu-a or emu-b. For full accuracy: "
"[`bios7.bin`](#sha1-777777777777), [`bios9.bin`](#sha1-999999999999).", ""])
def test_the_dsi_section_names_its_file(self) -> None:
lines = gs._start_with(self.files, self.consumers, section=("Nintendo", "Nintendo DSi"))
lines = startwith._start_with(self.files, self.consumers, section=("Nintendo", "Nintendo DSi"))
self.assertEqual(lines, ["**Start with**: [`dsi_bios7.bin`](#sha1-dddddddddddd).", ""])
def test_more_than_three_emulators_are_counted(self) -> None:
hle = {"required": False, "hle_fallback": True, "system": "nintendo-ds"}
consumers = _consumers_with_db({"7" * 40: [(f"emu-{n}", hle) for n in "abcd"]})
self.assertEqual(gs._start_with(self.files[:1], consumers, section=DS)[0],
self.assertEqual(startwith._start_with(self.files[:1], consumers, section=DS)[0],
"**No file needed**: none of its 4 emulators requires one. "
"For full accuracy: [`NDS_Bios7.bin`](#sha1-777777777777).")
def test_a_shipped_file_is_no_start(self) -> None:
consumers = _consumers_with_db({"7" * 40: [("emu-a", {"required": True, "bundled": True,
"system": "nintendo-ds"})]})
self.assertEqual(gs._start_with(self.files[:1], consumers, section=DS), [])
self.assertEqual(startwith._start_with(self.files[:1], consumers, section=DS), [])
class TheNameSetupsWrite(unittest.TestCase):
@@ -448,13 +456,13 @@ class TheNameSetupsWrite(unittest.TestCase):
"system": "nintendo-gba"})]},
destinations={"a" * 40: {"p1": {"gba_bios.bin"}, "p2": {"bios/gba_bios.bin"},
"p3": {"GBA_bios.rom"}}})
self.assertEqual(gs._start_with([f], consumers, section=("Nintendo", "Game Boy Advance")),
self.assertEqual(startwith._start_with([f], consumers, section=("Nintendo", "Game Boy Advance")),
["**Start with**: [`gba_bios.bin`](#sha1-aaaaaaaaaaaa).", ""])
def test_no_setup_then_the_emulators_name(self) -> None:
f = _file_at("x.rom", "b", "bios/Nintendo/Game Boy Advance/x.rom")
consumers = _consumers_with_db({"b" * 40: [("emu-a", {"name": "gba_bios.bin", "required": True})]})
self.assertEqual(gs._setup_name(f, consumers, [("emu-a", {"name": "gba_bios.bin"})]),
self.assertEqual(consolecards._setup_name(f, consumers, [("emu-a", {"name": "gba_bios.bin"})]),
"gba_bios.bin")
@@ -479,14 +487,14 @@ class ArcadeSetsAreNamedWhereverFiled(unittest.TestCase):
}, db_files=[self.aes, neogeo, mega_cd, shader])
def test_the_file_most_emulators_read_leads_and_the_arcade_set_is_linked(self) -> None:
lines = gs._start_with([self.aes], self.consumers, section=("SNK", "Neo Geo"))
lines = startwith._start_with([self.aes], self.consumers, section=("SNK", "Neo Geo"))
link = f"[`neogeo.zip`](/retrobios/files/?sha1={'2' * 40})"
self.assertEqual(lines[0], f"**Start with** {link}. Keep it zipped. "
"mame0, mame1 and mame2 read it.")
self.assertIn("Geolith reads [`aes.zip`](#sha1-111111111111) instead.", lines)
def test_another_consoles_file_or_an_emulators_folder_is_left_out(self) -> None:
text = "\n".join(gs._start_with([self.aes], self.consumers, section=("SNK", "Neo Geo")))
text = "\n".join(startwith._start_with([self.aes], self.consumers, section=("SNK", "Neo Geo")))
self.assertNotIn("bios_CD_U.bin", text)
self.assertNotIn("tfx.glsl", text)
@@ -497,14 +505,14 @@ class ArcadeSetsAreNamedWhereverFiled(unittest.TestCase):
"1" * 40: [("geolith", {"required": True})],
"5" * 40: [(f"emu{n}", {"required": True}) for n in range(3)],
})
cards = gs._console_cards("SNK", [one, many], consumers, set())
cards = consolecards._console_cards("SNK", [one, many], consumers, set())
self.assertIn("sp-s3.sp1", cards[0][1][2])
def test_a_long_list_names_the_first_files(self) -> None:
files = [_file_at(f"rom{i}.bin", "abcdefgh"[i], f"bios/SNK/Neo Geo/rom{i}.bin")
for i in range(8)]
consumers = _consumers_with_db({f["sha1"]: [("emu", {"required": True})] for f in files})
self.assertEqual(gs._start_with(files, consumers, first_below=False)[0],
self.assertEqual(startwith._start_with(files, consumers, first_below=False)[0],
"**Start with**: [`rom0.bin`](#sha1-aaaaaaaaaaaa), [`rom1.bin`](#sha1-bbbbbbbbbbbb), "
"[`rom2.bin`](#sha1-cccccccccccc) and 5 more files.")
@@ -528,8 +536,8 @@ class CardsSayWhichReleaseTheSetMatches(unittest.TestCase):
def card(self) -> str:
f = {"name": "set.zip", "sha1": "e" * 40, "md5": "e" * 32, "size": 4,
"path": str(self.path)}
with mock.patch.object(gs, "_romset_releases", return_value=self.releases):
return "\n".join(gs._system_file_card(f, _consumers_with_db({})))
with mock.patch.object(sitegen_cards, "_romset_releases", return_value=self.releases):
return "\n".join(sitegen_cards._system_file_card(f, _consumers_with_db({})))
def test_the_matching_releases_as_runs(self) -> None:
self.assertIn("<dt>Romset</dt><dd>Same contents as MAME 0.190 to 0.195, 0.220 and "
@@ -544,16 +552,16 @@ class CardsSayWhichReleaseTheSetMatches(unittest.TestCase):
self.assertNotIn("Romset", self.card())
def test_the_snapshots_cover_mame_and_fbneo(self) -> None:
coverage = gs._romset_coverage()
coverage = sitegen_cards._romset_coverage()
self.assertRegex(coverage, r"^MAME 0\.\d+ to 0\.\d+ or FBNeo [\d.]+$")
def test_a_page_of_sets_links_the_version_answer(self) -> None:
f = {"name": "set.zip", "sha1": "e" * 40, "path": "bios/SNK/Neo Geo/set.zip"}
with mock.patch.object(gs, "_romset_releases", return_value=self.releases):
page = gs.generate_system_page("SNK", {"Neo Geo": [f]}, _consumers_with_db({}))
with mock.patch.object(sitegen_cards, "_romset_releases", return_value=self.releases):
page = systempages.generate_system_page("SNK", {"Neo Geo": [f]}, _consumers_with_db({}))
self.assertIn("MAME and FBNeo sets must match the emulator's version. [Which version "
f"each core reads]({gs.ROMSET_FAQ}).", page)
anchor = gs.ROMSET_FAQ.split("#")[1]
f"each core reads]({sitegen_cards.ROMSET_FAQ}).", page)
anchor = sitegen_cards.ROMSET_FAQ.split("#")[1]
faq = (REPO_ROOT / "wiki" / "technical-faq.md").read_text(encoding="utf-8")
self.assertIn("## Which MAME version do the arcade BIOS sets match?", faq)
self.assertEqual(anchor, "which-mame-version-do-the-arcade-bios-sets-match")
@@ -562,7 +570,7 @@ class CardsSayWhichReleaseTheSetMatches(unittest.TestCase):
class ArcadeIsItsOwnGroup(unittest.TestCase):
def test_arcade_rows_under_arcade(self) -> None:
f = {"name": "a.bin", "sha1": "a" * 40, "path": "bios/x/a.bin"}
index = gs.generate_systems_index({"Arcade": {"MAME": [f]}, "Sony": {"PlayStation": [f]}})
index = systemsindex.generate_systems_index({"Arcade": {"MAME": [f]}, "Sony": {"PlayStation": [f]}})
arcade = index.index("## Arcade")
self.assertLess(index.index("## Consoles and computers"), arcade)
self.assertGreater(index.index("[MAME]"), arcade)
@@ -644,9 +652,9 @@ class InstallBoxesCountTowardTheSummary(unittest.TestCase):
def install(console: str, _declared: list) -> list[str]:
return ["x" * box] if console == "Boxed" else []
with mock.patch.object(gs, "_console_install_block", side_effect=install), \
mock.patch.object(gs, "SYSTEM_SUMMARY_HTML", 50_000):
return gs.system_pages("Maker", self.consoles, _consumers_with_db({}), budget=30_000)
with mock.patch.object(sitegen_install, "_console_install_block", side_effect=install), \
mock.patch.object(consolecards, "SYSTEM_SUMMARY_HTML", 50_000):
return systempages.system_pages("Maker", self.consoles, _consumers_with_db({}), budget=30_000)
def test_a_section_with_a_heavy_install_box_moves(self) -> None:
pages = self.pages(20_000)
@@ -709,7 +717,7 @@ class AFileFewRequireIsNoStartFile(unittest.TestCase):
consumers = _consumers_by_system({"1" * 40: [
("emux_gb", {"name": "dmg_boot.bin", "required": True}),
("gambatte", optional), ("mgba", optional), ("sameboy", optional)]})
line = _unlinked(gs._start_with([boot], consumers)[0])
line = _unlinked(startwith._start_with([boot], consumers)[0])
self.assertTrue(line.startswith("**No file needed** with "), line)
self.assertRegex(line, r"Only \S.* requires `dmg_boot.bin`\.$")
@@ -718,14 +726,14 @@ class AFileFewRequireIsNoStartFile(unittest.TestCase):
required = {"name": "scph5501.bin", "required": True}
consumers = _consumers_by_system({"2" * 40: [
("a", required), ("b", required), ("c", {"required": False, "hle_fallback": True})]})
self.assertEqual(_unlinked(gs._start_with([bios], consumers)[0]), "**Start with**: `scph5501.bin`.")
self.assertEqual(_unlinked(startwith._start_with([bios], consumers)[0]), "**Start with**: `scph5501.bin`.")
def test_an_entry_read_for_a_system_with_no_section_is_dropped(self) -> None:
sample = _game_boy_file("ym2608_adpcm_rom.bin", "3", "bios/Nintendo/NES/ym2608_adpcm_rom.bin")
consumers = _consumers_by_system({"3" * 40: [
("fbneo", {"name": "ym2608_adpcm_rom.bin", "required": True,
"system": "no-such-system-anywhere"})]})
self.assertEqual(gs._start_with([sample], consumers, section=("Nintendo", "NES")), [])
self.assertEqual(startwith._start_with([sample], consumers, section=("Nintendo", "NES")), [])
def test_the_home_usually_not_consoles_open_on_no_file_needed(self) -> None:
home = _built_page(DIST / "index.html")
@@ -750,7 +758,7 @@ class TheRomsetLineMatchesByCrc(unittest.TestCase):
main = next((f for sha1, f in db["files"].items() if sha1.startswith("447e2375")), None)
if main is None or not (REPO_ROOT / main["path"]).is_file():
self.skipTest("the main neogeo.zip is not in this checkout")
line = gs._romset_line(main)
line = sitegen_cards._romset_line(main)
self.assertIn("Holds every ROM of MAME 0.177 to 0.289", line)
self.assertNotIn("No match", line)
@@ -767,19 +775,19 @@ class TheNeoGeoOpensOnItsSet(unittest.TestCase):
"5" * 40: [("ares", {"name": "neo-epo.sp1", "required": True,
"system": "snk-neogeo"})],
})
lines = [_unlinked(line) for line in gs._start_with([neogeo, epo], consumers, section=("SNK", "Neo Geo"))]
lines = [_unlinked(line) for line in startwith._start_with([neogeo, epo], consumers, section=("SNK", "Neo Geo"))]
self.assertTrue(lines[0].startswith("**Start with** `neogeo.zip`. Keep it zipped. "))
self.assertIn("ares reads `neo-epo.sp1` instead.", lines)
cards = gs._console_cards("SNK", [epo, neogeo], consumers, set(),
start=gs._start_order([neogeo, epo], consumers,
cards = consolecards._console_cards("SNK", [epo, neogeo], consumers, set(),
start=startwith._start_order([neogeo, epo], consumers,
("SNK", "Neo Geo")))
self.assertIn("neogeo.zip", cards[0][1][2])
def test_a_setup_filing_the_set_elsewhere_gets_its_command(self) -> None:
consumers = _consumers_by_system({}, systems={"a" * 40: {"retroarch": {"arcade"}}})
pairs = gs._install_pairs([("batocera", "snk-neogeo")], "a" * 40, consumers)
pairs = systempages._install_pairs([("batocera", "snk-neogeo")], "a" * 40, consumers)
self.assertIn(("retroarch", "arcade"), pairs)
block = "\n".join(gs._console_install_block("Neo Geo", pairs))
block = "\n".join(sitegen_install._console_install_block("Neo Geo", pairs))
self.assertIn("<li>RetroArch: <code", block)
self.assertIn("--platform retroarch --system arcade</code>", block)
@@ -822,7 +830,7 @@ class EachArcadeBoardHasASection(unittest.TestCase):
md = _built_page(CONTENT / "systems" / "arcade.md")
headings = re.findall(r"^## (.+?) \{", md, re.M)
self.assertIn("Sega NAOMI", headings)
self.assertLess(headings.index("Sega NAOMI"), headings.index(gs.OTHER_ARCADE_LABEL))
self.assertLess(headings.index("Sega NAOMI"), headings.index(startwith.OTHER_ARCADE_LABEL))
class CardsNameEmulatorsByName(unittest.TestCase):
@@ -831,7 +839,7 @@ class CardsNameEmulatorsByName(unittest.TestCase):
def test_the_display_name_is_the_link_text(self) -> None:
sha1 = "6" * 40
consumers = _consumers_by_system({sha1: [("melonds_ds", {"name": "bios7.bin"})]})
link = gs._emulator_links(sha1, consumers)[0]
link = sitegen_cards._emulator_links(sha1, consumers)[0]
self.assertTrue(link.startswith("[melonDS DS]("), link)
def test_no_built_card_link_reads_an_id(self) -> None:
@@ -877,8 +885,8 @@ class PartPagesKnowWhereTheyAre(unittest.TestCase):
for i in range(10)]
consumers = _consumers_by_system({})
with gs.markup.using("mkdocs"):
one = sum(len(line) + 1 for line in gs._system_file_card(files[0], consumers))
pages = gs.system_pages("Sony", {"PlayStation 2": files}, consumers, budget=one * 7)
one = sum(len(line) + 1 for line in sitegen_cards._system_file_card(files[0], consumers))
pages = systempages.system_pages("Sony", {"PlayStation 2": files}, consumers, budget=one * 7)
parts = [stem for stem in pages if stem != "sony"]
self.assertEqual(len(parts), 2)
counts = [pages[stem][0].count('class="rb-sys-file"') for stem in parts]
@@ -888,7 +896,7 @@ class PartPagesKnowWhereTheyAre(unittest.TestCase):
self.assertIn(f"next:\n label: \"PlayStation 2 files rom05.bin to rom09.bin\"\n"
f" link: \"/systems/{parts[1]}/\"", first)
self.assertIn("# PlayStation 2 files rom00.bin to rom04.bin", first)
self.assertIn(f"searchWeight: {gs._part_weight()}", first)
self.assertIn(f"searchWeight: {systempages._part_weight()}", first)
def _consoles(page: str) -> list[str]:
@@ -909,7 +917,7 @@ class ConsolesFieldNamesMachinesOnce(unittest.TestCase):
def test_no_emulator_folder_is_a_console(self) -> None:
for maker in ("Other", "Game Engines"):
page = gs.system_pages(maker, {"dolphin": [_game_boy_file("a.bin", "a")]}, _consumers_by_system({}))
page = systempages.system_pages(maker, {"dolphin": [_game_boy_file("a.bin", "a")]}, _consumers_by_system({}))
self.assertEqual(_consoles(page[gs._slug(maker)][0]), [], maker)
def test_a_console_with_its_own_page_is_left_to_it(self) -> None:
@@ -918,15 +926,15 @@ class ConsolesFieldNamesMachinesOnce(unittest.TestCase):
small = [_game_boy_file("pico.bin", "p", "bios/Sega/Pico/pico.bin")]
consumers = _consumers_by_system({})
with gs.markup.using("mkdocs"):
one = sum(len(line) + 1 for line in gs._system_file_card(big[0], consumers))
one = sum(len(line) + 1 for line in sitegen_cards._system_file_card(big[0], consumers))
# Sega splits by size. Every Sony console has a page whatever its size.
pages = gs.system_pages("Sega", {"Saturn": big, "Pico": small},
pages = systempages.system_pages("Sega", {"Saturn": big, "Pico": small},
consumers, budget=one * 12)
self.assertIn("sega-saturn", pages)
self.assertEqual(_consoles(pages["sega"][0]), ["Pico"])
self.assertEqual(_consoles(pages["sega-saturn"][0]), ["Saturn"])
self.addCleanup(gs.reset_console_pages)
sony = gs.system_pages("Sony", {"PlayStation": big, "PocketStation": small},
sony = systempages.system_pages("Sony", {"PlayStation": big, "PocketStation": small},
consumers, budget=one * 12)
self.assertEqual(_consoles(sony["sony"][0]), [])
self.assertEqual(_consoles(sony["sony-pocketstation"][0]), ["PocketStation"])
@@ -936,7 +944,7 @@ class OneLineBeforeTheFirstConsole(unittest.TestCase):
"""6.8: four paragraphs, word for word on every maker's page."""
def test_the_intro_is_one_line_and_the_legend_closed(self) -> None:
page = gs.generate_system_page("SNK", {"Neo Geo": [_game_boy_file("a.bin", "a")]}, _consumers_by_system({}))
page = systempages.generate_system_page("SNK", {"Neo Geo": [_game_boy_file("a.bin", "a")]}, _consumers_by_system({}))
body = page.split("# SNK\n", 1)[1]
before = body[:body.index("## Neo Geo")]
self.assertTrue(before.lstrip().startswith(
@@ -954,7 +962,7 @@ class SetupsGroupedByPlace(unittest.TestCase):
def test_one_line_per_place(self) -> None:
places = [("Batocera", "b.md", ["scph5501.bin"]), ("KNULLI", "k.md", ["scph5501.bin"]),
("RetroDECK", "r.md", ["bios/scph5501.bin"]), ("EmuDeck", "e.md", [])]
self.assertEqual(gs._places_lines(places), [
self.assertEqual(sitegen_cards._places_lines(places), [
"<code>scph5501.bin</code>: [Batocera](b.md), [KNULLI](k.md)",
"<code>bios/scph5501.bin</code>: [RetroDECK](r.md)",
"[EmuDeck](e.md)",
@@ -1025,7 +1033,7 @@ class AStartFileIsNoOnesExtra(unittest.TestCase):
"1" * 40: [(e, {"name": "naomi.zip", "required": True}) for e, _ in both + extra],
"2" * 40: both + extra,
})
self.assertEqual([_unlinked(line) for line in gs._start_with([naomi, hod2], consumers)],
self.assertEqual([_unlinked(line) for line in startwith._start_with([naomi, hod2], consumers)],
["**Start with**: `naomi.zip`.", ""])
def test_the_naomi_page_opens_on_naomi_zip(self) -> None:
@@ -1037,7 +1045,7 @@ class AStartFileIsNoOnesExtra(unittest.TestCase):
"3" * 40: [(e, {"name": "bios7.bin", "required": True}) for e in ("a", "b")],
"4" * 40: [(e, {"name": "bios9.bin", "required": True}) for e in ("a", "b")],
})
self.assertEqual(_unlinked(gs._start_with([bios7, bios9], consumers)[0]),
self.assertEqual(_unlinked(startwith._start_with([bios7, bios9], consumers)[0]),
"**Start with**: `bios7.bin`, `bios9.bin`.")
def test_some_files_each_is_not_every_file_for_one(self) -> None:
@@ -1049,7 +1057,7 @@ class AStartFileIsNoOnesExtra(unittest.TestCase):
reads["1" * 40].append(("bsnes", {"name": "chip1.rom", "required": True}))
reads["2" * 40].append(("jgenesis", {"name": "chip2.rom", "required": True}))
reads["3" * 40].append(("jgenesis", {"name": "chip3.rom", "required": True}))
line = gs._start_with(files, _consumers(reads))[0]
line = startwith._start_with(files, _consumers(reads))[0]
self.assertIn("require some of these files: ", line)
@@ -1063,7 +1071,7 @@ class OtherNamesForOneSlotReadAsAlternatives(unittest.TestCase):
for e in ("mesen", "nestopia", "fceumm")],
"6" * 40: [("fbneo", {"name": "fdsbios.zip", "required": True})],
})
self.assertEqual(_unlinked(gs._start_with([disk, fds], consumers)[0]),
self.assertEqual(_unlinked(startwith._start_with([disk, fds], consumers)[0]),
"**Start with**: `disksys.rom`. FinalBurn Neo reads `fdsbios.zip` instead.")
def test_a_card_read_under_another_name_says_both(self) -> None:
@@ -1073,7 +1081,7 @@ class OtherNamesForOneSlotReadAsAlternatives(unittest.TestCase):
"7" * 40: [("c", {"name": "short.rom", "required": True})],
})
self.assertIn("reads `long name (1986).bin` (as `short.rom`) instead.",
_unlinked(gs._start_with([disk, card], consumers)[0]))
_unlinked(startwith._start_with([disk, card], consumers)[0]))
def test_a_regional_line_names_one_file_per_reader(self) -> None:
mega_cd = _system_page("sega").split("{ #mega-cd }", 1)[1].split("\n## ", 1)[0]
@@ -1199,7 +1207,7 @@ class EnginesGoByEngine(unittest.TestCase):
def test_moved_pages_redirect(self) -> None:
if not SYSTEMS.is_dir():
self.skipTest("pages not generated")
for old, target in gs.SYSTEM_PAGES_MOVED.items():
for old, target in systemsindex.SYSTEM_PAGES_MOVED.items():
new = target.partition("#")[0]
written = [path for path in (CONTENT / old, (CONTENT / old).with_suffix(".mdx"))
if path.exists()]
@@ -1224,9 +1232,9 @@ class OneLabelOnceOnABoardPage(unittest.TestCase):
"""6.7, 6.8, 6.9, 6.10: the words a board or part page repeats."""
def test_a_label_naming_files_installs_these_files(self) -> None:
block = "\n".join(gs._console_install_block("Other arcade files", [("mame", "arcade")]))
block = "\n".join(sitegen_install._console_install_block("Other arcade files", [("mame", "arcade")]))
self.assertIn("<summary>Install these files</summary>", block)
block = "\n".join(gs._console_install_block("Sega NAOMI", [("mame", "arcade")]))
block = "\n".join(sitegen_install._console_install_block("Sega NAOMI", [("mame", "arcade")]))
self.assertIn("<summary>Install the files of Sega NAOMI</summary>", block)
def test_a_board_page_has_no_heading_of_its_name(self) -> None:
@@ -1260,26 +1268,26 @@ class EachFileDownloadsFromItsCard(unittest.TestCase):
from packs.crossref import FileConsumers
f = _naomi_file("apple2-asoft-auto.rom", "3", "bios/Apple/Apple II/apple2-asoft-auto.rom")
title = next(line for line in gs._system_file_card(f, FileConsumers({"files": {}}))
title = next(line for line in sitegen_cards._system_file_card(f, FileConsumers({"files": {}}))
if "rb-file-title" in line)
self.assertIn('class="rb-download" href="https://raw.githubusercontent.com/Abdess/'
'retrobios/main/bios/Apple/Apple%20II/apple2-asoft-auto.rom"', title)
self.assertIn('aria-label="Download apple2-asoft-auto.rom"', title)
facts = "\n".join(gs._system_file_card(f, FileConsumers({"files": {}})))
facts = "\n".join(sitegen_cards._system_file_card(f, FileConsumers({"files": {}})))
self.assertNotIn("(download)", facts)
def test_a_start_name_leads_to_its_card(self) -> None:
line = gs._link_held_names("- **Apple II**: `a.rom`, `b.rom`.",
line = startwith._link_held_names("- **Apple II**: `a.rom`, `b.rom`.",
{"a.rom": "a" * 40, "b.rom": "b" * 40}, {"a" * 40})
self.assertEqual(line, "- **Apple II**: [`a.rom`](#sha1-aaaaaaaaaaaa), `b.rom`.")
def test_a_card_on_another_part_is_reached_by_its_permalink(self) -> None:
full = next(iter(json.loads((REPO_ROOT / "database.json").read_text())["files"]))
here = f'[`x.rom`](#sha1-{full[:12]})'
away = gs._cards_elsewhere(here)
away = decorate._cards_elsewhere(here)
self.assertEqual(away, f"[`x.rom`](/retrobios/files/?sha1={full})")
held = here + f'\n<h3 id="sha1-{full[:12]}" class="rb-file-title">'
self.assertEqual(gs._cards_elsewhere(held), held)
self.assertEqual(decorate._cards_elsewhere(held), held)
def test_every_start_name_on_the_built_apple_page_links(self) -> None:
page = next(SYSTEMS.glob("apple.md*"), None)
+4 -3
View File
@@ -92,9 +92,9 @@ class WikiSourceHeadings(unittest.TestCase):
class PlatformDetails(unittest.TestCase):
def test_lists_and_flags_read_as_prose(self):
import generate_site
from sitegen import fields
lines = generate_site._render_platform_details(
lines = fields._render_platform_details(
{"platform_details": {"megacd": {
"extensions_tried": [".bin", ".zip"],
"hle_available": False,
@@ -361,7 +361,8 @@ class TheSitemapIsAnnouncedWhereCrawlersLook(unittest.TestCase):
class TheHomeTitleSaysWhatTheSiteIs(unittest.TestCase):
def test_not_the_site_name_twice(self):
from generate_site import SITE_NAME, _browser_title
from sitegen.config import SITE_NAME
from sitegen.descriptions import _browser_title
title = _browser_title(Path("index.md"), SITE_NAME)
self.assertNotEqual(title, SITE_NAME)
+4 -3
View File
@@ -24,7 +24,8 @@ import re
import zlib
from pathlib import Path
import generate_site
from sitegen import gaps
from sitegen import lookup
from sitegen import wanted as sitewanted
from resolve import review
import yaml
@@ -451,7 +452,7 @@ class EveryFolderIsTheReviewsFolder(_World):
self.assertEqual(sitewanted.upload_href(sitewanted.UPLOAD_ROOT, "bios/Maker/Sub Dir/"),
"https://github.com/Abdess/retrobios/upload/main/bios/Maker/Sub%20Dir")
self.assertEqual(sitewanted.upload_href(sitewanted.UPLOAD_ROOT, ""),
generate_site.UPLOAD_URL)
gaps.UPLOAD_URL)
def _node(script: str) -> str:
@@ -527,7 +528,7 @@ class TheTwoPagesLinkEachOther(unittest.TestCase):
sends a reader to the other in one line."""
def test_links(self):
self.assertIn("[See if it is wanted](../wanted.md)", generate_site.generate_files_page())
self.assertIn("[See if it is wanted](../wanted.md)", lookup.generate_files_page())
self.assertIn("[Find or check a file](files/index.md)", sitewanted.page(2, 1))
+20 -15
View File
@@ -13,7 +13,12 @@ import tests
import unittest
import generate_site
from sitegen import cards
from sitegen import emulatorpage
from sitegen import nav as sitegen_nav
from sitegen import parts as sitegen_parts
from sitegen import platformfiles
from sitegen import systempages
from sitegen import starlight as sitestarlight
from sitegen import render as siterender
from sitegen import markup
@@ -36,7 +41,7 @@ class ASystemPageOverItsBudgetIsSplit(unittest.TestCase):
}
def _pages(self, budget: int) -> dict:
return generate_site.system_pages(
return systempages.system_pages(
"Maker", self.consoles, FileConsumers({"files": {}}), budget=budget)
def test_a_page_within_its_budget_stays_whole(self):
@@ -83,18 +88,18 @@ class ASystemPageOverItsBudgetIsSplit(unittest.TestCase):
class AnEmulatorWithTooManyCardsIsSplit(unittest.TestCase):
def test_parts_are_balanced_and_rows_keep_the_anchors(self):
files = [{"name": f"set{i:04d}.zip", "required": i % 2 == 0, "category": "bios_zip"}
for i in range(generate_site.EMULATOR_CARDS_PER_PAGE * 2 + 1)]
parts = generate_site.emulator_parts("big", files)
for i in range(emulatorpage.EMULATOR_CARDS_PER_PAGE * 2 + 1)]
parts = emulatorpage.emulator_parts("big", files)
self.assertEqual([stem for stem, _ in parts], ["big-files-1", "big-files-2", "big-files-3"])
sizes = [len(entries) for _, entries in parts]
self.assertLessEqual(max(sizes) - min(sizes), 1)
self.assertEqual(generate_site.emulator_parts("small", files[:3]), [])
self.assertEqual(emulatorpage.emulator_parts("small", files[:3]), [])
pages = generate_site.emulator_pages(
pages = emulatorpage.emulator_pages(
"big", {"emulator": "Big", "type": "standalone", "files": files}, {"files": {}})
self.assertEqual(sorted(pages), ["big", "big-files-1", "big-files-2", "big-files-3"])
main = pages["big"]
anchors = generate_site.emulator_file_anchors(files)
anchors = cards.emulator_file_anchors(files)
for anchor in anchors:
self.assertIn(f'<a id="{anchor}" href=', main)
self.assertIn('class="rb-card-index"', main)
@@ -102,9 +107,9 @@ class AnEmulatorWithTooManyCardsIsSplit(unittest.TestCase):
self.assertIn(f'id="{anchors[0]}" class="rb-file-title"', pages["big-files-1"])
def test_cards_are_linked_on_the_page_that_holds_them(self):
files = [{"name": f"set{i:04d}.zip"} for i in range(generate_site.EMULATOR_CARDS_PER_PAGE + 1)]
generate_site.plan_emulator_pages({"big": {"files": files}})
anchors = generate_site.emulator_file_anchors(files)
files = [{"name": f"set{i:04d}.zip"} for i in range(emulatorpage.EMULATOR_CARDS_PER_PAGE + 1)]
emulatorpage.plan_emulator_pages({"big": {"files": files}})
anchors = cards.emulator_file_anchors(files)
self.assertEqual(siterender.emulator_card_page("big", anchors[-1]), "big-files-2")
self.assertEqual(siterender.emulator_card_page("other", "file-x"), "other")
@@ -114,13 +119,13 @@ class APlatformSystemOverItsBudgetMoves(unittest.TestCase):
files = [{"name": f"f{i:04d}.zip", "status": "ok"} for i in range(40)]
config = {("arcade", f["name"]): [{"name": f["name"], "md5": "a" * 32}] for f in files}
moved: dict[str, str] = {}
budget = generate_site.PLATFORM_SECTION_BUDGET
generate_site.PLATFORM_SECTION_BUDGET = 5
budget = sitegen_parts.PLATFORM_SECTION_BUDGET
sitegen_parts.PLATFORM_SECTION_BUDGET = 5
try:
lines = generate_site._render_platform_systems(
lines = platformfiles._render_platform_systems(
{"arcade": files}, config, {}, ("deck", "Deck"), moved)
finally:
generate_site.PLATFORM_SECTION_BUDGET = budget
sitegen_parts.PLATFORM_SECTION_BUDGET = budget
text = "\n".join(lines)
self.assertIn("{ #arcade }", text)
self.assertIn("](deck-arcade.md)", text)
@@ -136,7 +141,7 @@ class TheNavigationOpensOneInitial(unittest.TestCase):
for key, name in (("a1", "Alpha"), ("b1", "Beta"), ("b2", "bravo"), ("z", "Zed"),
("n", "2ship"))
}
nav = generate_site._emulator_nav(profiles)
nav = sitegen_nav._emulator_nav(profiles)
self.assertEqual(nav[1:], [
{"0 to 9": [{"2ship": "emulators/n.md"}]},
{"A": [{"Alpha": "emulators/a1.md"}]},
+4 -3
View File
@@ -25,11 +25,12 @@ class WhichPackRows(unittest.TestCase):
def test_platform_rows_name_their_own_pack(self):
"""A row links its own get/ page, never another setup's and never a
release asset: the asset URL dies with its tag."""
import generate_site
from sitegen import install
from sitegen import whichpack
import release_record
record = release_record.load_advertised()
page = generate_site.generate_which_pack()
page = whichpack.generate_which_pack()
row = re.compile(r"^\| \[[^\]]+\]\(platforms/([a-z0-9]+)\.md\) \|(.*)$", re.M)
get = re.compile(r'href="get/([a-z0-9]+)\.md"')
checked = 0
@@ -42,6 +43,6 @@ class WhichPackRows(unittest.TestCase):
if pack:
checked += 1
self.assertEqual(linked, {key})
elif not generate_site.has_release_pack(key):
elif not install.has_release_pack(key):
self.assertIn(f"No ZIP. [Use the command](platforms/{key}.md#install).", rest)
self.assertGreater(checked, 3)