-
Notifications
You must be signed in to change notification settings - Fork 9
/
update-copyright.py
executable file
·59 lines (48 loc) · 2.05 KB
/
update-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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import datetime
import fnmatch
import os
license_template = \
"""\
/**********************************************************************************
* Copyright (c) 2013-{CURRENT_YEAR} BalaBit IT Ltd, Budapest, Hungary
*
* This file is part of qlogsystem.
*
* qlogsystem is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* qlogsystem is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with qlogsystem; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**********************************************************************************/
"""
def main():
license = license_template.format(CURRENT_YEAR=datetime.datetime.now().year)
first_line, second_line = license.split('\n')[0:2]
copyright = second_line[:21]
for root, dirnames, filenames in os.walk(os.path.dirname(os.path.abspath(__file__))):
if root.startswith('.'):
continue
for filename in (fnmatch.filter(filenames, '*.hh') + fnmatch.filter(filenames, '*.cc')):
filename = os.path.join(root, filename)
with open(filename, 'r+') as f:
if f.readline().startswith(first_line) and f.readline().startswith(copyright):
print("Updating copyright on " + filename)
f.seek(0, 0)
f.write(license)
else:
print("Adding copyright to " + filename)
f.seek(0, 0)
content = f.read()
f.seek(0, 0)
f.write(license)
f.write(content)
if __name__ == "__main__":
main()