forked from Maproom/qmapshack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
collect_copyright.py
executable file
·40 lines (31 loc) · 1.05 KB
/
collect_copyright.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
#!/usr/bin/python3
import re
from pathlib import Path
names = set()
def find_copyright(filename):
""" parse files for copyrights"""
regex = re.compile(r"Copyright \(C\)\s*[0-9-]*\s(.*)\s\<.*")
with open(filename) as file:
lines = file.readlines()
for line in lines:
line = line.strip()
if not line:
continue
if line.endswith("***/"):
break
res = regex.match(line)
if res:
names.add(res.group(1).strip())
else:
if "COPYRIGHT" in line.upper():
print(f"Bad matching copyright: {line}\nin file: {filename}")
raise Exception
for path in Path('src').rglob('*.cpp'):
find_copyright(path)
for path in Path('src').rglob('*.h'):
find_copyright(path)
with open("src/qmapshack/contributors.h", "w") as file:
print('constexpr auto contributors = ""', file=file)
for name in sorted(names):
print(f'"{name}, "', file=file)
print('"";', file=file)