-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrootpy-copyright
More file actions
executable file
·54 lines (50 loc) · 1.78 KB
/
Copy pathrootpy-copyright
File metadata and controls
executable file
·54 lines (50 loc) · 1.78 KB
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
#!/usr/bin/env python
import os
import sys
import datetime
if not os.path.isfile('COPYRIGHT'):
sys.exit('run this script from the top-level of rootpy')
start_year = 2012
end_year = datetime.datetime.now().year
if end_year == start_year:
year_range = start_year
else:
year_range = '%d-%d' % (start_year, end_year)
copyright = '''\
# Copyright %s the rootpy developers
# distributed under the terms of the GNU General Public License
''' % year_range
print copyright
for path in ['rootpy', 'scripts']:
for dirpath, dirnames, filenames in os.walk(path):
# skip external code
try:
dirnames.remove('extern')
except ValueError:
pass
for filename in filenames:
_, ext = os.path.splitext(filename)
fullpath = os.path.join(dirpath, filename)
if ext != '.py' and not os.access(fullpath, os.X_OK):
# only write copyright info in python source files and scripts
continue
src_orig = open(fullpath)
lines_orig = src_orig.readlines()
src_orig.close()
content = ''.join(lines_orig).strip()
if not content:
# only write copyright info in non-empty files
continue
insert_idx = 0
if content.startswith('#!'):
insert_idx = 1
if lines_orig[insert_idx].startswith('# Copyright'):
# don't duplicate copyright info
continue
if lines_orig[insert_idx].startswith('# rootpy license excluded'):
continue
print fullpath
src_new = open(fullpath, 'w')
lines_orig[insert_idx:insert_idx] = copyright
map(src_new.write, lines_orig)
src_new.close()