-
Notifications
You must be signed in to change notification settings - Fork 37
/
update_license_header.py
53 lines (47 loc) · 1.55 KB
/
update_license_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
import os
old_header = r"""# (c) 2015-2018 Acellera Ltd http://www.acellera.com
# All Rights Reserved
# Distributed under HTMD Software License Agreement
# No redistribution in whole or part
#
"""
new_header = r"""# (c) 2015-2022 Acellera Ltd http://www.acellera.com
# All Rights Reserved
# Distributed under HTMD Software License Agreement
# No redistribution in whole or part
#
"""
exclusions = (
"moleculekit/lib",
"moleculekit/share",
"moleculekit/test-data",
"moleculekit/pdbx",
"moleculekit/tools/obabel_tools",
)
for root, dirs, files in os.walk("moleculekit"):
for i, fname in enumerate(
[
os.path.join(root, file)
for file in files
if not any(exclusion in root for exclusion in exclusions)
]
):
if fname in exclusions:
continue
if fname.endswith((".py", ".sh")):
try:
print(f"-------------------------- {fname} ---------------------------")
with open(fname) as f:
print("".join(f.readlines()[:6]))
with open(fname) as f:
text = f.read()
if old_header in text:
text = text.replace(old_header, new_header)
else:
text = new_header + text
print("XXXXXXXXXXXXXXXX")
print("\n".join(text.split("\n")[:10]))
with open(fname, "w") as fout:
fout.write(text)
except Exception as e:
print(f"ERROR: {e}")