File: collect_copyright.py

package info (click to toggle)
qmapshack 1.16.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 108,132 kB
  • sloc: cpp: 405,103; python: 1,199; sh: 652; xml: 210; awk: 21; makefile: 8; ansic: 1
file content (40 lines) | stat: -rwxr-xr-x 1,073 bytes parent folder | download | duplicates (4)
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)