Skip to content
Permalink
Browse files

fix method names to listPackagesSimple and countAndFilterResults.

    1. replace listPackages call by listPackagesSimple.
    2. replace filterResults by countAndFilterResults.
  • Loading branch information...
xning committed Aug 31, 2016
1 parent 029c464 commit 4b5eeef34666f56097bbf099cd7d553b3ecce9b7
Showing with 24 additions and 39 deletions.
  1. +8 −2 cli/koji
  2. +12 −30 hub/kojihub.py
  3. +2 −4 www/kojiweb/index.py
  4. +2 −3 www/lib/kojiweb/util.py
@@ -3110,7 +3110,10 @@ def anon_handle_list_pkgs(options, session, args):
opts['event'] = event['id']
event['timestr'] = time.asctime(time.localtime(event['ts']))
print "Querying at event %(id)i (%(timestr)s)" % event
data = session.listPackages(**opts)
if 'tagID' in opts or 'pkgID' in opts or 'userID' in opts:
data = session.listPackages(**opts)
else:
data = session.listPackagesSimple(**opts)
if not data:
print "(no matching packages)"
return 1
@@ -6047,7 +6050,10 @@ def handle_set_pkg_owner_global(options, session, args):
continue
to_change.extend(entries)
if not packages and options.old_user:
entries = session.listPackages(**opts)
if 'tagID' in opts or 'pkgID' in opts or 'userID' in opts:
entries = session.listPackages(**opts)
else:
entries = session.listPackagesSimple(**opts)
if not entries:
print "No data for user %s" % old_user['name']
return 1
@@ -9477,7 +9477,7 @@ def listPackages(self, tagID=None, userID=None, pkgID=None, prefix=None, inherit
return results


def listFlatPackages(self, prefix=None, queryOpts=None):
def listPackagesSimple(self, prefix=None, queryOpts=None):
"""list packages that starts with prefix and are filted
and ordered by queryOpts.

@@ -9491,16 +9491,18 @@ def listFlatPackages(self, prefix=None, queryOpts=None):
'package_name' and 'package_id'.
"""
_escape = lambda _str: _str.replace('_', '#_').replace('%', '#%')

fields = (('package.id', 'package_id'),
('package.name', 'package_name'))
if prefix is None:
clauses = None
else:
clauses = ["""package.name ILIKE '%s%%' ESCAPE '#'"""
% _escape(prefix)]
prefix = _escape(prefix)
clauses = ["""package.name ILIKE '%(prefix)s%%' ESCAPE '#'"""]
query = QueryProcessor(
tables=['package'], clauses=clauses,
columns=['package.id', 'package.name'], opts=queryOpts)
return query.executeOne()
tables=['package'], clauses=clauses, values=locals(),
columns=[f[0] for f in fields], aliases=[f[1] for f in fields],
opts=queryOpts)
return query.execute()


def checkTagPackage(self,tag,pkg):
@@ -10178,31 +10180,11 @@ def filterResults(self, methodName, *args, **kw):
NULL higher than all other values; default to True for consistency
with database sorts
"""
filterOpts = kw.pop('filterOpts', {})

results = getattr(self, methodName)(*args, **kw)
if results is None:
return None
elif not isinstance(results, list):
raise TypeError, '%s() did not return a list' % methodName

order = filterOpts.get('order')
if order:
results.sort(self._sortByKeyFunc(order, filterOpts.get('noneGreatest', True)))

offset = filterOpts.get('offset')
if offset is not None:
results = results[offset:]
limit = filterOpts.get('limit')
if limit is not None:
results = results[:limit]

return results
return self.countAndFilterResults(methodName, *args, **kw)[1]


def CountAndFilterResults(self, methodName, *args, **kw):
""" Replacement of the method filterResults when we need both the total
result count and the filtered result.
def countAndFilterResults(self, methodName, *args, **kw):
"""Filter results by a given name and count total result account.

Execute the XML-RPC method with the given name and filter the results
based on the options specified in the keywork option "filterOpts".
@@ -354,8 +354,7 @@ def notificationedit(environ, notificationID):
values = _initValues(environ, 'Edit Notification')

values['notif'] = notification
packages = server.listPackages()
packages.sort(kojiweb.util.sortByKeyFunc('package_name'))
packages = server.listPackagesSimple(queryOpts={'order': 'package_name'})
values['packages'] = packages
tags = server.listTags(queryOpts={'order': 'name'})
values['tags'] = tags
@@ -399,8 +398,7 @@ def notificationcreate(environ):
values = _initValues(environ, 'Edit Notification')

values['notif'] = None
packages = server.listPackages()
packages.sort(kojiweb.util.sortByKeyFunc('package_name'))
packages = server.listPackagesSimple(queryOpts={'order': 'package_name'})
values['packages'] = packages
tags = server.listTags(queryOpts={'order': 'name'})
values['tags'] = tags
@@ -331,12 +331,11 @@ def paginateResults(server, values, methodName, args=None, kw=None,
if not dataName:
raise StandardError, 'dataName must be specified'

totalRows = server.count(methodName, *args, **kw)

kw['filterOpts'] = {'order': order,
'offset': start,
'limit': pageSize}
data = server.filterResults(methodName, *args, **kw)

totalRows, data = server.countAndFilterResults(methodName, *args, **kw)
count = len(data)

_populateValues(values, dataName, prefix, data, totalRows, start, count, pageSize, order)

0 comments on commit 4b5eeef

Please sign in to comment.
You can’t perform that action at this time.