mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 01:57:48 -06:00
refactor: build the readme zip table in one place
This commit is contained in:
1 parent
be63c6575a
commit
8db5bf6cf0
5 files changed
+66
-65
No files matched your search
@@ -8,8 +8,7 @@ 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
|
||||
from sitegen.readme import release_state, release_totals
|
||||
|
||||
|
||||
# Platform pages
|
||||
@@ -66,9 +65,11 @@ def setup_table(coverages: dict) -> list[str]:
|
||||
]
|
||||
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, releaserecord.load_advertised())
|
||||
zipped = (f"{files:,}" if files
|
||||
else "No ZIP yet" if has_release_pack(name) else "No ZIP")
|
||||
record = releaserecord.load_advertised()
|
||||
state = release_state(name, record)
|
||||
files, _size = release_totals(name, record)
|
||||
zipped = ("No ZIP" if state == "none" else "No ZIP yet" if state == "pending"
|
||||
else f"{files:,}" if files else "-")
|
||||
lines.append(
|
||||
f"| [{cov['platform']}](../platforms/{name}.md) | {listed} | {zipped} | "
|
||||
f"{check_label(cov['mode'], cov['config'].get('hash_rule'))} |"
|
||||
|
||||
+39
-46
@@ -15,7 +15,7 @@ from devtools import prchecks
|
||||
from model import releaserecord
|
||||
from core.artifacts import write_if_changed
|
||||
from core.cli import InputMissing
|
||||
from core.paths import DB_FILE, PLATFORMS_DIR, REPO_ROOT
|
||||
from core.paths import DB_FILE, REPO_ROOT
|
||||
from core.sizes import size_text
|
||||
from core.upstream import forge_headers
|
||||
from installer_build.module import installer_module
|
||||
@@ -30,7 +30,7 @@ from model.systems import system_index
|
||||
from packs.coverage import verify_platform
|
||||
from resolve.cores import resolve_platform_cores
|
||||
from resolve.review import LARGE_FILE_ISSUE_URL
|
||||
from sitegen.install import display_name, platform_display
|
||||
from sitegen.install import display_name, has_release_pack, platform_display
|
||||
|
||||
|
||||
# The repository's profiles wherever the script is run from: a bare
|
||||
@@ -240,6 +240,18 @@ def release_totals(platform_name: str, record: dict) -> tuple[int | None, int |
|
||||
return pack["files"], pack["extracted_size"]
|
||||
|
||||
|
||||
def release_state(platform_name: str, record: dict) -> str:
|
||||
""""none" for a setup no release publishes a ZIP for (`release_pack`),
|
||||
"pending" for one the recorded release carries no pack for, added since,
|
||||
else "released". No recorded tag, no release to be missing from."""
|
||||
if not has_release_pack(platform_name):
|
||||
return "none"
|
||||
pack = releaserecord.pack_for(platform_name, record)
|
||||
if record.get("tag") and not (pack and pack.get("assets")):
|
||||
return "pending"
|
||||
return "released"
|
||||
|
||||
|
||||
NO_PACK = "Use the command"
|
||||
|
||||
|
||||
@@ -282,7 +294,7 @@ def asset_links(
|
||||
def download_links(
|
||||
platform_name: str, record: dict, label: str, attrs: str = "",
|
||||
button: Callable[[str, str], str] | None = None,
|
||||
site: str = "", platforms_dir: str = PLATFORMS_DIR, page: str | None = None,
|
||||
site: str = "", page: str | None = None,
|
||||
) -> str:
|
||||
"""The download cell of a platform: its permanent get/ page.
|
||||
|
||||
@@ -299,10 +311,10 @@ def download_links(
|
||||
def link(text: str) -> str:
|
||||
return button(text, page) if button else f"[{text}]({page}){attrs}"
|
||||
|
||||
if (load_platform_registry(platforms_dir).get(platform_name) or {}).get("release_pack") is not True:
|
||||
state = release_state(platform_name, record)
|
||||
if state == "none":
|
||||
return link(NO_PACK)
|
||||
pack = releaserecord.pack_for(platform_name, record)
|
||||
if record.get("tag") and not (pack and pack.get("assets")):
|
||||
if state == "pending":
|
||||
return f"No ZIP yet: {link(NO_PACK.lower())}"
|
||||
return link(label)
|
||||
|
||||
@@ -369,30 +381,31 @@ def download_table(
|
||||
extract_paths: dict[str, str],
|
||||
record: dict,
|
||||
) -> list[str]:
|
||||
"""One row per platform: what its released pack holds and where it extracts."""
|
||||
"""The README's ZIP table: one row per setup the release carries a pack
|
||||
for, then the sentence linking every other setup to its get/ page."""
|
||||
by_name = sorted(coverages, key=lambda n: coverages[n]["platform"])
|
||||
released = [name for name in by_name if release_totals(name, record)[0]]
|
||||
lines = [
|
||||
"| Platform | Files | Extracted size | Extract to | Download |",
|
||||
"|----------|------:|---------------:|-----------|----------|",
|
||||
"| Setup | Files | Size | Unzip into | Download |",
|
||||
"|-------|------:|-----:|------------|----------|",
|
||||
]
|
||||
for name, cov in sorted(coverages.items(), key=lambda x: x[1]["platform"]):
|
||||
for name in released:
|
||||
files, size = release_totals(name, record)
|
||||
display = coverages[name]["platform"]
|
||||
lines.append(
|
||||
f"| {cov['platform']} | {f'{files:,}' if files else '-'} |"
|
||||
f" {size_text(size) if size else '-'} |"
|
||||
f" {extract_paths.get(cov['platform'], '')} |"
|
||||
f"| {display} | {files:,} | {size_text(size) if size else '-'} |"
|
||||
f" {extract_paths.get(display, '')} |"
|
||||
f" {download_links(name, record, 'Download', site=SITE_URL)} |"
|
||||
)
|
||||
return lines
|
||||
|
||||
|
||||
def no_pack_line() -> str:
|
||||
"""Why some rows read "Use the command", in one sentence."""
|
||||
return (
|
||||
"ZIPs are made for the setups most people download. The others read"
|
||||
f" \"{NO_PACK}\": the installer above installs every file for them and"
|
||||
" checks each one, and `--dry-run` shows what it would install"
|
||||
f" ([why no ZIP]({SITE_URL}wiki/faq/#why-is-there-no-zip-for-my-setup))."
|
||||
)
|
||||
others = [name for name in by_name if name not in released]
|
||||
return [
|
||||
*lines,
|
||||
"",
|
||||
"ZIPs are made for the setups most people download. The others install with the line"
|
||||
" above, and each page gives the command: "
|
||||
+ ", ".join(f"[{coverages[name]['platform']}]({SITE_URL}get/{name}/)" for name in others)
|
||||
+ ".",
|
||||
]
|
||||
|
||||
|
||||
def _names_list(coverages: dict) -> str:
|
||||
@@ -598,8 +611,6 @@ def generate_readme(db: dict, platforms_dir: str, db_path: str = DB_FILE) -> str
|
||||
# once carried (coverage, collection, build commands) are the site's.
|
||||
record = releaserecord.load_advertised(platforms_dir=platforms_dir)
|
||||
extract_paths = _extract_cells(platforms_dir)
|
||||
released = [name for name in sorted(coverages, key=lambda n: coverages[n]["platform"])
|
||||
if release_totals(name, record)[0]]
|
||||
lines = [
|
||||
'<p align="center">',
|
||||
" <picture>",
|
||||
@@ -663,25 +674,7 @@ def generate_readme(db: dict, platforms_dir: str, db_path: str = DB_FILE) -> str
|
||||
"",
|
||||
"The Files column counts what a pack holds once unzipped.",
|
||||
"",
|
||||
"| Setup | Files | Size | Unzip into | Download |",
|
||||
"|-------|------:|-----:|------------|----------|",
|
||||
]
|
||||
for name in released:
|
||||
files, size = release_totals(name, record)
|
||||
display = coverages[name]["platform"]
|
||||
lines.append(
|
||||
f"| {display} | {files:,} | {size_text(size) if size else '-'} |"
|
||||
f" {extract_paths.get(display, '')} |"
|
||||
f" {download_links(name, record, 'Download', site=SITE_URL)} |"
|
||||
)
|
||||
others = [name for name in sorted(coverages, key=lambda n: coverages[n]["platform"])
|
||||
if name not in released]
|
||||
lines.extend([
|
||||
"",
|
||||
"ZIPs are made for the setups most people download. The others install with the line"
|
||||
" above, and each page gives the command: "
|
||||
+ ", ".join(f"[{coverages[name]['platform']}]({SITE_URL}get/{name}/)" for name in others)
|
||||
+ ".",
|
||||
*download_table(coverages, extract_paths, record),
|
||||
"",
|
||||
"Unzip into the BIOS folder, files straight in it. A big pack comes in parts"
|
||||
" (`Pack.part1of2.zip`): download every part"
|
||||
@@ -726,7 +719,7 @@ def generate_readme(db: dict, platforms_dir: str, db_path: str = DB_FILE) -> str
|
||||
"",
|
||||
"</details>",
|
||||
"",
|
||||
])
|
||||
]
|
||||
|
||||
contributors = fetch_contributors()
|
||||
if not contributors:
|
||||
|
||||
@@ -25,8 +25,8 @@ 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_text, setup_picker
|
||||
from sitegen.install import installer_module, has_release_pack, platform_display
|
||||
from sitegen.readme import NO_PACK, download_links
|
||||
from sitegen.install import installer_module, platform_display
|
||||
from sitegen.readme import NO_PACK, download_links, release_state
|
||||
|
||||
|
||||
# Build cross-reference indexes
|
||||
@@ -76,11 +76,11 @@ def _folder_cell(name: str, guide: Guide, prefix: str = "") -> str:
|
||||
|
||||
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)."
|
||||
state = release_state(name, record)
|
||||
if state != "released":
|
||||
no_zip = "No ZIP yet" if state == "pending" else "No ZIP"
|
||||
return f"{no_zip}. [{NO_PACK}]({prefix}platforms/{name}.md#install)."
|
||||
pack = releaserecord.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),
|
||||
@@ -233,9 +233,7 @@ def generate_which_pack() -> str:
|
||||
*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, releaserecord.pack_for(key, record)) for key in registry))
|
||||
if record.get("tag") and pending:
|
||||
if any(release_state(key, record) == "pending" for key in registry):
|
||||
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})", ""]
|
||||
|
||||
Reference in new issue
Block a user