-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathupdate_license.py
More file actions
157 lines (137 loc) · 6.29 KB
/
Copy pathupdate_license.py
File metadata and controls
157 lines (137 loc) · 6.29 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python3
import os
ROOT = os.path.dirname(os.path.abspath(__file__))
SKIP = {"build", "managed_components", "lvgl-env"}
# --- Replacement pairs (old Apache block → new GPL v3 block) -----------------
SLASH_OLD = (
"// Licensed under the Apache License, Version 2.0 (the \"License\");\n"
"// you may not use this file except in compliance with the License.\n"
"// You may obtain a copy of the License at\n"
"//\n"
"// http://www.apache.org/licenses/LICENSE-2.0\n"
"//\n"
"// Unless required by applicable law or agreed to in writing, software\n"
"// distributed under the License is distributed on an \"AS IS\" BASIS,\n"
"// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
"// See the License for the specific language governing permissions and\n"
"// limitations under the License."
)
SLASH_NEW = (
"// TentacleOS is free software: you can redistribute it and/or modify\n"
"// it under the terms of the GNU General Public License as published by\n"
"// the Free Software Foundation, either version 3 of the License, or\n"
"// (at your option) any later version.\n"
"//\n"
"// TentacleOS is distributed in the hope that it will be useful,\n"
"// but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"// GNU General Public License for more details.\n"
"//\n"
"// You should have received a copy of the GNU General Public License\n"
"// along with TentacleOS. If not, see <https://www.gnu.org/licenses/>."
)
HASH_OLD = (
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n"
"# you may not use this file except in compliance with the License.\n"
"# You may obtain a copy of the License at\n"
"#\n"
"# http://www.apache.org/licenses/LICENSE-2.0\n"
"#\n"
"# Unless required by applicable law or agreed to in writing, software\n"
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n"
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
"# See the License for the specific language governing permissions and\n"
"# limitations under the License."
)
HASH_NEW = (
"# TentacleOS is free software: you can redistribute it and/or modify\n"
"# it under the terms of the GNU General Public License as published by\n"
"# the Free Software Foundation, either version 3 of the License, or\n"
"# (at your option) any later version.\n"
"#\n"
"# TentacleOS is distributed in the hope that it will be useful,\n"
"# but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"# GNU General Public License for more details.\n"
"#\n"
"# You should have received a copy of the GNU General Public License\n"
"# along with TentacleOS. If not, see <https://www.gnu.org/licenses/>."
)
REPLACEMENTS = [(SLASH_OLD, SLASH_NEW), (HASH_OLD, HASH_NEW)]
# --- Header to insert in tools/ scripts (no existing copyright) --------------
HASH_HEADER = (
"# Copyright (c) 2025 HIGH CODE LLC\n"
"#\n"
"# TentacleOS is free software: you can redistribute it and/or modify\n"
"# it under the terms of the GNU General Public License as published by\n"
"# the Free Software Foundation, either version 3 of the License, or\n"
"# (at your option) any later version.\n"
"#\n"
"# TentacleOS is distributed in the hope that it will be useful,\n"
"# but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"# GNU General Public License for more details.\n"
"#\n"
"# You should have received a copy of the GNU General Public License\n"
"# along with TentacleOS. If not, see <https://www.gnu.org/licenses/>."
)
TOOLS_SKIP = {"LVGLImage.py"} # third-party
TOOLS_EXTS = {".sh", ".py", ".ps1"}
# -----------------------------------------------------------------------------
def replace_in_file(fpath):
with open(fpath, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
if "Copyright (c) 2025 HIGH CODE LLC" not in content:
return False
new_content = content
for old, new in REPLACEMENTS:
new_content = new_content.replace(old, new)
if new_content == content:
return False
with open(fpath, "w", encoding="utf-8") as f:
f.write(new_content)
return True
def insert_header_in_file(fpath):
with open(fpath, "r", encoding="utf-8", errors="ignore") as f:
content = f.read()
if "Copyright" in content:
return False
lines = content.splitlines(keepends=True)
if lines and lines[0].startswith("#!"):
new_content = lines[0] + "\n" + HASH_HEADER + "\n\n" + "".join(lines[1:])
else:
new_content = HASH_HEADER + "\n\n" + content
with open(fpath, "w", encoding="utf-8") as f:
f.write(new_content)
return True
updated = 0
skipped = 0
# Pass 1 — replace Apache → GPL v3 in firmware sources
for subdir in ["firmware_c5/main", "firmware_c5/components", "firmware_p4/main", "firmware_p4/components"]:
for dirpath, dirnames, filenames in os.walk(os.path.join(ROOT, subdir)):
dirnames[:] = [d for d in dirnames if d not in SKIP]
for fname in filenames:
ext = os.path.splitext(fname)[1]
if ext not in {".c", ".h"} and fname != "CMakeLists.txt":
continue
fpath = os.path.join(dirpath, fname)
if replace_in_file(fpath):
print(f" replaced: {os.path.relpath(fpath, ROOT)}")
updated += 1
else:
skipped += 1
# Pass 2 — insert GPL v3 header in tools/ scripts
for dirpath, dirnames, filenames in os.walk(os.path.join(ROOT, "tools")):
dirnames[:] = [d for d in dirnames if d not in SKIP]
for fname in filenames:
if fname in TOOLS_SKIP:
continue
if os.path.splitext(fname)[1] not in TOOLS_EXTS:
continue
fpath = os.path.join(dirpath, fname)
if insert_header_in_file(fpath):
print(f" inserted: {os.path.relpath(fpath, ROOT)}")
updated += 1
else:
skipped += 1
print(f"\n{updated} files updated, {skipped} skipped.")