2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-23 01:53:28 +00:00
confluent/genesis/extracttmuxlicenses.py
Jarrod Johnson 521a58c1d9 Have a utility to generate NOTICE from tmux
tmux basically defers to the c files, so
generate a NOTICE file from c files.
2023-01-31 08:37:42 -05:00

60 lines
2.1 KiB
Python

import glob
yearsbyname = {}
namesbylicense = {}
filesbylicense = {}
for source in glob.glob('*.c'):
with open(source, 'r') as sourcein:
cap = False
thelicense = ''
currnames = set([])
for line in sourcein.readlines():
if '$OpenBSD$' in line:
continue
if '/*' in line:
cap = True
elif '*/' in line:
cap = False
break
elif cap:
line = line[3:]
if line.startswith('Author: '):
continue
if line.startswith('Copyright'):
_, _, years, name = line.split(maxsplit=3)
name = name.split('>', 1)[0] + '>'
currnames.add(name)
if name not in yearsbyname:
yearsbyname[name] = set([])
yearsbyname[name].add(years)
continue
thelicense += line
if thelicense not in namesbylicense:
namesbylicense[thelicense] = set([])
namesbylicense[thelicense].update(currnames)
if thelicense not in filesbylicense:
filesbylicense[thelicense] = set([])
filesbylicense[thelicense].add(source)
# with open(source + '.license', 'w') as liceout:
# liceout.write(thelicense)
for license in namesbylicense:
for file in sorted(filesbylicense[license]):
print('File: ' + file)
print('')
for author in namesbylicense[license]:
years = []
for year in sorted(yearsbyname[author]):
if not years:
years.append(year)
continue
if int(years[-1].split('-')[-1]) == int(year) - 1:
if '-' in years[-1]:
years[-1] = years[-1].split('-', 1)[0] + '-' + year
else:
years[-1] = years[-1] + '-' + year
else:
years.append(year)
authline = 'Copyright (c) {} {}'.format(','.join(years), author)
print(authline)
print("\n" + license + "\n\n")