From 3f57163c3ffa9212dff7c8ec71609eb8badf7ef3 Mon Sep 17 00:00:00 2001 From: Yu Ming Zhu Date: Nov 17 2020 22:59:32 +0000 Subject: [PATCH 1/3] hub: [listBuilds] add nvr glob pattern support fixes: #2554 --pattern is also added in list-builds command --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index 3d3cd4a..c400399 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -3009,6 +3009,7 @@ def anon_handle_list_builds(goptions, session, args): parser.add_option("--task", help=_("List builds for this task")) parser.add_option("--type", help=_("List builds of this type.")) parser.add_option("--prefix", help=_("Only builds starting with this prefix")) + parser.add_option("--pattern", help=_("Only list builds matching this GLOB pattern")) parser.add_option("--source", help=_("Only builds where the source field matches " "(glob pattern)")) parser.add_option("--owner", help=_("List builds built by this owner")) @@ -3024,7 +3025,7 @@ def anon_handle_list_builds(goptions, session, args): parser.error(_("This command takes no arguments")) ensure_connection(session) opts = {} - for key in ('type', 'prefix'): + for key in ('type', 'prefix', 'pattern'): value = getattr(options, key) if value is not None: opts[key] = value diff --git a/hub/kojihub.py b/hub/kojihub.py index 9488eaa..3b1c539 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -11173,7 +11173,7 @@ class RootExports(object): volumeID=None, source=None, createdBefore=None, createdAfter=None, completeBefore=None, completeAfter=None, type=None, typeInfo=None, - queryOpts=None): + queryOpts=None, pattern=None): """Return a list of builds that match the given parameters Filter parameters @@ -11184,6 +11184,7 @@ class RootExports(object): - volumeID: only builds stored on the given volume (numeric id) - source: only builds where the source field matches (glob pattern) - prefix: only builds whose package name starts with that prefix + - pattern: only builds whose nvr matches the glob pattern - state: only builds in the given state (numeric value) Timestamp filter parameters @@ -11287,6 +11288,10 @@ class RootExports(object): clauses.append('build.source ilike %(source)s') if prefix: clauses.append("package.name ilike %(prefix)s || '%%'") + if pattern: + pattern = self._prepareSearchTerms(pattern, 'glob') + clauses.append('package.name || '-' || build.version || '-' || build.release' + ' ilike %(pattern)s') if state is not None: clauses.append('build.state = %(state)i') if createdBefore: From 23c1ee9f449b7a5256b58581533a5044c57fdb68 Mon Sep 17 00:00:00 2001 From: Yu Ming Zhu Date: Nov 17 2020 23:16:00 +0000 Subject: [PATCH 2/3] catch the exception on old hub --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index c400399..a8a249a 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -3106,7 +3106,12 @@ def anon_handle_list_builds(goptions, session, args): else: # Check filter exists if any(opts): - data = session.listBuilds(**opts) + try: + data = session.listBuilds(**opts) + except koji.ParameterError as e: + if e.args[0].endswith("'pattern'"): + parser.error(_("The hub doesn't support the 'pattern' argument, please try" + " filtering the result on your local instead.")) else: parser.error(_("Filter must be provided for list")) if not options.sort_key: From 7d3bf216122e3bdf9639a1d5332e112f17d4194b Mon Sep 17 00:00:00 2001 From: Yu Ming Zhu Date: Nov 18 2020 04:53:38 +0000 Subject: [PATCH 3/3] fix typo of quote --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 3b1c539..2df0fb0 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -11290,8 +11290,8 @@ class RootExports(object): clauses.append("package.name ilike %(prefix)s || '%%'") if pattern: pattern = self._prepareSearchTerms(pattern, 'glob') - clauses.append('package.name || '-' || build.version || '-' || build.release' - ' ilike %(pattern)s') + clauses.append("package.name || '-' || build.version || '-' || build.release" + " ilike %(pattern)s") if state is not None: clauses.append('build.state = %(state)i') if createdBefore: