"""Where the local romsets are: yours, named by two environment variables. ``NO_INTRO_DIR`` is a folder of No-Intro sets, one folder per system under No-Intro's own names (``Sega - Master System - Mark III`` and so on), each cartridge a zip. ``MAME_ROMPATH`` is a MAME rompath: the folder holding ``sms.zip``, ``sf7000.zip`` and the other BIOS sets, for MAME itself and for the scripts that boot through a BIOS. Nothing here is fetched or committed, and without the variables the scripts look in ``./No-Intro`` and ``./roms``. """ from __future__ import annotations import os from pathlib import Path MIRROR = Path(os.environ.get("NO_INTRO_DIR", "No-Intro")) MAME_ROMPATH = Path(os.environ.get("MAME_ROMPATH", "roms")) # romset name -> its No-Intro folders (licensed, then aftermarket). FOLDERS = { # No-Intro renamed "Sega - SG-1000" and moved its aftermarket titles out; a # mirror can still hold the old folder beside the new, with those titles twice. "sg1000": ["Sega - SG-1000 - SC-3000", "Sega - SG-1000 - SC-3000 (Aftermarket)"], "mastersystem": [ "Sega - Master System - Mark III", "Sega - Master System - Mark III (Aftermarket)", ], "gamegear": ["Sega - Game Gear", "Sega - Game Gear (Aftermarket)"], } def carts(system: str) -> list[Path]: """Every cartridge archive of a romset, sorted by name; BIOS images left out.""" found = [ path for folder in FOLDERS[system] for path in (MIRROR / folder).glob("*.zip") if not path.name.startswith("[BIOS]") ] return sorted(found, key=lambda path: path.name) def find(system: str, name: str) -> Path: """The archive of the cartridge with this No-Intro name (no extension).""" for folder in FOLDERS[system]: path = MIRROR / folder / f"{name}.zip" if path.exists(): return path raise FileNotFoundError(f"{name}.zip is in none of {FOLDERS[system]} under {MIRROR}")