# SPDX-License-Identifier: MIT """Read only the `license:` and `copyright-holders:` lines of MAME source files. MAME is a closed box for this repository: its source is never kept. This asks GitHub for the first 256 bytes of each file (an HTTP Range request), keeps the two header lines in memory, prints them, and discards the rest unread; nothing is written to disk. A file with no `license:` line is GPL-2.0+ by MAME's COPYING (emulator-lineage docs/sources.md, MAME row). python -I scripts/mame_license_lines.py --tag mame0285 src/mame/namco/namcos22.cpp ... """ from __future__ import annotations import argparse import re import sys import urllib.error import urllib.request LINE = re.compile(r"(license|copyright-holders):\s*([^\r\n]*)") def header(tag: str, path: str) -> dict[str, str]: url = f"https://raw.githubusercontent.com/mamedev/mame/{tag}/{path}" req = urllib.request.Request(url, headers={"Range": "bytes=0-255", "User-Agent": "license-line-check"}) with urllib.request.urlopen(req, timeout=30) as r: head = r.read(256).decode("utf-8", "replace") found: dict[str, str] = {} for line in head.splitlines()[:3]: for key, value in LINE.findall(line): found[key] = value.strip() return found def main() -> int: ap = argparse.ArgumentParser() ap.add_argument("--tag", default="mame0285") ap.add_argument("paths", nargs="+") a = ap.parse_args() for p in a.paths: try: h = header(a.tag, p) except urllib.error.HTTPError as e: print(f"{p}\tNOT FOUND at {a.tag} (HTTP {e.code})\t") continue lic = h.get("license", "NO license: LINE (GPL-2.0+ by COPYING)") print(f"{p}\t{lic}\t{h.get('copyright-holders', '')}") return 0 if __name__ == "__main__": sys.exit(main())