Files
astronomy/generate/update_copyrights.py
Don Cross 62192357ba Updated copyrights for 2023.
Windows build process now updates copyright
years just like the Linux build process does.
Ran it to update the copyright years for 2023.
2023-01-07 17:13:07 -05:00

40 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright (c) 2019-2023 Don Cross <cosinekitty@gmail.com>
import sys
import re
import datetime
CurrentYear = str(datetime.datetime.utcnow().year)
def UpdateCopyrights(fn):
count = 0
rx = re.compile(r'Copyright\s+\(c\)\s+2019(-(\d+))?\s+Don\s+Cross')
update = 'Copyright (c) 2019-' + CurrentYear + ' Don Cross'
newlines = []
with open(fn, 'rt') as infile:
if not fn.endswith('.pdf'):
for line in infile:
m = rx.search(line)
if m:
if m.group(2) != CurrentYear:
count += 1
line = rx.sub(update, line)
newlines.append(line)
if count > 0:
print('update_copyrights.py: {}'.format(fn))
with open(fn, 'wt') as outfile:
for line in newlines:
outfile.write(line)
return 1
return 0
def main(fnlist):
nfiles = 0
for fn in fnlist:
nfiles += UpdateCopyrights(fn)
print('update_copyrights: updated {:d} files'.format(nfiles))
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))