[yum-commits] Branch 'yum-3_2_X' - 3 commits - utils.py yum/comps.py yum/Errors.py yum/__init__.py yummain.py yum/misc.py

James Antill james at osuosl.org
Fri Dec 10 20:45:24 UTC 2010


 utils.py        |   43 ++++++++++++++++++++++++++++++++-----------
 yum/Errors.py   |    2 +-
 yum/__init__.py |    7 +++++--
 yum/comps.py    |    5 ++++-
 yum/misc.py     |    4 ++--
 yummain.py      |   16 ++++++++--------
 6 files changed, 52 insertions(+), 25 deletions(-)

New commits:
commit 1aa7b07093ebb2b37607dc1d1b3afc6146f8e342
Author: James Antill <james at and.org>
Date:   Fri Dec 10 14:38:54 2010 -0500

    Use exception2msg in utils.py.

diff --git a/utils.py b/utils.py
index 837c9b6..ced6ba0 100644
--- a/utils.py
+++ b/utils.py
@@ -129,6 +129,27 @@ def show_lock_owner(pid, logger):
     return ps
 
 
+def exception2msg(e):
+    """ DIE python DIE! Which one works:
+        to_unicode(e.value); unicode(e); str(e); 
+        Call this so you don't have to care. """
+    try:
+        return to_unicode(e.value)
+    except:
+        pass
+
+    try:
+        return unicode(e)
+    except:
+        pass
+
+    try:
+        return str(e)
+    except:
+        pass
+    return "<exception failed to convert to text>"
+
+
 class YumUtilBase(YumBaseCli):
     def __init__(self,name,ver,usage):
         YumBaseCli.__init__(self)
@@ -154,7 +175,7 @@ class YumUtilBase(YumBaseCli):
         if e.errno == 32:
             self.logger.critical(_('\n\nExiting on Broken Pipe'))
         else:
-            self.logger.critical(_('\n\n%s') % str(e))
+            self.logger.critical(_('\n\n%s') % exception2msg(e))
         if self.unlock(): return 200
         return 1
 
@@ -163,14 +184,14 @@ class YumUtilBase(YumBaseCli):
 
         Log the plugin's exit message if one was supplied.
         ''' # ' xemacs hack
-        exitmsg = str(e)
+        exitmsg = exception2msg(e)
         if exitmsg:
             self.logger.warn('\n\n%s', exitmsg)
         if self.unlock(): return 200
         return 1
 
     def exFatal(self, e):
-        self.logger.critical('\n\n%s', to_unicode(e.value))
+        self.logger.critical('\n\n%s', exception2msg(e))
         if self.unlock(): return 200
         return 1
         
@@ -196,8 +217,8 @@ class YumUtilBase(YumBaseCli):
             try:
                 self.doLock()
             except Errors.LockError, e:
-                if "%s" %(e.msg,) != lockerr:
-                    lockerr = "%s" %(e.msg,)
+                if exception2msg(e) != lockerr:
+                    lockerr = exception2msg(e)
                     self.logger.critical(lockerr)
                 if not self.conf.exit_on_lock:
                     self.logger.critical("Another app is currently holding the yum lock; waiting for it to exit...")  
@@ -257,16 +278,16 @@ class YumUtilBase(YumBaseCli):
                     setattr(self.conf, opt, getattr(self.main_setopts, opt))
 
         except Errors.ConfigError, e:
-            self.logger.critical(_('Config Error: %s'), e)
+            self.logger.critical(_('Config Error: %s'), exception2msg(e))
             sys.exit(1)
         except ValueError, e:
-            self.logger.critical(_('Options Error: %s'), e)
+            self.logger.critical(_('Options Error: %s'), exception2msg(e))
             sys.exit(1)
         except plugins.PluginYumExit, e:
-            self.logger.critical(_('PluginExit Error: %s'), e)
+            self.logger.critical(_('PluginExit Error: %s'), exception2msg(e))
             sys.exit(1)
         except Errors.YumBaseError, e:
-            self.logger.critical(_('Yum Error: %s'), e)
+            self.logger.critical(_('Yum Error: %s'), exception2msg(e))
             sys.exit(1)
             
         # update usage in case plugins have added commands
@@ -294,7 +315,7 @@ class YumUtilBase(YumBaseCli):
             self._getRepos(doSetup = True)
             self._getSacks()
         except Errors.YumBaseError, msg:
-            self.logger.critical(str(msg))
+            self.logger.critical(exception2msg(msg))
             sys.exit(1)
 
     def doUtilBuildTransaction(self, unfinished_transactions_check=True):
@@ -304,7 +325,7 @@ class YumUtilBase(YumBaseCli):
             return self.exPluginExit(e)
         except Errors.YumBaseError, e:
             result = 1
-            resultmsgs = [unicode(e)]
+            resultmsgs = [exception2msg(e)]
         except KeyboardInterrupt:
             return self.exUserCancel()
         except IOError, e:
diff --git a/yummain.py b/yummain.py
index 39df675..c64b140 100755
--- a/yummain.py
+++ b/yummain.py
@@ -31,33 +31,13 @@ from yum import _
 from yum.i18n import to_unicode, utf8_width
 import yum.misc
 import cli
-from utils import suppress_keyboard_interrupt_message, show_lock_owner
+from utils import suppress_keyboard_interrupt_message, show_lock_owner, exception2msg
 
 def main(args):
     """This does all the real work"""
 
     yum.misc.setup_locale(override_time=True)
 
-    def exception2msg(e):
-        """ DIE python DIE! Which one works:
-            to_unicode(e.value); unicode(e); str(e); 
-            Call this so you don't have to care. """
-        try:
-            return to_unicode(e.value)
-        except:
-            pass
-
-        try:
-            return unicode(e)
-        except:
-            pass
-
-        try:
-            return str(e)
-        except:
-            pass
-        return "<exception failed to convert to text>"
-
     def exUserCancel():
         logger.critical(_('\n\nExiting on user cancel'))
         if unlock(): return 200
commit 4e51c4d16ee80d860f8846729b1e1ebe2693b2a0
Author: James Antill <james at and.org>
Date:   Fri Dec 10 14:17:47 2010 -0500

    Don't write when in cache mode, for comps/tags, and catch IOError for comps.

diff --git a/yum/__init__.py b/yum/__init__.py
index 45123a3..1b36994 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -780,7 +780,9 @@ class YumBase(depsolve.Depsolve):
             groupfile = repo.getGroups()
             # open it up as a file object so iterparse can cope with our compressed file
             if groupfile:
-                groupfile = misc.repo_gen_decompress(groupfile, 'groups.xml')
+                groupfile = misc.repo_gen_decompress(groupfile, 'groups.xml',
+                                                     cached=repo.cache)
+                # Do we want a RepoError here?
                 
             try:
                 self._comps.add(groupfile)
@@ -819,7 +821,8 @@ class YumBase(depsolve.Depsolve):
                 try:
                     tag_md = repo.retrieveMD('pkgtags')
                     tag_sqlite  = misc.repo_gen_decompress(tag_md,
-                                                           'pkgtags.sqlite')
+                                                           'pkgtags.sqlite',
+                                                           cached=repo.cache)
                     # feed it into _tags.add()
                     self._tags.add(repo.id, tag_sqlite)
                 except (Errors.RepoError, Errors.PkgTagsError), e:
diff --git a/yum/comps.py b/yum/comps.py
index 408bb1c..65f6d5e 100755
--- a/yum/comps.py
+++ b/yum/comps.py
@@ -503,7 +503,10 @@ class Comps(object):
             
         if type(srcfile) in types.StringTypes:
             # srcfile is a filename string
-            infile = open(srcfile, 'rt')
+            try:
+                infile = open(srcfile, 'rt')
+            except IOError, e:
+                raise CompsException, 'open(%s): #%u %s' % (srcfile, e.errno, e.strerror)
         else:
             # srcfile is a file object
             infile = srcfile
diff --git a/yum/misc.py b/yum/misc.py
index 4fa5ed9..4a1ede2 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -1077,7 +1077,7 @@ def decompress(filename, dest=None, fn_only=False, check_timestamps=False):
         
     return out
     
-def repo_gen_decompress(filename, generated_name):
+def repo_gen_decompress(filename, generated_name, cached=False):
     """ This is a wrapper around decompress, where we work out a cached
         generated name, and use check_timestamps. filename _must_ be from
         a repo. and generated_name is the type of the file. """
@@ -1086,7 +1086,7 @@ def repo_gen_decompress(filename, generated_name):
     if not os.path.exists(dest):
         os.makedirs(dest, mode=0755)
     dest += '/' + generated_name
-    return decompress(filename, dest=dest, check_timestamps=True)
+    return decompress(filename, dest=dest, check_timestamps=True,fn_only=cached)
     
 def read_in_items_from_dot_dir(thisglob, line_as_list=True):
     """takes a glob of a dir (like /etc/foo.d/*.foo)
commit ac5f8eac5aec8cf8c017e3312f194aac0b55d10a
Author: James Antill <james at and.org>
Date:   Fri Dec 10 13:53:03 2010 -0500

    Get the sledgehammer out and "fix" unicode exceptions. BZ 662148

diff --git a/yum/Errors.py b/yum/Errors.py
index 143c9a4..c1af4ad 100644
--- a/yum/Errors.py
+++ b/yum/Errors.py
@@ -65,7 +65,7 @@ class YumRPMTransError(YumBaseError):
 
 class LockError(YumBaseError):
     def __init__(self, errno, msg, pid=0):
-        YumBaseError.__init__(self)
+        YumBaseError.__init__(self, msg)
         self.errno = errno
         self.msg = msg
         self.pid = pid
diff --git a/yummain.py b/yummain.py
index 0241684..39df675 100755
--- a/yummain.py
+++ b/yummain.py
@@ -38,6 +38,26 @@ def main(args):
 
     yum.misc.setup_locale(override_time=True)
 
+    def exception2msg(e):
+        """ DIE python DIE! Which one works:
+            to_unicode(e.value); unicode(e); str(e); 
+            Call this so you don't have to care. """
+        try:
+            return to_unicode(e.value)
+        except:
+            pass
+
+        try:
+            return unicode(e)
+        except:
+            pass
+
+        try:
+            return str(e)
+        except:
+            pass
+        return "<exception failed to convert to text>"
+
     def exUserCancel():
         logger.critical(_('\n\nExiting on user cancel'))
         if unlock(): return 200
@@ -47,7 +67,7 @@ def main(args):
         if e.errno == 32:
             logger.critical(_('\n\nExiting on Broken Pipe'))
         else:
-            logger.critical(_('\n\n%s') % str(e))
+            logger.critical(_('\n\n%s') % exception2msg(e))
         if unlock(): return 200
         return 1
 
@@ -56,14 +76,14 @@ def main(args):
 
         Log the plugin's exit message if one was supplied.
         ''' # ' xemacs hack
-        exitmsg = str(e)
+        exitmsg = exception2msg(e)
         if exitmsg:
             logger.warn('\n\n%s', exitmsg)
         if unlock(): return 200
         return 1
 
     def exFatal(e):
-        logger.critical('\n\n%s', to_unicode(e.value))
+        logger.critical('\n\n%s', exception2msg(e.value))
         if unlock(): return 200
         return 1
 
@@ -96,8 +116,8 @@ def main(args):
         try:
             base.doLock()
         except Errors.LockError, e:
-            if "%s" %(e.msg,) != lockerr:
-                lockerr = "%s" %(e.msg,)
+            if exception2msg(e) != lockerr:
+                lockerr = exception2msg(e)
                 logger.critical(lockerr)
             if not base.conf.exit_on_lock:
                 logger.critical(_("Another app is currently holding the yum lock; waiting for it to exit..."))
@@ -117,7 +137,7 @@ def main(args):
         return exPluginExit(e)
     except Errors.YumBaseError, e:
         result = 1
-        resultmsgs = [unicode(e)]
+        resultmsgs = [exception2msg(e)]
     except KeyboardInterrupt:
         return exUserCancel()
     except IOError, e:
@@ -158,7 +178,7 @@ def main(args):
         return exPluginExit(e)
     except Errors.YumBaseError, e:
         result = 1
-        resultmsgs = [unicode(e)]
+        resultmsgs = [exception2msg(e)]
     except KeyboardInterrupt:
         return exUserCancel()
     except IOError, e:


More information about the Yum-commits mailing list