[yum-commits] Branch 'yum-3_2_X' - cli.py yum/comps.py yum/depsolve.py

Ville Skyttä scop at osuosl.org
Mon Oct 19 15:21:21 UTC 2009


 cli.py          |    2 +-
 yum/comps.py    |   13 ++-----------
 yum/depsolve.py |   36 ++++++++++++++----------------------
 3 files changed, 17 insertions(+), 34 deletions(-)

New commits:
commit a0448fb4701b6230a4bf400b03f23f793ea5ed0a
Author: Ville Skyttä <ville.skytta at iki.fi>
Date:   Sat Oct 17 17:02:25 2009 +0300

    Replace some cmp based sorts with key based ones.

diff --git a/cli.py b/cli.py
index b098a9f..ef23717 100644
--- a/cli.py
+++ b/cli.py
@@ -138,7 +138,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         """
         usage = 'yum [options] COMMAND\n\nList of Commands:\n\n'
         commands = yum.misc.unique(self.yum_cli_commands.values())
-        commands.sort(cmp=lambda x,y : cmp(x.getNames()[0], y.getNames()[0]))
+        commands.sort(key=lambda x: x.getNames()[0])
         for command in commands:
             # XXX Remove this when getSummary is common in plugins
             try:
diff --git a/yum/comps.py b/yum/comps.py
index 2048c77..1e91b64 100755
--- a/yum/comps.py
+++ b/yum/comps.py
@@ -389,23 +389,14 @@ class Comps(object):
                               # lists, yet.
 
 
-    def __sort_order(self, item1, item2):
-        """ This sorts for machines, so is the same in all locales. """
-        if item1.display_order > item2.display_order:
-            return 1
-        elif item1.display_order == item2.display_order:
-            return cmp(item1.name, item2.name)
-        else:
-            return -1
-    
     def get_groups(self):
         grps = self._groups.values()
-        grps.sort(self.__sort_order)
+        grps.sort(key=lambda x: (x.display_order, x.name))
         return grps
         
     def get_categories(self):
         cats = self._categories.values()
-        cats.sort(self.__sort_order)
+        cats.sort(key=lambda x: (x.display_order, x.name))
         return cats
     
     groups = property(get_groups)
diff --git a/yum/depsolve.py b/yum/depsolve.py
index d9b5e6f..e5b3a42 100644
--- a/yum/depsolve.py
+++ b/yum/depsolve.py
@@ -812,18 +812,15 @@ class Depsolve(object):
         return CheckDeps, CheckInstalls, CheckRemoves, any_missing
 
     @staticmethod
-    def _sort_reqs(pkgtup1, pkgtup2):
-        """ Sort the requires for a package from most "narrow" to least,
+    def _sort_req_key(pkgtup):
+        """ Get a sort key for a package requires from most "narrow" to least,
             this tries to ensure that if we have two reqs like
             "libfoo = 1.2.3-4" and "foo-api" (which is also provided by
             libxyz-foo) that we'll get just libfoo.
             There are other similar cases this "handles"."""
 
-        mapper = {'EQ' : 1, 'LT' : 2, 'LE' : 3, 'GT' : 4, 'GE' : 5,
-                  None : 99}
-        ret = mapper.get(pkgtup1[1], 10) - mapper.get(pkgtup2[1], 10)
-        if ret:
-            return ret
+        mapper = {'EQ' : 1, 'LT' : 2, 'LE' : 3, 'GT' : 4, 'GE' : 5, None : 99}
+        flagscore = mapper.get(pkgtup[1], 10)
 
         # This is pretty magic, basically we want an explicit:
         #
@@ -835,12 +832,13 @@ class Depsolve(object):
         #
         # ...because sometimes the libfoo.so.0() is provided by multiple
         # packages. Do we need more magic for other implicit deps. here?
-        def _req_name2val(name):
-            if (name.startswith("lib") and
-                (name.endswith("()") or name.endswith("()(64bit)"))):
-                return 99 # Processes these last
-            return 0
-        return _req_name2val(pkgtup1[0]) - _req_name2val(pkgtup2[0])
+
+        namescore = 0
+        if pkgtup[0].startswith("lib") and \
+                (pkgtup[0].endswith("()") or pkgtup[0].endswith("()(64bit)")):
+            namescore = 99 # Processes these last
+
+        return (flagscore, namescore)
 
     def _checkInstall(self, txmbr):
         txmbr_reqs = txmbr.po.returnPrco('requires')
@@ -854,7 +852,7 @@ class Depsolve(object):
         oldreqs = set(oldreqs)
 
         ret = []
-        for req in sorted(txmbr_reqs, cmp=self._sort_reqs):
+        for req in sorted(txmbr_reqs, key=self._sort_req_key):
             if req[0].startswith('rpmlib('):
                 continue
             if req in txmbr_provs:
@@ -1006,13 +1004,6 @@ class Depsolve(object):
            return a dictionary of po=score"""
         self.verbose_logger.log(logginglevels.DEBUG_4,
               _("Running compare_providers() for %s") %(str(pkgs)))
-
-        def _cmp_best_providers(x, y):
-            """ Compare first by score, and then compare the pkgs if the score
-                is the same. Note that this sorts in reverse. """
-            ret = cmp(y[1], x[1])
-            if ret: return ret
-            return cmp(y[0], x[0])
         
         def _common_prefix_len(x, y, minlen=2):
             num = min(len(x), len(y))
@@ -1181,7 +1172,8 @@ class Depsolve(object):
                     pkgresults[po] += 8
             pkgresults[po] += (len(po.name)*-1)
 
-        bestorder = sorted(pkgresults.items(), cmp=_cmp_best_providers)
+        bestorder = sorted(pkgresults.items(),
+                           key=lambda x: (x[1], x[0]), reverse=True)
         self.verbose_logger.log(logginglevels.DEBUG_4,
                 _('Best Order: %s' % str(bestorder)))
 


More information about the Yum-commits mailing list