dl/commands/retrodeck.py
Michel Roux fec6b8e6f9
All checks were successful
dl / lint (push) Successful in 1m40s
dl / docker (push) Successful in 2m42s
feat: add retrodeck bios scanner
2025-01-23 21:10:25 +01:00

46 lines
1.5 KiB
Python

#!/usr/bin/env python3
from argparse import ArgumentParser
from csv import reader
from hashlib import md5
from pathlib import Path
from urllib import request
parser = ArgumentParser()
parser.add_argument(
"-d",
"--directory",
default=Path.cwd(),
type=Path,
help="Folder to scan for existing bioses",
)
args = parser.parse_args()
with request.urlopen(
"https://raw.githubusercontent.com/RetroDECK/RetroDECK/main/emu-configs/defaults/retrodeck/reference_lists/bios_checklist.cfg"
) as response:
bioses = reader(response.read().decode().splitlines(), delimiter="^")
for bios in bioses:
if "pico" in bios[0]:
continue
bios_path = args.directory / bios[1] / bios[0]
local_path = list((args.directory / bios[1]).glob(bios[0], case_sensitive=False))
if not local_path:
print(
f"\033[91mMissing {bios_path.relative_to(args.directory)} on "
f"{bios[3]} with hash {bios[2]}\033[00m"
)
elif bios[2] == "Unknown":
print(f"Unknown checksum for {bios_path.relative_to(args.directory)} on {bios[3]}")
else:
with open(local_path[0], "rb") as file:
checksum = md5(file.read()).hexdigest()
if checksum != bios[2]:
print(
f"\033[93mChecksum mismatch for {bios_path.relative_to(args.directory)} on "
f"{bios[3]}: {checksum}\033[00m != \033[92m{bios[2]}\033[00m"
)