mirror of
https://github.com/boostorg/odeint.git
synced 2025-05-09 15:14:02 +00:00
copyright: script takes dates and names from git history.
This commit is contained in:
parent
1953c385e5
commit
208e6fae02
16
.mailmap
Normal file
16
.mailmap
Normal file
@ -0,0 +1,16 @@
|
||||
# git log --all --format='%an <%ae>' | sort -u
|
||||
# Proper Name <proper@email> <commit@email>
|
||||
Andreas Angelopoulos <andrewtlor@gmail.com> <andrewtlor@gmail.com>
|
||||
Christoph Koke <koke@kip.uni-heidelberg.de> <koke@kip.uni-heidelberg.de>
|
||||
Daniel James <dnljms@gmail.com> <dnljms@gmail.com>
|
||||
Denis Demidov <ddemidov@ksu.ru> <ddemidov@ksu.ru>
|
||||
Karsten Ahnert <karsten.ahnert@gmx.de> <karsten.ahnert@gmx.de>
|
||||
Karsten Ahnert <karsten.ahnert@gmx.de> <karsten@manta.(none)>
|
||||
Karsten Ahnert <karsten.ahnert@gmx.de> <karsten@b8fc166d-592f-0410-95f2-cb63ce0dd405>
|
||||
Kyle Lutz <kyle.r.lutz@gmail.com> <kyle.r.lutz@gmail.com>
|
||||
Mario Mulansky <mario.mulansky@gmx.net> <mariomulansky@b8fc166d-592f-0410-95f2-cb63ce0dd405>
|
||||
Mario Mulansky <mario.mulansky@gmx.net> <mario.mulansky@gmx.net>
|
||||
Mario Mulansky <mario.mulansky@gmx.net> <mario@neutrino.stat.physik.uni-potsdam.de>
|
||||
Mario Mulansky <mario.mulansky@gmx.net> <mario@.(none)>
|
||||
Pascal Germroth <pascal@ensieve.org> <pascal@ensieve.org>
|
||||
Sylwester Arabas <slayoo@igf.fuw.edu.pl> <slayoo@igf.fuw.edu.pl>
|
71
fix-copyright.py
Executable file
71
fix-copyright.py
Executable file
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python
|
||||
from subprocess import check_output as run
|
||||
from datetime import datetime
|
||||
from itertools import groupby
|
||||
from operator import itemgetter
|
||||
import re
|
||||
import magic
|
||||
|
||||
def authors(filename):
|
||||
log = run(['git', 'log', '--follow',
|
||||
'--date=short','--format=%aN%x09%ad', filename],
|
||||
universal_newlines=True)
|
||||
for line in log.splitlines():
|
||||
author, date = line.split('\t')
|
||||
if author != 'fix-copyright.py':
|
||||
yield author, datetime.strptime(date, '%Y-%m-%d')
|
||||
|
||||
def new_copyright(filename, previous):
|
||||
def f():
|
||||
au = list(authors(filename))
|
||||
alldates = map(itemgetter(1), au)
|
||||
aup = sorted(au + map(lambda a: (a, None), previous), key=itemgetter(0))
|
||||
for author, records in groupby(aup, itemgetter(0)):
|
||||
dates = filter(None, map(itemgetter(1), records))
|
||||
if not dates: dates = alldates
|
||||
start = min(dates)
|
||||
end = max(dates)
|
||||
fmt = '{0}' if start.year == end.year else '{0}-{1}'
|
||||
line = 'Copyright ' + fmt.format(start.year, end.year) + ' ' + author
|
||||
key = (start, author)
|
||||
yield key, line
|
||||
return map(itemgetter(1), sorted(f()))
|
||||
|
||||
def fix_copyright(filename):
|
||||
# Find copyright block in original file
|
||||
prefix = set()
|
||||
names = []
|
||||
lines = []
|
||||
with open(filename, 'r') as f:
|
||||
content = list(f)
|
||||
for i, line in enumerate(content[:15]):
|
||||
m = re.match(r'^(?P<prefix>\W*)(\(c\))?\s*?copyright\s*(\(c\))?\s+\d{4}(\s*-\s*\d{4})?\s+(?P<name>.+?)\s*$', line, re.IGNORECASE)
|
||||
if m:
|
||||
d = m.groupdict()
|
||||
prefix.add(d['prefix'])
|
||||
lines.append(i)
|
||||
names.append(d['name'].strip())
|
||||
if len(prefix) != 1:
|
||||
print 'Not found:', filename
|
||||
return
|
||||
prefix = list(prefix)[0]
|
||||
|
||||
print filename
|
||||
new = iter(new_copyright(filename, names))
|
||||
with open(filename, 'w') as f:
|
||||
for i, line in enumerate(content):
|
||||
if i in lines:
|
||||
for repl in new:
|
||||
print >>f, prefix + repl
|
||||
else:
|
||||
print >>f, line,
|
||||
pass
|
||||
|
||||
def all_files():
|
||||
ls = run(['git', 'ls-files'], universal_newlines=True)
|
||||
for filename in ls.splitlines():
|
||||
if magic.from_file(filename, mime=True).split('/')[0] == 'text':
|
||||
yield filename
|
||||
|
||||
for f in all_files():
|
||||
fix_copyright(f)
|
Loading…
x
Reference in New Issue
Block a user