diff options
-rw-r--r-- | noRMS-apk.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/noRMS-apk.py b/noRMS-apk.py index a3039c3..b05456a 100644 --- a/noRMS-apk.py +++ b/noRMS-apk.py @@ -17,7 +17,7 @@ args = parser.parse_args() verbose = args.verbose -PACKAGE = re.compile(r'^(?P<name_and_version>\S+) (?P<arch>\S+) \{(?P<origin>[^}]+)\} \((?P<licenses>[^)]+)\) \[installed\]$') +PACKAGE = re.compile(r'^(?P<name>\S+)-[\d\w\._]+-r\d+ \S+ \{(?P<origin>[^}]+)\} \([^)]+\) \[installed\]$') # from https://directory.fsf.org/wiki/GNU: # `new Set([].map.call(document.querySelectorAll('table tr td:nth-child(3)'), x => new URL(x.innerText).host))` @@ -49,25 +49,31 @@ origins = dict() all_packages = subprocess.check_output(['apk', 'list', '--installed'], text=True) for package in all_packages.splitlines(): match = PACKAGE.match(package) - name_and_version, arch, origin, licenses = match['name_and_version'], match['arch'], match['origin'], match['licenses'] + if match is None: + print('oops!', package) + name, origin = match['name'], match['origin'] if origin not in origins: origins[origin] = [] - origins[origin].append(name_and_version) + origins[origin].append(name) + +info_output = subprocess.check_output(['apk', 'info', '-wv', *origins.keys()], text=True) +package_webpage_map = dict(x.split(': ', 1) for x in info_output.splitlines()) rms_count = 0 -origin_keys = list(origins.keys()) -info_output = subprocess.check_output(['apk', 'info', '-w', *origin_keys], text=True) -info_pieces = info_output.split('\n\n') -for origin, info in zip(origin_keys, info_pieces): - webpage = info.splitlines()[1] +for origin in origins: + webpage = package_webpage_map[origin] parsed_url = urllib.parse.urlparse(webpage) host = parsed_url.netloc if verbose >= 1: print('origin:', origin, 'host:', host, 'webpage:', webpage) if host in GNU_DOMAINS: - package_text = ', '.join(origins[origin]) - print(f'error: {origin} ({package_text}) is GNU software (website is {webpage})') + subpackages = [x for x in origins[origin] if x != origin] + if len(subpackages) == 0: + package_text = '' + else: + package_text = ' (& ' + ', '.join(sorted(subpackages)) + ')' + print(f'error: {origin}{package_text} is GNU software (website is {webpage})') rms_count += 1 print() |