2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-22 17:43:14 +00:00
confluent/genesis/getlicenses.py

85 lines
2.2 KiB
Python
Raw Normal View History

import subprocess
import sys
import shlex
def runcmd(cmd):
return subprocess.check_output(shlex.split(cmd)).decode('utf8').split('\n')
def getsrpm(rpm):
rpminfo = runcmd(f'rpm -qi {rpm}')
for inf in rpminfo:
if inf.startswith('Source RPM'):
srpm = inf.split(':', 1)[1].strip()
return srpm
srpmtorpm = {}
rpmtosrpm = {}
allrpmlist = runcmd('rpm -qa')
for rpm in allrpmlist:
if not rpm:
continue
srpm = getsrpm(rpm)
rpmtosrpm[rpm] = srpm
if srpm in srpmtorpm:
srpmtorpm[srpm].add(rpm)
else:
srpmtorpm[srpm] = {rpm}
with open(sys.argv[1]) as rpmlist:
rpmlist = rpmlist.read().split('\n')
licenses = set([])
2023-01-31 13:52:32 +00:00
licensesbyrpm = {}
for rpm in rpmlist:
if not rpm:
continue
srpm = rpmtosrpm[rpm]
2022-11-15 16:46:52 +00:00
if srpm.startswith('linux-firmware'):
continue
for relrpm in srpmtorpm[srpm]:
liclist = runcmd(f'rpm -qL {relrpm}')
for lic in liclist:
2023-01-31 13:52:32 +00:00
if not lic:
continue
if lic == '(contains no files)':
continue
2023-01-31 13:52:32 +00:00
licensesbyrpm[rpm] = lic
licenses.add(lic)
for lic in sorted(licenses):
print(lic)
2023-01-31 13:52:32 +00:00
manualrpms = [
'ipmitool',
'almalinux-release',
'libaio',
'hwdata',
'snmp',
'libnl3',
'libbpf', # this is covered by kernel
'sqlite', # public domain
'linux-firmware', #all pertinent licenses are stripped out
'xfsprogs', # manually added by hand below (not in rpm)
'tmux', # use the extracttmuxlicenses on the source to generate NOTICE below
]
manuallicenses = [
'/usr/share/doc/ipmitool/COPYING',
'/usr/share/doc/libaio/COPYING',
'/usr/share/doc/net-snmp/COPYING',
'/usr/share/doc/libnl3/COPYING',
'/usr/share/licenses/xfsprogs/GPL-2.0',
'/usr/share/licenses/xfsprogs/LGPL-2.1',
'/usr/share/licenses/tmux/NOTICE',
]
for lic in manuallicenses:
print(lic)
for rpm in rpmlist:
if not rpm:
continue
for manualrpm in manualrpms:
if manualrpm in rpm:
break
else:
if rpm not in licensesbyrpm:
raise Exception('Unresolved license info for ' + rpm)
print("UH OH: " + rpm)