Hi,
I have cleaned up processTransaction a little and added yum/callbacks.py
with some callback classes to use with processTransaction
I have attached the patch and a test program.
Tim
diff --git a/yum/__init__.py b/yum/__init__.py
index 377fd0f..823ac5a 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
+
from utils import YumUtilBase
from yum.callbacks import ProcessTransBaseCallback
import output
import yum
name = 'test'
ver = '0.1'
usage = 'test [options] [args]'
yb = YumUtilBase(name,ver,usage)
yb.doUtilConfigSetup()
txmbr = yb.install(name='yum-utils')
if txmbr:
print "Installing : %s" % str(txmbr[0].po)
rc,msgs = yb.buildTransaction()
if rc !=2:
print "Dep Errors"
print "\n".join(msgs)
else:
try:
yb.processTransaction(callback=ProcessTransBaseCallback(),
rpmDisplay=output.YumCliRPMCallBack())
except yum.Errors.YumBaseError, msgs:
print "Error in Transaction Processing"
print "\n".join(msgs)
else:
print "nothing to do"
_______________________________________________
Yum-devel mailing list
[email protected]
https://lists.dulug.duke.edu/mailman/listinfo/yum-devel