[yum-git] Branch 'yum-3_2_X' - 2 commits - yum/config.py yum/__init__.py yum/logginglevels.py yummain.py

James Antill james at linux.duke.edu
Thu Aug 7 22:59:09 UTC 2008


 yum/__init__.py      |    5 ++++-
 yum/config.py        |    4 ++--
 yum/logginglevels.py |   37 ++++++++++++++++++++++++++++++++++++-
 yummain.py           |    3 ++-
 4 files changed, 44 insertions(+), 5 deletions(-)

New commits:
commit 50b058ad327d60dec7b72842d4bd321a1ebec793
Author: James Antill <james at and.org>
Date:   Thu Aug 7 18:55:08 2008 -0400

     Move syslog configs. to StatupConfig, act on them in logging. use LOG_DAEMON
      Fixes: bug 450949

diff --git a/yum/__init__.py b/yum/__init__.py
index 07a21a7..5e58a0b 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -157,6 +157,8 @@ class YumBase(depsolve.Depsolve):
         @param enabled_plugins: Plugins to be enabled
         '''
 
+        # ' xemacs syntax hack
+
         if self._conf:
             return self._conf
         conf_st = time.time()            
@@ -176,7 +178,8 @@ class YumBase(depsolve.Depsolve):
         if errorlevel != None:
             startupconf.errorlevel = errorlevel
 
-        self.doLoggingSetup(startupconf.debuglevel, startupconf.errorlevel)
+        self.doLoggingSetup(startupconf.debuglevel, startupconf.errorlevel,
+                            startupconf.syslog_ident, startupconf.syslog_facility)
 
         if init_plugins and startupconf.plugins:
             self.doPluginSetup(optparser, plugin_types, startupconf.pluginpath,
diff --git a/yum/config.py b/yum/config.py
index 7f761e3..a924935 100644
--- a/yum/config.py
+++ b/yum/config.py
@@ -581,6 +581,8 @@ class StartupConf(BaseConfig):
     pluginpath = ListOption(['/usr/share/yum-plugins', '/usr/lib/yum-plugins'])
     pluginconfpath = ListOption(['/etc/yum/pluginconf.d'])
     gaftonmode = BoolOption(False)
+    syslog_ident = Option()
+    syslog_facility = Option('LOG_DAEMON')
 
 class YumConf(StartupConf):
     '''
@@ -596,8 +598,6 @@ class YumConf(StartupConf):
     keepcache = BoolOption(True)
     logfile = Option('/var/log/yum.log')
     reposdir = ListOption(['/etc/yum/repos.d', '/etc/yum.repos.d'])
-    syslog_ident = Option()
-    syslog_facility = Option('LOG_DAEMON')
 
     commands = ListOption()
     exclude = ListOption()
diff --git a/yum/logginglevels.py b/yum/logginglevels.py
index ce7a92c..ba7f718 100644
--- a/yum/logginglevels.py
+++ b/yum/logginglevels.py
@@ -45,8 +45,38 @@ logging.addLevelName(DEBUG_4, "DEBUG_4")
 __NO_LOGGING = 100
 logging.raiseExceptions = False
 
+import syslog as syslog_module
+
 syslog = None
 
+# Mostly borrowed from original yum-updated.py
+_syslog_facility_map = { "KERN"   : syslog_module.LOG_KERN,
+                         "USER"   : syslog_module.LOG_USER,
+                         "MAIL"   : syslog_module.LOG_MAIL,
+                         "DAEMON" : syslog_module.LOG_DAEMON,
+                         "AUTH"   : syslog_module.LOG_AUTH,
+                         "LPR"    : syslog_module.LOG_LPR,
+                         "NEWS"   : syslog_module.LOG_NEWS,
+                         "UUCP"   : syslog_module.LOG_UUCP,
+                         "CRON"   : syslog_module.LOG_CRON,
+                         "LOCAL0" : syslog_module.LOG_LOCAL0,
+                         "LOCAL1" : syslog_module.LOG_LOCAL1,
+                         "LOCAL2" : syslog_module.LOG_LOCAL2,
+                         "LOCAL3" : syslog_module.LOG_LOCAL3,
+                         "LOCAL4" : syslog_module.LOG_LOCAL4,
+                         "LOCAL5" : syslog_module.LOG_LOCAL5,
+                         "LOCAL6" : syslog_module.LOG_LOCAL6,
+                         "LOCAL7" : syslog_module.LOG_LOCAL7,}
+def syslogFacilityMap(self, facility):
+    if type(facility) == int:
+        return facility
+    elif facility.upper() in _syslog_facility_map:
+        return _syslog_facility_map[facility.upper()]
+    elif (facility.upper().startswith("LOG_") and
+          facility[4:].upper() in _syslog_facility_map):
+        return _syslog_facility_map[facility[4:].upper()]
+    return syslog.LOG_USER
+
 def logLevelFromErrorLevel(error_level):
     """ Convert an old-style error logging level to the new style. """
     error_table = { -1 : __NO_LOGGING, 0 : logging.CRITICAL, 1 : logging.ERROR,
@@ -87,7 +117,8 @@ def setErrorLevel(level):
     logging.getLogger("yum").setLevel(converted_level)
 
 _added_handlers = False
-def doLoggingSetup(debuglevel, errorlevel):
+def doLoggingSetup(debuglevel, errorlevel,
+                   syslog_ident=None, syslog_facility=None):
     """
     Configure the python logger.
     
@@ -133,6 +164,10 @@ def doLoggingSetup(debuglevel, errorlevel):
             syslog = logging.handlers.SysLogHandler(log_dev)
             syslog.setFormatter(syslogformatter)
             filelogger.addHandler(syslog)
+            if syslog_ident is not None or syslog_facility is not None:
+                ident = syslog_ident    or ''
+                facil = syslog_facility or 'LOG_USER'
+                syslog_module.openlog(ident, 0, syslogFacilityMap(facil))
         except socket.error:
             if syslog is not None:
                 syslog.close()
commit adfa2f4dff6b3669121bba3257a77a9895734219
Author: James Antill <james at and.org>
Date:   Thu Aug 7 15:06:00 2008 -0400

    Another unicode => to_unicode, hopefully fixes 447504

diff --git a/yummain.py b/yummain.py
index 1787d4f..27c6b2c 100755
--- a/yummain.py
+++ b/yummain.py
@@ -28,6 +28,7 @@ from yum import Errors
 from yum import plugins
 from yum import logginglevels
 from yum import _
+from yum.misc import to_unicode
 import cli
 
 
@@ -74,7 +75,7 @@ def main(args):
         return 1
 
     def exFatal(e):
-        logger.critical('\n\n%s', unicode(e))
+        logger.critical('\n\n%s', to_unicode(e))
         if unlock(): return 200
         return 1
 



More information about the Yum-cvs-commits mailing list