refactor: raise download errors to the command

release.latest no longer reads RETROBIOS_API at import: download.py checks
it and passes the endpoint to get_latest_release. The release modules raise
DownloadError and hand progress lines to a callback, so download.py reports
every failure on stderr with exit code 1, the missing release included.
This commit is contained in:
Abdessamad Derraz committed 2026-11-22 02:26:45 +01:00
1 parent ebabb03e74
commit 758bc76b6f
6 files changed
+173 -81

No files matched your search

+54 -47
View File
@@ -29,13 +29,19 @@ from pathlib import Path
sys.path.insert(0, os.path.dirname(__file__))
from core.upstream import UpstreamError
from core.ziptools import safe_extract_zip
from release.latest import get_latest_release
from release.downloaderror import DownloadError
from release.latest import DEFAULT_API, checked_url, get_latest_release
from release.packfetch import fetch_checksums, fetch_pack, make_staging
from release.packgroups import find_pack, list_platforms
from release.packinfo import exit_without_pack, show_info
FETCH_ERRORS = (
urllib.error.URLError, OSError, http.client.HTTPException, UpstreamError,
json.JSONDecodeError,
)
def main() -> None:
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
allow_abbrev=False,
description="Download BIOS packs from GitHub Releases",
@@ -53,62 +59,63 @@ To check files already in place, use: python install.py --check
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()
return parser
if args.list:
try:
release = get_latest_release()
platforms = list_platforms(release)
def main() -> None:
parser = build_parser()
args = parser.parse_args()
try:
api = checked_url(os.environ.get("RETROBIOS_API", DEFAULT_API), "RETROBIOS_API")
if args.list:
try:
platforms = list_platforms(get_latest_release(api))
except FETCH_ERRORS as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
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)
return
if not args.platform:
parser.error("Platform name required (use --list to see options)")
try:
release = get_latest_release(api)
except FETCH_ERRORS as e:
print(f"Error fetching release info: {e}", file=sys.stderr)
sys.exit(1)
return
if not args.platform:
parser.error("Platform name required (use --list to see options)")
if args.info:
show_info(args.platform, release)
return
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)
if not args.dest:
parser.error("Destination directory required")
pack = find_pack(release, args.platform)
if not pack:
exit_without_pack(args.platform, release)
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)
print(f"Extracting to {dest}/...")
for archive in archives:
safe_extract_zip(str(archive), str(dest))
finally:
shutil.rmtree(staging, ignore_errors=True)
except DownloadError as exc:
print(exc, 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:
exit_without_pack(args.platform, release)
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!")