File size: 2,639 Bytes
8c3e275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/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"
        "SPDX-FileCopyrightText: 2026 Team Centurions\n"
        "SPDX-License-Identifier: AGPL-3.0-or-later\n"
        "-->\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()