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
|
#!/usr/bin/env python
# this small utility takes 'README' file from stellarium
# and formats it properly for 'copyright' file in debian directory
from os.path import join, abspath, dirname
import sys
this = dirname(abspath(__file__))
readme = join(this, '..', 'README')
lines = open(readme, 'rb').readlines()
matches = [ (i, l) for i, l in enumerate(lines) if l.startswith('8. FULL REFERENCES') ]
assert len(matches) == 1
lineno, _ = matches[0]
license = []
for line in lines[lineno-1:]:
line = line.rstrip()
if line == '': # empty lines
license.append(' .')
else:
license.append(' %s' % line.replace('\t', ' '))
# now find the proper place to inject this
copyright = open('copyright', 'rb').readlines()
copyright = [ l.rstrip() for l in copyright ]
matches = [ (i, l) for i, l in enumerate(copyright) if '8. FULL REFERENCES' in l ]
lineno, _ = matches[0]
copyright = copyright[:lineno-1]
final = copyright + license
open('copyright', 'wb').write('\n'.join(final))
# print copyright
|