[yum-cvs] yum yum-updatesd.py,1.38,1.39

Jeremy Katz katzj at linux.duke.edu
Wed Mar 28 16:00:50 UTC 2007


Update of /home/groups/yum/cvs/yum
In directory login1.linux.duke.edu:/tmp/cvs-serv16726

Modified Files:
	yum-updatesd.py 
Log Message:
make it so that we can pass back initialization errors to callers over the bus.
Patch from Ray Strode (halfline AT gmail DOT com)


Index: yum-updatesd.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum-updatesd.py,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- yum-updatesd.py	19 Mar 2007 19:34:24 -0000	1.38
+++ yum-updatesd.py	28 Mar 2007 16:00:47 -0000	1.39
@@ -28,6 +28,7 @@
 # $ dbus-send --system --print-reply --type=method_call \
 #   --dest=edu.duke.linux.yum /Updatesd edu.duke.linux.yum.CheckNow
 
+import gettext
 import os
 import sys
 import time
@@ -57,7 +58,7 @@
 import callback
 
 config_file = '/etc/yum/yum-updatesd.conf'
-
+initial_directory = os.getcwd()
 
 class UpdateEmitter(object):
     """Abstract object for implementing different types of emitters."""
@@ -82,6 +83,11 @@
         """Emitted when checking for updates failed."""
         pass
 
+    def setupFailed(self, error, translation_domain):
+       """Emitted when plugin initialization failed."""
+       pass
+ 
+
 class SyslogUpdateEmitter(UpdateEmitter):
     def __init__(self, syslog_facility, ident = "yum-updatesd",
                  level = "WARN"):
@@ -196,6 +202,10 @@
     def checkFailed(self, error):
         self.dbusintf.CheckFailedSignal(error)
 
+    def setupFailed(self, error, translation_domain):
+        self.dbusintf.SetupFailedSignal(error, translation_domain)
+
+
 class YumDbusInterface(dbus.service.Object):
     def __init__(self, bus_name, object_path='/UpdatesAvail'):
         dbus.service.Object.__init__(self, bus_name, object_path)
@@ -220,6 +230,11 @@
     def CheckFailedSignal(self, message):
         pass
 
+    @dbus.service.signal('edu.duke.linux.yum')
+    def SetupFailedSignal(self, message, translation_domain=""):
+        pass
+
+
 class UDConfig(BaseConfig):
     """Config format for the daemon"""
     run_interval = IntOption(3600)
@@ -316,7 +331,7 @@
     def __init__(self, opts):
         yum.YumBase.__init__(self)
         self.opts = opts
-        self.doSetup()
+        self.didSetup = False
 
         self.emitters = []
         if 'dbus' in self.opts.emit_via:
@@ -432,6 +447,27 @@
                 self.tsInfo.addObsoleted(installed, obsoleting)
 
     def updatesCheck(self):
+        if not self.didSetup:
+            try:
+                self.doSetup()
+            except Exception, e:
+                syslog.syslog(syslog.LOG_WARNING,
+                              "error initializing: %s" % e)
+
+                if isinstance(e, yum.plugins.PluginYumExit):
+                    self.emitSetupFailed(e.value, e.translation_domain)
+                else:
+                    # if we don't know where the string is from, then assume
+                    # it's not marked for translation (versus sending 
+                    # gettext.textdomain() and assuming it's from the default
+                    # domain for this app)
+                    self.emitSetupFailed(str(e))
+                # Setup failed, let's restart and try again after the update
+                # interval
+                restart()
+            else:
+                self.didSetup = True
+
         try:
             if not self.refreshUpdates():
                 return
@@ -519,6 +555,10 @@
         """method to emit a notice when checking for updates failed"""
         map(lambda x: x.checkFailed(error), self.emitters)
 
+    def emitSetupFailed(self, error, translation_domain=""):
+        """method to emit a notice when checking for updates failed"""
+        map(lambda x: x.setupFailed(error, translation_domain), self.emitters)
+
 
 class YumDbusListener(dbus.service.Object):
     def __init__(self, updd, bus_name, object_path='/Updatesd',
@@ -558,6 +598,10 @@
 def shutDown():
     sys.exit(0)
 
+def restart():
+    os.chdir(initial_directory)
+    os.execve(sys.argv[0], sys.argv, os.environ)  
+
 def main():
     # we'll be threading for downloads/updates
     gobject.threads_init()




More information about the Yum-cvs-commits mailing list