[yum-git] Branch 'yum-3_2_X' - yumcommands.py

James Antill james at linux.duke.edu
Sun Sep 21 14:24:20 UTC 2008


 yumcommands.py |   58 +++++++++++++++++++++++++++++++--------------------------
 1 file changed, 32 insertions(+), 26 deletions(-)

New commits:
commit 284a9eabca4a9a5368044b7d5b447c66b38754e2
Author: James Antill <james at and.org>
Date:   Sat Sep 20 16:38:01 2008 -0400

    Dynamically size check-update using the "list updates" code

diff --git a/yumcommands.py b/yumcommands.py
index ba1f139..0e07cd3 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -196,6 +196,34 @@ class UpdateCommand(YumCommand):
         except yum.Errors.YumBaseError, e:
             return 1, [str(e)]
 
+def _add_pkg_simple_list_lens(data, pkg, indent=''):
+    """ Get the length of each pkg's column. Add that to data.
+        This "knows" about simpleList and printVer. """
+    na  = len(pkg.name)    + 1 + len(pkg.arch)    + len(indent)
+    ver = len(pkg.version) + 1 + len(pkg.release)
+    rid = len(pkg.repoid)
+    if pkg.epoch != '0':
+        ver += len(pkg.epoch) + 1
+    for (d, v) in (('na', na), ('ver', ver), ('rid', rid)):
+        data[d].setdefault(v, 0)
+        data[d][v] += 1
+
+def _list_cmd_calc_columns(base, ypl):
+    """ Work out the dynamic size of the columns to pass to fmtColumns. """
+    data = {'na' : {}, 'ver' : {}, 'rid' : {}}
+    for lst in (ypl.installed, ypl.available, ypl.extras,
+                ypl.updates, ypl.recent):
+        for pkg in lst:
+            _add_pkg_simple_list_lens(data, pkg)
+    if len(ypl.obsoletes) > 0:
+        for (npkg, opkg) in ypl.obsoletesTuples:
+            _add_pkg_simple_list_lens(data, npkg)
+            _add_pkg_simple_list_lens(data, opkg, indent=" " * 4)
+
+    data = [data['na'], data['ver'], data['rid']]
+    columns = base.calcColumns(data, remainder_column=1)
+    return (-columns[0], -columns[1], -columns[2])
+
 class InfoCommand(YumCommand):
     def getNames(self):
         return ['info']
@@ -217,31 +245,7 @@ class InfoCommand(YumCommand):
             columns = None
             if basecmd == 'list':
                 # Dynamically size the columns
-                def _add_pkg_simple_list_lens(data, pkg, indent=''):
-                    """ Get the length of each pkg's column. Add that to data.
-                        This "knows" about simpleList and printVer. """
-                    na  = len(pkg.name)    + 1 + len(pkg.arch)    + len(indent)
-                    ver = len(pkg.version) + 1 + len(pkg.release)
-                    rid = len(pkg.repoid)
-                    if pkg.epoch != '0':
-                        ver += len(pkg.epoch) + 1
-                    for (d, v) in (('na', na), ('ver', ver), ('rid', rid)):
-                        data[d].setdefault(v, 0)
-                        data[d][v] += 1
-
-                data = {'na' : {}, 'ver' : {}, 'rid' : {}}
-                for lst in (ypl.installed, ypl.available, ypl.extras,
-                            ypl.updates, ypl.recent):
-                    for pkg in lst:
-                        _add_pkg_simple_list_lens(data, pkg)
-                if len(ypl.obsoletes) > 0:
-                    for (npkg, opkg) in ypl.obsoletesTuples:
-                        _add_pkg_simple_list_lens(data, npkg)
-                        _add_pkg_simple_list_lens(data, opkg, indent=" " * 4)
-
-                data = [data['na'], data['ver'], data['rid']]
-                columns = base.calcColumns(data, remainder_column=1)
-                columns = (-columns[0], -columns[1], -columns[2])
+                columns = _list_cmd_calc_columns(base, ypl)
 
             if ypl.installed:
                 #  If we have installed and available lists, then do the
@@ -527,8 +531,10 @@ class CheckUpdateCommand(YumCommand):
         result = 0
         try:
             ypl = base.returnPkgLists(extcmds)
+            columns = _list_cmd_calc_columns(base, ypl)
             if len(ypl.updates) > 0:
-                base.listPkgs(ypl.updates, '', outputType='list')
+                base.listPkgs(ypl.updates, '', outputType='list',
+                              columns=columns)
                 result = 100
         except yum.Errors.YumBaseError, e:
             return 1, [str(e)]



More information about the Yum-cvs-commits mailing list