#!/usr/bin/python3 """ Retrieves the monitoring status of all the packages for which the specified username is the point of contact. """ import argparse import requests default_dist_git = "https://src.fedoraproject.org/" def get_arguments(): """ Parse and return the CLI arguments. """ parser = argparse.ArgumentParser( description="Retrieves the monitoring status of all the packages " "for which the specified packager is the point of contact" ) parser.add_argument( "--url", default=default_dist_git, help=f"Dist-git url to query, defaults to: {default_dist_git}", ) parser.add_argument( "username", help="Username of the packager to query the packages of." ) return parser.parse_args() def get_projects_of_users(username, url): """ Returns the list of project (as dict) owned by the specified user. """ projects = [] page = 1 url = f"{url.rstrip('/')}/api/0/projects?owner={username}" while 1: req = requests.get(url) data = req.json() projects.extend(data["projects"]) print( f"Retrieving list of packages for user: {username}, " f"page {data['pagination']['page']} of " f"{data['pagination']['pages']}", end="\r", ) url = data["pagination"]["next"] if not url: break return projects def get_monitoring_status(namespace, name, url): """ Return the monitoring status of the specified project. """ url = f"{url.rstrip('/')}/_dg/anitya/{namespace}/{name}" req = requests.get(url) output = "Failed to retrieve status" if req.ok: data = req.json() output = data["monitoring"] return output def main(): """ Main function. """ args = get_arguments() projects = get_projects_of_users(args.username, args.url) for project in projects: monitoring = get_monitoring_status( project["namespace"], project["name"], args.url ) project_name = f"{project['namespace']}/{project['name']}" print(f"{project_name.ljust(70)} : {monitoring}") print(f" {args.url.rstrip('/')}/{project_name}") if __name__ == "__main__": try: main() except KeyboardInterrupt: print("We were asked to stop, so complying...")