From 23e3565f7d69827119bb0e501199abcc77cc66de Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Jun 03 2019 16:03:02 +0000 Subject: Module-overview allows filtering by owner Adds additional arguments to command `fedpkg module-overview`: '--owner' - param is added to mbs query and shows only builds of that owner '--mine' - use current Kerberos user (or system username if Kerberos is not present) for filtering Arguments are mutually exclusive. JIRA: COMPOSE-3538 Fixes: https://pagure.io/fedpkg/issue/325 Signed-off-by: Ondrej Nosek --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 1f61082..a4012cb 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -3510,7 +3510,7 @@ class Commands(object): else: raise - def module_overview(self, limit=10, finished=True): + def module_overview(self, limit=10, finished=True, owner=None): """ Show the overview of the latest builds in MBS @@ -3518,6 +3518,7 @@ class Commands(object): to display. This defaults to 10. :param bool finished: a boolean that determines if only finished or unfinished module builds should be displayed. This defaults to True. + :param str owner: list only builds of that user. """ # Don't let the user cause problems by specifying a negative limit if limit < 1: @@ -3540,12 +3541,13 @@ class Commands(object): states = [build_states['init'], build_states['wait'], build_states['build']] - def _get_module_builds(state): + def _get_module_builds(state, owner=None): """ Private function that is used for multithreading later on to get the desired amount of builds for a specific state. :param state: an integer representing the build state to query for + :param owner: a string; to query for that owner's builds :return: a generator to yield dictionaries of the builds found """ total = 0 @@ -3560,6 +3562,8 @@ class Commands(object): 'verbose': True, 'per_page': per_page } + if owner: + params['owner'] = owner while total < limit: params['page'] = page response = requests.get(baseurl, params=params, timeout=30) @@ -3592,9 +3596,13 @@ class Commands(object): # Eventually, the MBS should support a range of states but for now, we # have to be somewhat wasteful and query per state module_builds = pool.map( - lambda x: list(_get_module_builds(state=x)), states) + lambda x: list(_get_module_builds(state=x, owner=owner)), states) # Make one flat list with all the modules module_builds = [item for sublist in module_builds for item in sublist] + # Sort the list with a secondary key first. It should prevent the situation + # that two builds with same id (its status was changed during the queries) + # are in the list and the record with older status is removed. + module_builds.sort(key=lambda x: x['time_modified'], reverse=True) # Sort the list of builds to be oldest to newest module_builds.sort(key=lambda x: x['id']) # Only grab the desired limit starting from the newest builds diff --git a/pyrpkg/cli.py b/pyrpkg/cli.py index eb0f499..97dec0f 100644 --- a/pyrpkg/cli.py +++ b/pyrpkg/cli.py @@ -1242,6 +1242,12 @@ defined, packages will be built sequentially.""" % {'name': self.name}) self.module_overview_parser.add_argument( '--limit', default=10, type=int, help='The number of most recent module builds to display') + group = self.module_overview_parser.add_mutually_exclusive_group() + group.add_argument( + '--owner', metavar='FAS_ID', help='List only items of that owner') + group.add_argument( + '--mine', action='store_true', default=False, + help='Use current Kerberos name or username') self.module_overview_parser.set_defaults( command=self.module_overview) @@ -2331,9 +2337,15 @@ see API KEY section of copr-cli(1) man page. def module_overview(self): """Show the overview of the latest builds in the MBS""" self.set_module_api_url() + owner = self.args.owner + if self.args.mine: + owner = self.cmd.user + if not owner: + raise rpkgError("Can not obtain current Kerberos name or username") self.cmd.module_overview( self.args.limit, - finished=(not self.args.unfinished)) + finished=(not self.args.unfinished), + owner=owner) def module_scratch_build(self): # A module scratch build is just a module build with --scratch diff --git a/tests/test_cli.py b/tests/test_cli.py index ee92389..2da80eb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2671,7 +2671,8 @@ Components: 'owner': 'jkaluza', 'state_name': 'ready', 'stream': 'master', - 'version': '20171011093314' + 'version': '20171011093314', + 'time_modified': '2019-06-03T15:12:06Z', }, { 'id': 1099, @@ -2680,7 +2681,8 @@ Components: 'owner': 'jkaluza', 'state_name': 'ready', 'stream': 'master', - "version": "20171011092951" + "version": "20171011092951", + 'time_modified': '2019-06-03T14:46:02Z', } ], 'meta': { @@ -2699,7 +2701,8 @@ Components: 'scratch': True, 'state_name': 'failed', 'stream': 'master', - 'version': '20171011173928' + 'version': '20171011173928', + 'time_modified': '2019-06-03T14:47:12Z', }, { 'id': 1094, @@ -2708,7 +2711,8 @@ Components: 'owner': 'mprahl', 'state_name': 'failed', 'stream': 'master', - 'version': '20171010151103' + 'version': '20171010151103', + 'time_modified': '2019-06-03T14:45:26Z', } ], 'meta': {