mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
147 lines
4.8 KiB
Python
147 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Download BIOS packs from GitHub Releases.
|
|
|
|
Cross-platform tool (Linux/macOS/Windows) using only Python stdlib.
|
|
|
|
A pack over the release asset limit is published in several files, so a
|
|
platform is a group of assets rather than a single one. The parts are each
|
|
a ZIP (`.part1of2.zip`), checked and extracted one after the other. Releases
|
|
up to v2026.09.04 carry byte ranges of one archive instead (`.zip.001`,
|
|
`.zip.002`), which are joined first.
|
|
|
|
Usage:
|
|
python scripts/download.py --list # List platforms
|
|
python scripts/download.py retroarch ~/path/ # Download pack
|
|
python scripts/download.py --info retroarch # Show pack info
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import http.client
|
|
import json
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import urllib.error
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, os.path.dirname(__file__))
|
|
from core.sizes import size_text
|
|
from core.text import count_text
|
|
from core.upstream import UpstreamError
|
|
from core.ziptools import safe_extract_zip
|
|
from release.latest import get_latest_release
|
|
from release.packfetch import fetch_checksums, fetch_pack, make_staging
|
|
from release.packgroups import find_pack, list_platforms
|
|
|
|
# A release publishes packs for the setups most people download. The others
|
|
# are served file by file by the installer.
|
|
NO_PACK_HINT = (
|
|
"A setup without a pack is served by the installer:\n"
|
|
" curl -fsSL https://abdess.github.io/retrobios/i | sh -s -- --platform <name>"
|
|
)
|
|
|
|
|
|
def show_info(platform: str, release: dict) -> None:
|
|
"""Show pack information for a platform."""
|
|
pack = find_pack(release, platform)
|
|
if not pack:
|
|
print(f"Platform '{platform}' not found in release.")
|
|
print("Available:", ", ".join(list_platforms(release)))
|
|
print(NO_PACK_HINT)
|
|
sys.exit(1)
|
|
|
|
print(f" Platform: {pack.platform}")
|
|
print(f" File: {pack.name}")
|
|
print(f" Parts: {count_text(len(pack.parts), 'part')}")
|
|
print(f" Size: {pack.size:,} bytes ({size_text(pack.size)})")
|
|
for part in pack.parts:
|
|
print(f" {part['name']} ({part.get('size', 0):,} bytes)")
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(
|
|
allow_abbrev=False,
|
|
description="Download BIOS packs from GitHub Releases",
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
epilog="""
|
|
Examples:
|
|
%(prog)s --list List available platforms
|
|
%(prog)s retroarch ~/RetroArch/system Download RetroArch pack
|
|
%(prog)s --info retroarch Show pack info
|
|
|
|
To check files already in place, use: python install.py --check
|
|
""",
|
|
)
|
|
parser.add_argument("platform", nargs="?", help="Platform name")
|
|
parser.add_argument("dest", nargs="?", help="Destination directory")
|
|
parser.add_argument("--list", action="store_true", help="List available platforms")
|
|
parser.add_argument("--info", action="store_true", help="Show platform info")
|
|
args = parser.parse_args()
|
|
|
|
if args.list:
|
|
try:
|
|
release = get_latest_release()
|
|
platforms = list_platforms(release)
|
|
if platforms:
|
|
print("Available platforms:")
|
|
for p in platforms:
|
|
print(f" - {p}")
|
|
else:
|
|
print("No platform packs found in latest release")
|
|
except (
|
|
urllib.error.URLError,
|
|
urllib.error.HTTPError,
|
|
OSError,
|
|
http.client.HTTPException,
|
|
UpstreamError,
|
|
json.JSONDecodeError,
|
|
) as e:
|
|
print(f"Error: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
return
|
|
|
|
if not args.platform:
|
|
parser.error("Platform name required (use --list to see options)")
|
|
|
|
try:
|
|
release = get_latest_release()
|
|
except (urllib.error.URLError, OSError, http.client.HTTPException, UpstreamError,
|
|
json.JSONDecodeError) as e:
|
|
print(f"Error fetching release info: {e}", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
if args.info:
|
|
show_info(args.platform, release)
|
|
return
|
|
|
|
if not args.dest:
|
|
parser.error("Destination directory required")
|
|
|
|
pack = find_pack(release, args.platform)
|
|
if not pack:
|
|
print(f"Platform '{args.platform}' not found in release.")
|
|
print("Available:", ", ".join(list_platforms(release)))
|
|
print(NO_PACK_HINT)
|
|
sys.exit(1)
|
|
|
|
dest = Path(os.path.expanduser(args.dest))
|
|
dest.mkdir(parents=True, exist_ok=True)
|
|
|
|
staging = make_staging(dest)
|
|
try:
|
|
archives = fetch_pack(pack, staging, fetch_checksums(release))
|
|
print(f"Extracting to {dest}/...")
|
|
for archive in archives:
|
|
safe_extract_zip(str(archive), str(dest))
|
|
finally:
|
|
shutil.rmtree(staging, ignore_errors=True)
|
|
print("Done!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from core.cli import run_cli
|
|
|
|
run_cli(main)
|