From 6a7a2672a513713b8b95f32771401dc470a5b12c Mon Sep 17 00:00:00 2001 From: Sandro Date: Sep 25 2022 02:04:09 +0000 Subject: Find package maintainers and their role Adoption of find-package-maintainers listing role of maintainer in relation to package (both ways). - allows file input (-f) - allows direct package input (-p) - specify type of package (-t) - specify role (-r) - does error handling if package isn't found --- diff --git a/README.rst b/README.rst index 91190cc..3052eb6 100644 --- a/README.rst +++ b/README.rst @@ -48,3 +48,20 @@ find-orphaned-packages This lists all orphaned packages that are not retired on master. Needs Python 3.7 and aiohttp. + +find-package-maintainers-role +----------------------------- + +Accepts either file with package names (one per line) (-f) or package names (-p). + +Allows to specify package type (-t) (default: rpms) and role (-r) (default: admin) +to search for. + +Errors in package names are handled. + +Outputs two lists to stdout: + +* All maintainers per package with given role added in () + +* All packages per maintainer with given role added in () + diff --git a/find-package-maintainers-role b/find-package-maintainers-role new file mode 100755 index 0000000..d797a17 --- /dev/null +++ b/find-package-maintainers-role @@ -0,0 +1,76 @@ +#!/usr/bin/python3 + +import argparse +import requests +import sys + +def options_parse(): + p = argparse.ArgumentParser( + description='Find maintainers and their roles given package names') + + source = p.add_mutually_exclusive_group(required=True) + + source.add_argument('-f', '--file', type=argparse.FileType('r'), nargs='?', + help='file containing package names') + source.add_argument('-p', '--packages', nargs='+', + help='list of packages to query') + + p.add_argument('-t', '--type', nargs='?', default='rpms', + help='{ container | flatpaks | modules | rpms | tests }') + p.add_argument('-r', '--role', nargs='?', default='admin', + help='{ admin | epel | fedora }') + p.add_argument('-v', '--verbose', action='store_true', + help='Be verbose') + + opts = p.parse_args() + + return opts + +def main(): + opts = options_parse() + + if opts.file: + packages = [line.strip() for line in opts.file] + else: + packages = opts.packages + + owners = requests.get('https://src.fedoraproject.org/extras/pagure_owner_alias.json').json() + roles = requests.get('https://src.fedoraproject.org/extras/pagure_poc.json').json() + + try: + by_package = {pkg: owners[opts.type][pkg] for pkg in packages} + by_package_role = {pkg: roles[opts.type][pkg][opts.role] for pkg in packages} + except KeyError as e: + print("Error: No %s by the name of %s" % (opts.type, e)) + exit(1) + + print(by_package) + print(by_package_role) + + by_maintainer = {} + + print('Maintainers by package:') + for pkg, maints in sorted(by_package.items()): + print('{:20}'.format(pkg), end=' ') + for maint in sorted(maints): + if by_package_role[pkg] == maint: + print(maint + ' (' + opts.role + ')', end=' ') + else: + print(maint, end=' ') + by_maintainer.setdefault(maint, []).append(pkg) + print() + + print() + print(by_maintainer) + print('Packages by maintainer:') + for maint, pkgs in sorted(by_maintainer.items()): + print('{:10}'.format(maint), end=' ') + for pkg in pkgs: + if by_package_role[pkg] == maint: + print(pkg + ' (' + opts.role + ')', end=' ') + else: + print(pkg, end=' ') + print() + +if __name__ == '__main__': + main()