#2320 hub: allow glob matching for listTags
Merged 3 years ago by tkopecek. Opened 3 years ago by tkopecek.
tkopecek/koji issue2086  into  master

file modified
+11 -7
@@ -4113,7 +4113,17 @@ 

          if not buildinfo:

              parser.error(_("Invalid build %s" % options.build))

  

-     tags = session.listTags(buildinfo.get('id', None), pkginfo.get('id', None))

+     if not args:

+         # list everything if no pattern is supplied

+         args = [None]

+ 

+     tags = []

+     with session.multicall() as m:

+         for arg in args:

+             tags.append(m.listTags(build=buildinfo.get('id', None),

+                                    package=pkginfo.get('id', None),

+                                    pattern=arg))

+     tags = list(itertools.chain(*[t.result for t in tags]))

      tags.sort(key=lambda x: x['name'])

      # if options.verbose:

      #    fmt = "%(name)s [%(id)i] %(perm)s %(locked)s %(arches)s"
@@ -4122,12 +4132,6 @@ 

      else:

          fmt = "%(name)s"

      for tag in tags:

-         if args:

-             for pattern in args:

-                 if fnmatch.fnmatch(tag['name'], pattern):

-                     break

-             else:

-                 continue

          if options.unlocked:

              if tag['locked'] or tag['perm']:

                  continue

file modified
+25 -21
@@ -1232,27 +1232,26 @@ 

      return packages

  

  

- def list_tags(build=None, package=None, perms=True, queryOpts=None):

-     """List tags.  If build is specified, only return tags associated with the

-     given build.  If package is specified, only return tags associated with the

-     specified package.  If neither is specified, return all tags.  Build can be

-     either an integer ID or a string N-V-R.  Package can be either an integer ID

-     or a string name.  Only one of build and package may be specified.  Returns

-     a list of maps.  Each map contains keys:

-       - id

-       - name

-       - arches

-       - locked

- 

-     If package is specified, each map will also contain:

-       - owner_id

-       - owner_name

-       - blocked

-       - extra_arches

- 

-     If perms is True, each map will also contain:

-       - perm_id

-       - perm

+ def list_tags(build=None, package=None, perms=True, pattern=None, queryOpts=None):

Trivial thing here: pattern=None should be better after queryOpts for backward compatibility

+     """List tags according to filters

+ 

+     :param int|str build: If build is specified, only return tags associated with

+                           the given build.  Build can be either an integer ID or

+                           a string N-V-R.

+     :param int|str package: If package is specified, only return tags associated with the

+                             specified package. Package can be either an integer ID or a

+                             string name.

+ 

+                             In this case resulting map will have additional keys:

+                               - owner_id

+                               - owner_name

+                               - blocked

+                               - extra_arches

+     :param bool perms: If perms is True, perm_id and perm is added to resulting maps.

+     :param pattern: If glob pattern is specified, only return tags matching that pattern.

+ 

+     :returns list of dicts: Each map contains id, name, arches and locked keys and

+                             additional keys as specified via package or perms options.

      """

      if build is not None and package is not None:

          raise koji.GenericError('only one of build and package may be specified')
@@ -1293,6 +1292,11 @@ 

                       "   tag_package_owners.active IS TRUE")

          joins.append('users ON tag_package_owners.owner = users.id')

          packageID = packageinfo['id']

+     if pattern is not None:

+         # copied from _prepareSearchTerms / glob

+         pattern = pattern.replace(

+             '\\', '\\\\').replace('_', r'\_').replace('?', '_').replace('*', '%')

+         clauses.append('tag.name ILIKE %(pattern)s')

  

      query = QueryProcessor(columns=fields, aliases=aliases, tables=tables,

                             joins=joins, clauses=clauses, values=locals(),

server-side filtering would be better than CLI/client side filtering.

Fixes: https://pagure.io/koji/issue/2086

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

3 years ago

pretty please pagure-ci rebuild

3 years ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

3 years ago

Commit 98601ff fixes this pull-request

Pull-Request has been merged by tkopecek

3 years ago

Trivial thing here: pattern=None should be better after queryOpts for backward compatibility