[yum-commits] cli.py utils.py yummain.py

zpavlas at osuosl.org zpavlas at osuosl.org
Mon Jan 7 08:49:43 UTC 2013


 cli.py     |   27 +++++++++++++++++++++++++++
 utils.py   |   24 ------------------------
 yummain.py |   24 ++----------------------
 3 files changed, 29 insertions(+), 46 deletions(-)

New commits:
commit 8c214b3beb69dcb18615288cf2684fe45377d927
Author: Zdeněk Pavlas <zpavlas at redhat.com>
Date:   Tue Dec 18 14:34:01 2012 +0100

    move waitForLock() from YumUtilBase to YumBaseCli, use it in yummain.
    
    - errno != 0 => fatal error
    - raise YumBaseError instead of sys.exit()/return
    - keep show_lock_owner() and get_process_info() in utils
      (lazy import is better than api break)

diff --git a/cli.py b/cli.py
index 4122d5d..9225d5a 100755
--- a/cli.py
+++ b/cli.py
@@ -451,6 +451,33 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         return summary
 
 
+    def waitForLock(self):
+        """Establish the yum lock.  If another process is already
+        holding the yum lock, by default this method will keep trying
+        to establish the lock until it is successful.  However, if
+        :attr:`self.conf.exit_on_lock` is set to True, it will
+        raise a :class:`Errors.YumBaseError`.
+        """
+        lockerr = ""
+        while True:
+            try:
+                self.doLock()
+            except yum.Errors.LockError, e:
+                if exception2msg(e) != lockerr:
+                    lockerr = exception2msg(e)
+                    self.logger.critical(lockerr)
+                if e.errno:
+                    raise yum.Errors.YumBaseError, _("Can't create lock file; exiting")
+                if not self.conf.exit_on_lock:
+                    self.logger.critical("Another app is currently holding the yum lock; waiting for it to exit...")
+                    import utils
+                    utils.show_lock_owner(e.pid, self.logger)
+                    time.sleep(2)
+                else:
+                    raise yum.Errors.YumBaseError, _("Another app is currently holding the yum lock; exiting as configured by exit_on_lock")
+            else:
+                break
+
     def doCommands(self):
         """Call the base command, and pass it the extended commands or
            arguments.
diff --git a/utils.py b/utils.py
index e465cf7..28fdd70 100755
--- a/utils.py
+++ b/utils.py
@@ -261,30 +261,6 @@ class YumUtilBase(YumBaseCli):
         """
         return self._option_group    
     
-    def waitForLock(self):
-        """Establish the yum lock.  If another process is already
-        holding the yum lock, by default this method will keep trying
-        to establish the lock until it is successful.  However, if
-        :attr:`self.conf.exit_on_lock` is set to True, it will
-        raise a :class:`Errors.YumBaseError`.
-        """
-        lockerr = ""
-        while True:
-            try:
-                self.doLock()
-            except Errors.LockError, e:
-                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...")  
-                    show_lock_owner(e.pid, self.logger)
-                    time.sleep(2)
-                else:
-                    raise Errors.YumBaseError, _("Another app is currently holding the yum lock; exiting as configured by exit_on_lock")
-            else:
-                break
-        
     def _printUtilVersion(self):
         print "%s - %s (yum - %s)" % (self._utilName,self._utilVer,yum.__version__)
         
diff --git a/yummain.py b/yummain.py
index a11f26e..a9f001b 100755
--- a/yummain.py
+++ b/yummain.py
@@ -32,7 +32,7 @@ from yum import _
 from yum.i18n import utf8_width, exception2msg
 import yum.misc
 import cli
-from utils import suppress_keyboard_interrupt_message, show_lock_owner
+from utils import suppress_keyboard_interrupt_message
 
 def main(args):
     """Run the yum program from a command line interface."""
@@ -120,27 +120,7 @@ def main(args):
     except (OSError, IOError), e:
         return exIOError(e)
 
-    lockerr = ""
-    while True:
-        try:
-            base.doLock()
-        except Errors.LockError, e:
-            if exception2msg(e) != lockerr:
-                lockerr = exception2msg(e)
-                logger.critical(lockerr)
-            if e.errno in (errno.EPERM, errno.EACCES, errno.ENOSPC):
-                logger.critical(_("Can't create lock file; exiting"))
-                return 1
-
-            if not base.conf.exit_on_lock:
-                logger.critical(_("Another app is currently holding the yum lock; waiting for it to exit..."))
-                show_lock_owner(e.pid, logger)
-                time.sleep(2)
-            else:
-                logger.critical(_("Another app is currently holding the yum lock; exiting as configured by exit_on_lock"))
-                return 1
-        else:
-            break
+    base.waitForLock()
 
     try:
         result, resultmsgs = base.doCommands()


More information about the Yum-commits mailing list