#!/usr/bin/env python3 # SPDX-FileCopyrightText: 2026 Team Centurions # SPDX-License-Identifier: AGPL-3.0-or-later import sys from pathlib import Path ROOT_DIR = Path(__file__).resolve().parent.parent EXCLUDED_DIRS = { ".git", ".github", ".gitlab", ".venv", ".pytest_cache", ".mypy_cache", "node_modules", "dist", "build", "tmp", "models", ".specify", } EXCLUDED_FILES = { "pageparse.db", "package-lock.json", ".secrets.baseline", } HEADERS = { "hash": ( "# SPDX-FileCopyrightText: 2026 Team Centurions\n" "# SPDX-License-Identifier: AGPL-3.0-or-later\n\n" ), "slash": ( "// SPDX-FileCopyrightText: 2026 Team Centurions\n" "// SPDX-License-Identifier: AGPL-3.0-or-later\n\n" ), "xml": ( "\n\n" ) } def inject_file(file_path: Path) -> None: if file_path.name in EXCLUDED_FILES: return try: content = file_path.read_text(encoding="utf-8", errors="ignore") if "SPDX-License-Identifier" in content: return ext = file_path.suffix.lower() if ext in [".py", ".yml", ".yaml", ".gbnf"]: # Python files might have a shebang. If so, put the header after shebang. lines = content.splitlines(keepends=True) if lines and lines[0].startswith("#!"): new_content = lines[0] + HEADERS["hash"] + "".join(lines[1:]) else: new_content = HEADERS["hash"] + content elif ext in [".ts", ".tsx"]: new_content = HEADERS["slash"] + content elif ext == ".md": new_content = HEADERS["xml"] + content else: return file_path.write_text(new_content, encoding="utf-8") print(f"Injected: {file_path.relative_to(ROOT_DIR)}") except Exception as e: print(f"ERROR processing {file_path}: {e}") def main() -> None: print("Injecting license compliance in files...") # Check all files under source and configurations for path in ROOT_DIR.rglob("*"): if path.is_file(): parts = path.relative_to(ROOT_DIR).parts if any(p in EXCLUDED_DIRS for p in parts): continue if path.suffix in [".py", ".ts", ".tsx", ".yml", ".yaml", ".md", ".gbnf"]: inject_file(path) print("Injection complete.") if __name__ == "__main__": main()