-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadd_copyright_header.py
executable file
·79 lines (69 loc) · 3.07 KB
/
add_copyright_header.py
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
#!/usr/bin/python3
# This file is part of the RKWard project (https://rkward.kde.org).
# SPDX-FileCopyrightText: 2023 by Thomas Friedrichsmeier <[email protected]>
# SPDX-FileContributor: The RKWard Team <[email protected]>
# SPDX-License-Identifier: GPL-2.0-or-later
# crude helper script to add one of the more common REUSE copyright headers, to files where it is still missing
# please check results, manually
# REUSE-IgnoreStart
import os
import sys
rootdir = sys.argv[1]
def rewrite (filename):
with open(filename, 'r') as src:
content = src.read()
if (content.find("SPDX-FileCopyrightText") > -1):
print(filename + " has header")
return
holdern = input(filename + " Prim copyright holder: [0] skip [1] Thomas [2] Meik [3] Prasenjit [4] Stefan? ")
holder = ""
if (holdern.startswith("1")):
holder = "Thomas Friedrichsmeier <[email protected]>"
elif (holdern.startswith("2")):
holder = "Meik Michalke <[email protected]>"
elif (holdern.startswith("3")):
holder = "Prasenjit Kapat <[email protected]>"
elif (holdern.startswith("4")):
holder = "Stefan Rödiger <[email protected]>"
else:
print("skipping")
return
text = "- This file is part of the RKWard project (https://rkward.kde.org).\n"
text += "SPDX-FileCopyrightText: by " + holder + "\n"
text += "SPDX-FileContributor: The RKWard Team <[email protected]>\n"
text += "SPDX-License-Identifier: GPL-2.0-or-later"
if (content.startswith("<!DOCTYPE") or filename.endswith(".xml")):
with open(filename, 'wt') as dst:
index = content.find("\n") + 1
dst.write(content[:index])
dst.write("<!--")
dst.write(text)
dst.write("\n-->\n")
dst.write(content[index:])
elif (filename.endswith(".js")):
with open(filename, 'wt') as dst:
dst.write("/*")
dst.write(text)
dst.write("\n*/\n")
dst.write(content)
elif (filename.endswith(".R") or filename.endswith("CMakeLists.txt")):
with open(filename, 'wt') as dst:
dst.write("# " + text.replace("\n", "\n# ") + "\n")
dst.write(content)
elif (filename.endswith(".sh") or filename.endswith(".py")):
index = 0;
if (content.startswith("#!")):
index = content.find("\n")+ 1
with open(filename, 'wt') as dst:
dst.write(content[:index])
dst.write("# " + text.replace("\n", "\n# ") + "\n")
dst.write(content[index:])
else:
print(filename + " not handled")
for folder, subs, files in os.walk(rootdir):
for filename in files:
if filename.startswith("po"):
continue
if (True or filename.endswith(".xml")):
rewrite(os.path.join(folder, filename))
# REUSE-IgnoreEnd