[yum-git] Branch 'yum-3_2_X' - 2 commits - cli.py output.py yumcommands.py

James Antill james at linux.duke.edu
Wed Aug 13 15:07:14 UTC 2008


 cli.py         |   10 ------
 output.py      |   83 ++++++++++++++++++++++++++++++++++++---------------------
 yumcommands.py |    7 ++++
 3 files changed, 60 insertions(+), 40 deletions(-)

New commits:
commit 381aba7da0c4aad2bb1a7ef8d360f205b7cfb8be
Author: James Antill <james at and.org>
Date:   Wed Aug 13 10:55:18 2008 -0400

    Delete some old, misleading, comments in returnPkgLists

diff --git a/cli.py b/cli.py
index 90e5e44..c3cbc36 100644
--- a/cli.py
+++ b/cli.py
@@ -638,10 +638,8 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
             
         ypl = self.doPackageLists(pkgnarrow=pkgnarrow, patterns=extcmds,
                                   ignore_case=True)
-        # rework the list output code to know about:
-        # obsoletes output
-        # the updates format
 
+        # This is mostly leftover from when patterns didn't exist
         def _shrinklist(lst, args):
             if len(lst) > 0 and len(args) > 0:
                 self.verbose_logger.log(yum.logginglevels.DEBUG_1,
@@ -658,12 +656,6 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         ypl.extras = _shrinklist(ypl.extras, extcmds)
         ypl.obsoletes = _shrinklist(ypl.obsoletes, extcmds)
         
-#        for lst in [ypl.obsoletes, ypl.updates]:
-#            if len(lst) > 0 and len(extcmds) > 0:
-#                self.logger.log(4, 'Matching packages for tupled package list to user args')
-#                for (pkg, instpkg) in lst:
-#                    exactmatch, matched, unmatched = yum.packages.parsePackages(lst, extcmds)
-                    
         return ypl
 
     def search(self, args):
commit f84343903b4325d94ee480b77646cd5ff0d568a1
Author: James Antill <james at and.org>
Date:   Wed Aug 13 10:51:36 2008 -0400

     Add highlighting to packages which have updates in list commands,
    like list/info/groupinfo. Add some helper functions.
     This makes it more obvious what is "available to install" and what is
    "available to update".
    
     We also only do the processiing when we have the installed+available
    this is a feature.

diff --git a/output.py b/output.py
index 212937a..23334a5 100644
--- a/output.py
+++ b/output.py
@@ -245,21 +245,34 @@ class YumOutput:
         
     def simpleProgressBar(self, current, total, name=None):
         progressbar(current, total, name)
-    
-    def simpleList(self, pkg, ui_overflow=False):
+
+    def _highlight(self, highlight):
+        if highlight:
+            hibeg = self.term.MODE['bold']
+            hiend = self.term.MODE['normal']
+        else:
+            hibeg = ''
+            hiend = ''
+        return (hibeg, hiend)
+
+    def simpleList(self, pkg, ui_overflow=False, indent='', highlight=False):
+        (hibeg, hiend) = self._highlight(highlight)
         ver = pkg.printVer()
-        na = '%s.%s' % (pkg.name, pkg.arch)
-        if ui_overflow and len(na) > 40:
-            print "%s %s" % (na, "...")
+        na = '%s%s.%s' % (indent, pkg.name, pkg.arch)
+        if ui_overflow and (len(na) - (len(hibeg) + len(hiend))) > 40:
+            print "%s%s%s %s" % (hibeg, na, hiend, "...")
             na = ""
-        print "%-40.40s %-22.22s %-16.16s" % (na, ver, pkg.repoid)
-
-    def simpleEnvraList(self, pkg, ui_overflow=False, indent=''):
-        envra = "%s%s" % (indent, str(pkg))
-        if ui_overflow and len(envra) > 63:
-            print "%s %s" % (envra, "...")
+        print "%s%-40.40s%s %-22.22s %-16.16s" % (hibeg, na, hiend,
+                                                  ver, pkg.repoid)
+
+    def simpleEnvraList(self, pkg, ui_overflow=False,
+                        indent='', highlight=False):
+        (hibeg, hiend) = self._highlight(highlight)
+        envra = '%s%s' % (indent, str(pkg))
+        if ui_overflow and (len(envra) - (len(hibeg) + len(hiend))) > 63:
+            print "%s%s%s %s" % (hibeg, envra, hiend, "...")
             envra = ""
-        print "%-63.63s %-16.16s" % (envra, pkg.repoid)
+        print "%s%-63.63s%s %-16.16s" % (hibeg, envra, hiend, pkg.repoid)
 
     def fmtKeyValFill(self, key, val):
         """ Return a key value pair in the common two column output format. """
@@ -300,8 +313,9 @@ class YumOutput:
                     break
         return to_unicode(s)
 
-    def infoOutput(self, pkg):
-        print _("Name       : %s") % pkg.name
+    def infoOutput(self, pkg, highlight=False):
+        (hibeg, hiend) = self._highlight(highlight)
+        print _("Name       : %s%s%s") % (hibeg, pkg.name, hiend)
         print _("Arch       : %s") % pkg.arch
         if pkg.epoch != "0":
             print _("Epoch      : %s") % pkg.epoch
@@ -333,21 +347,25 @@ class YumOutput:
         # FIXME - other ideas for how to print this out?
         print '%-35.35s [%.12s] %.10s %-20.20s' % (c_compact, c_repo, changetype, i_compact)
 
-    def listPkgs(self, lst, description, outputType):
+    def listPkgs(self, lst, description, outputType, highlight_na={}):
         """outputs based on whatever outputType is. Current options:
            'list' - simple pkg list
-           'info' - similar to rpm -qi output"""
-        
+           'info' - similar to rpm -qi output
+           ...also highlight_na can be passed, and we'll highlight
+           pkgs with (names, arch) in that set."""
+
         if outputType in ['list', 'info']:
             thingslisted = 0
             if len(lst) > 0:
                 thingslisted = 1
                 print '%s' % description
                 for pkg in sorted(lst):
+                    highlight = (pkg.name, pkg.arch) in highlight_na
                     if outputType == 'list':
-                        self.simpleList(pkg, ui_overflow=True)
+                        self.simpleList(pkg, ui_overflow=True,
+                                        highlight=highlight)
                     elif outputType == 'info':
-                        self.infoOutput(pkg)
+                        self.infoOutput(pkg, highlight=highlight)
                     else:
                         pass
     
@@ -392,25 +410,28 @@ class YumOutput:
         # FIXME what should we be printing here?
         return self.userconfirm()
 
-    def _group_names2pkgs(self, pkg_names):
-        # Convert pkg_names to installed pkgs and available pkgs
+    def _group_names2aipkgs(self, pkg_names):
+        """ Convert pkg_names to installed pkgs or available pkgs, return
+            value is a dict on pkg.name returning (apkg, ipkg). """
         ipkgs = self.rpmdb.searchNames(pkg_names)
         apkgs = self.pkgSack.searchNames(pkg_names)
         apkgs = packagesNewestByNameArch(apkgs)
 
-        # FIXME: Basically doPackageLists('all') behaviour
+        # This is somewhat similar to doPackageLists()
         pkgs = {}
         for pkg in ipkgs:
-            pkgs[(pkg.name, pkg.arch)] = pkg
+            pkgs[(pkg.name, pkg.arch)] = (None, pkg)
         for pkg in apkgs:
             key = (pkg.name, pkg.arch)
-            if key not in pkgs or pkg.verGT(pkgs[key]):
-                pkgs[(pkg.name, pkg.arch)] = pkg
+            if key not in pkgs:
+                pkgs[(pkg.name, pkg.arch)] = (pkg, None)
+            elif pkg.verGT(pkgs[key][1]):
+                pkgs[(pkg.name, pkg.arch)] = (pkg, pkgs[key][1])
 
         # Convert (pkg.name, pkg.arch) to pkg.name dict
         ret = {}
-        for pkg in pkgs.itervalues():
-            ret.setdefault(pkg.name, []).append(pkg)
+        for (apkg, ipkg) in pkgs.itervalues():
+            ret.setdefault(pkg.name, []).append((apkg, ipkg))
         return ret
 
     def _displayPkgsFromNames(self, pkg_names, verbose, pkg_names2pkgs,
@@ -423,8 +444,10 @@ class YumOutput:
                 if item not in pkg_names2pkgs:
                     print '%s%s' % (indent, item)
                     continue
-                for pkg in sorted(pkg_names2pkgs[item]):
-                    self.simpleEnvraList(pkg, ui_overflow=True, indent=indent)
+                for (apkg, ipkg) in sorted(pkg_names2pkgs[item],
+                                           key=lambda x: x[1] or x[0]):
+                    self.simpleEnvraList(ipkg or apkg, ui_overflow=True,
+                                         indent=indent, highlight=ipkg and apkg)
     
     def displayPkgsInGroups(self, group):
         mylang = get_my_lang_code()
@@ -433,7 +456,7 @@ class YumOutput:
         verb = self.verbose_logger.isEnabledFor(logginglevels.DEBUG_3)
         pkg_names2pkgs = None
         if verb:
-            pkg_names2pkgs = self._group_names2pkgs(group.packages)
+            pkg_names2pkgs = self._group_names2aipkgs(group.packages)
         if group.descriptionByLang(mylang) != "":
             print _(' Description: %s') % to_unicode(group.descriptionByLang(mylang))
         if len(group.mandatory_packages) > 0:
diff --git a/yumcommands.py b/yumcommands.py
index 2244ddb..f705e24 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -212,7 +212,12 @@ class InfoCommand(YumCommand):
         except yum.Errors.YumBaseError, e:
             return 1, [str(e)]
         else:
-            rip = base.listPkgs(ypl.installed, _('Installed Packages'), basecmd)
+            if ypl.installed:
+                update_pkgs = set([(po.name, po.arch) for po in ypl.available])
+            else:
+                update_pkgs = set()
+            rip = base.listPkgs(ypl.installed, _('Installed Packages'), basecmd,
+                                highlight_na=update_pkgs)
             rap = base.listPkgs(ypl.available, _('Available Packages'), basecmd)
             rep = base.listPkgs(ypl.extras, _('Extra Packages'), basecmd)
             rup = base.listPkgs(ypl.updates, _('Updated Packages'), basecmd)



More information about the Yum-cvs-commits mailing list