#!/usr/bin/env python3 """Fail if the public tree contains the OnCo corpus or a redistributed slice.""" from __future__ import annotations import json import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] FORBIDDEN_TRACKED = ( "tests/onco-reference/local/", "tests/onco-reference/authorization.json", "upstream-onco/", ) def main() -> int: problems: list[str] = [] tracked = subprocess.run( ["git", "ls-files"], cwd=ROOT, check=True, capture_output=True, text=True, ).stdout.splitlines() for path in tracked: for prefix in FORBIDDEN_TRACKED: if path.startswith(prefix): problems.append(f"tracked licensed path: {path}") if path.startswith("examples/") and path.endswith(".json"): text = (ROOT / path).read_text(encoding="utf-8") if "CC-BY-NC-4.0" in text or "Data from OnCo" in text: problems.append(f"public example carries OnCo rights: {path}") examples = ROOT / "examples" / "dataspaces" for snapshot_path in examples.glob("*/snapshot.json"): snapshot = json.loads(snapshot_path.read_text(encoding="utf-8")) for source in snapshot.get("sources") or []: if source.get("license") == "CC-BY-NC-4.0": problems.append(f"{snapshot_path}: CC-BY-NC source {source.get('id')}") if problems: print("\n".join(problems), file=sys.stderr) return 1 print("Public tree has no OnCo slice") return 0 if __name__ == "__main__": raise SystemExit(main())