# 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 fetched or kept. This asks GitHub for the first 256 bytes of each file (an HTTP Range request), keeps the two header lines and discards the rest unread. A file with no `license:` line is GPL-2.0+ by MAME's COPYING (emulator-lineage docs/sources.md, the MAME row). python -I scripts/mame_license_lines.py --tag mame0285 src/mame/namco/namcos1.cpp ... """ import argparse import re import urllib.request LINE = re.compile(r"(license|copyright-holders):\s*([^\r\n]*)") def header(tag, path): 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") first = head.splitlines()[:3] found = {} for line in first: for key, value in LINE.findall(line): found[key] = value.strip() return found def main(): 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', '')}") if __name__ == "__main__": main()