[yum-cvs] yum/callbacks.py yum/__init__.py

Tim Lauridsen timlau at linux.duke.edu
Thu Aug 23 08:21:56 UTC 2007


 yum/__init__.py  |   24 ++++++++++++------------
 yum/callbacks.py |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 12 deletions(-)

New commits:
commit 0a978617763acb9d8f9fdf90f9856bede99b4d97
Author: Tim Lauridsen <tla at rasmil.dk>
Date:   Thu Aug 23 10:16:08 2007 +0200

    Reworked the processTransaction callback a little.
    * Added yum/callbacks.py with callback classes to use with processTransaction
    * Dont parse strings to callback, use some flags insted
    * Dont call the callbacks at both start/end of each step, only at start

diff --git a/yum/__init__.py b/yum/__init__.py
index d1b6b1e..41cad75 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -45,6 +45,7 @@ import depsolve
 import plugins
 import logginglevels
 import yumRepo
+import callbacks
 
 import warnings
 warnings.simplefilter("ignore", Errors.YumFutureDeprecationWarning)
@@ -2183,22 +2184,21 @@ class YumBase(depsolve.Depsolve):
         @param rpmDisplay: Name of display class to use in RPM Transaction 
         '''
         
-        action = "Download Packages"
-        if callback: callback.event(action=action, state="Start")
+        if not callback:
+            callback = callbacks.ProcessTransNoOutputCallback()
+        
+        # Download Packages
+        callback.event(callbacks.PT_DOWNLOAD)
         pkgs = self._downloadPackages()
-        if callback: callback.event(action=action, state="End")
-        action = "Checking Signatures"
-        if callback: callback.event(action=action, state="Start")
+        # Check Package Signatures
+        callback.event(callbacks.PT_GPGCHECK)
         self._checkSignatures(pkgs)
-        if callback: callback.event(action=action, state="End")
-        action = "Test Transaction"
-        if callback: callback.event(action=action, state="Start")
+        # Run Test Transaction
+        callback.event(callbacks.PT_TEST_TRANS)
         self._doTestTransaction(display=rpmTestDisplay)
-        if callback: callback.event(action=action, state="End")
-        action = "Run Transaction"
-        if callback: callback.event(action=action, state="Start")
+        # Run Transaction
+        callback.event(callbacks.PT_TRANSACTION)
         self._doTransaction(display=rpmDisplay)
-        if callback: callback.event(action=action, state="End")
     
     def _downloadPackages(self):
         ''' Download the need packages in the Transaction '''
diff --git a/yum/callbacks.py b/yum/callbacks.py
new file mode 100644
index 0000000..10a2c43
--- /dev/null
+++ b/yum/callbacks.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python -tt
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+# imports
+
+import logging 
+
+# ProcessTransaction States
+
+PT_DOWNLOAD        = 0
+PT_GPGCHECK        = 1
+PT_TEST_TRANS      = 2
+PT_TRANSACTION     = 3
+
+PT_MESSAGES = { PT_DOWNLOAD    : "Downloading Packages",
+                PT_GPGCHECK    : "Check Package Signatures",
+                PT_TEST_TRANS  : "Running Test Transaction",
+                PT_TRANSACTION : "Running Transaction"}
+
+
+
+class ProcessTransBaseCallback:
+    
+    def __init__(self):
+        self.logger = logging.getLogger('yum.verbose.ProcessTrasactionBaseCallback')
+        
+    def event(self,state):
+        self.logger.info(PT_MESSAGES[state])
+
+class ProcessTransNoOutputCallback:
+    def __init__(self):
+        pass
+         
+    def event(self,state):
+        pass
+        



More information about the Yum-cvs-commits mailing list