forked from lballabio/QuantLib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcollect_copyrights.py
executable file
·40 lines (32 loc) · 1.01 KB
/
collect_copyrights.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
#!/usr/bin/python
import re, sys
regex1 = re.compile(r"Copyright \(C\) ([0-9]{4}-[0-9]{4}) (.+)$")
regex2 = re.compile(r"Copyright \(C\) (([0-9]{4})(, [0-9]{4})*) (.+)$")
copyrights = {}
for line in sys.stdin:
m1 = regex1.search(line)
m2 = regex2.search(line)
if m1 is None and m2 is None:
print line
continue
if m1:
first, last = [ int(y) for y in m1.groups()[0].split('-') ]
years = range(first, last+1)
owner = m1.groups()[-1].strip()
elif m2:
years = [ int(y) for y in m2.groups()[0].split(', ') ]
owner = m2.groups()[-1].strip()
s = copyrights.get(owner,set())
for y in years:
s.add(y)
copyrights[owner] = s
for owner in copyrights:
s = copyrights[owner]
l = [ y for y in s ]
l.sort()
copyrights[owner] = l
copyrights = [ (years,owner) for owner,years in copyrights.items() ]
copyrights.sort()
print 60*'-'
for years, owner in copyrights:
print "Copyright (C)", ', '.join([str(y) for y in years]), owner