[Yum-devel] [PATCH] display/retrieve additional history info we have stored

Seth Vidal skvidal at fedoraproject.org
Tue Jun 29 21:09:00 UTC 2010


- add 'addon-info' as an option to history cmd
- add return_addon_data as method of history class
- display that addon info is available in yum history info results
- update docs to mention it
---
 docs/yum.8     |    2 +-
 output.py      |   44 ++++++++++++++++++++++++++++++++++++++++++++
 yum/history.py |   17 ++++++++++++++++-
 yumcommands.py |    4 +++-
 4 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/docs/yum.8 b/docs/yum.8
index d5ede0a..527b33e 100644
--- a/docs/yum.8
+++ b/docs/yum.8
@@ -71,7 +71,7 @@ gnome\-packagekit application\&.
 .br
 .I \fR * version [ all | installed | available | group-* | nogroups* | grouplist | groupinfo ]
 .br
-.I \fR * history [info|list|summary|redo|undo|new] 
+.I \fR * history [info|list|summary|redo|undo|new|addon-info] 
 .br
 .I \fR * check
 .br 
diff --git a/output.py b/output.py
index 468b2df..ca6f667 100755
--- a/output.py
+++ b/output.py
@@ -1584,9 +1584,19 @@ to exit.
             print _("Return-Code    :"), _("Failure:"), old.return_code
         else:
             print _("Return-Code    :"), _("Success")
+            
         if old.cmdline is not None:
             print _("Command Line   :"), old.cmdline
 
+        addon_info = self.history.return_addon_data(old.tid)
+        
+        # for the ones we create by default - don't display them as there
+        default_addons = set(['activeconfig', 'enabled-repos'])
+        non_default = set(addon_info).difference(default_addons)
+        if len(non_default) > 0:
+                print _("Additional non-default information stored: %d" 
+                            % len(non_default))
+
         print _("Transaction performed with:")
         for hpkg in old.trans_with:
             _simple_pkg(hpkg, 4, was_installed=True)
@@ -1740,6 +1750,40 @@ to exit.
                              utf8_width_fill(uperiod, 19, 19),
                              utf8_width_fill(uiacts, 16, 16), count)
 
+    def historyAddonInfoCmd(self, extcmds):
+        tid = extcmds[1]
+        try:
+            int(tid)
+        except ValueError:
+            self.logger.critical(_('No transaction ID given'))
+            return 1, ['Failed history addon-info']
+
+        old = self.history.old(tids=[tid])
+        if old is None:
+            self.logger.critical(_('No Transaction %s found') % tid)
+            return 1, ['Failed history addon-info']
+            
+        hist_data = old[0]
+        addon_info = self.history.return_addon_data(hist_data.tid)
+        if len(extcmds) <= 2:
+            print 'Available additional history information:'
+            for itemname in self.history.return_addon_data(hist_data.tid):
+                print '  %s' % itemname
+            print ''
+            
+            return 0, ['history addon-info']
+            
+        
+        for item in extcmds[2:]:
+            if item in addon_info:
+                print '%s:' % item
+                print self.history.return_addon_data(hist_data.tid, item)
+            else:
+                print '%s: No additional data found by this name' % item
+
+            print ''
+
+
 
 class DepSolveProgressCallBack:
     """provides text output callback functions for Dependency Solver callback"""
diff --git a/yum/history.py b/yum/history.py
index 91c6f8d..502b908 100644
--- a/yum/history.py
+++ b/yum/history.py
@@ -619,7 +619,22 @@ class YumHistory:
         # return
         return True
         
-
+    def return_addon_data(self, tid, item=None):
+        hist_and_tid = self.conf.addon_path + '/' + str(tid) + '/'
+        addon_info = glob.glob(hist_and_tid + '*')
+        addon_names = [ i.replace(hist_and_tid, '') for i in addon_info ]
+        if not item:
+            return addon_names
+        
+        if item not in addon_names:
+            # XXX history needs SOME kind of exception, or warning, I think?
+            return None
+        
+        fo = open(hist_and_tid + item, 'r')
+        data = fo.read()
+        fo.close()
+        return data
+        
     def _old_with_pkgs(self, tid):
         cur = self._get_cursor()
         executeSQL(cur,
diff --git a/yumcommands.py b/yumcommands.py
index 6b134a4..a7f5d9e 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -1323,7 +1323,7 @@ class HistoryCommand(YumCommand):
         base.history._create_db_file()
 
     def doCheck(self, base, basecmd, extcmds):
-        cmds = ('list', 'info', 'summary', 'repeat', 'redo', 'undo', 'new')
+        cmds = ('list', 'info', 'summary', 'repeat', 'redo', 'undo', 'new', 'addon-info')
         if extcmds and extcmds[0] not in cmds:
             base.logger.critical(_('Invalid history sub-command, use: %s.'),
                                  ", ".join(cmds))
@@ -1347,6 +1347,8 @@ class HistoryCommand(YumCommand):
             ret = base.historyInfoCmd(extcmds)
         elif vcmd == 'summary':
             ret = base.historySummaryCmd(extcmds)
+        elif vcmd == 'addon-info':
+            ret = base.historyAddonInfoCmd(extcmds)
         elif vcmd == 'undo':
             ret = self._hcmd_undo(base, extcmds)
         elif vcmd in ('redo', 'repeat'):
-- 
1.7.0.1



More information about the Yum-devel mailing list