forked from yesint/pteros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage_license.py
37 lines (27 loc) · 1.05 KB
/
manage_license.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
import os,sys,re
rootdir = '.'
license = open("license_header.txt").read()
for root, subdirs, files in os.walk(rootdir):
for f in files:
if f.endswith(".cpp") or f.endswith(".h"):
# Try this file
text = open(os.path.join(root,f)).read()
# Try to extract leading comment
lines = text.split('\n');
if not lines[0].startswith("/*"):
continue
body = ""
good = False
in_body = False
for line in lines:
if not good and not in_body and re.search("Pteros",line):
good = True
if not in_body and line.endswith("*/"):
in_body = True
continue
if good and in_body:
body += line+"\n"
if good:
print(os.path.join(root,f))
with open(os.path.join(root,f),'w') as out:
out.write(license+body)