commit:     a7dd0129e0f01026e29583805e0b0c1232a8e747
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Wed Sep  9 15:16:15 2015 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Wed Sep  9 15:16:36 2015 +0000
URL:        https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=a7dd0129

Fix LockInUse return code failure

Move trapping of the lock failure from the top most build call to the run() 
where
it can do cleanup work before exiting.

 catalyst/base/stagebase.py | 18 +++++++++++++++---
 catalyst/main.py           | 11 +++++------
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py
index 5eb8fc9..60acd55 100644
--- a/catalyst/base/stagebase.py
+++ b/catalyst/base/stagebase.py
@@ -20,7 +20,7 @@ from catalyst.support import (CatalystError, msg, 
file_locate, normpath,
 from catalyst.base.targetbase import TargetBase
 from catalyst.base.clearbase import ClearBase
 from catalyst.base.genbase import GenBase
-from catalyst.lock import LockDir
+from catalyst.lock import LockDir, LockInUse
 from catalyst.fileops import ensure_dirs, pjoin
 from catalyst.base.resume import AutoResume
 
@@ -1419,18 +1419,30 @@ class StageBase(TargetBase, ClearBase, GenBase):
                        print "StageBase: run() purge"
                        self.purge()
 
+               failure = False
                for x in self.settings["action_sequence"]:
                        print "--- Running action sequence: "+x
                        sys.stdout.flush()
                        try:
                                apply(getattr(self,x))
+                       except LockInUse:
+                               print "Error, unable to aquire the lock..."
+                               print " Catalyst aborting...."
+                               failure = True
+                               break
                        except Exception as error:
                                print "Exception running action sequence %s" % x
                                print "Error:", str(error)
-                               print "Running unbind()"
-                               self.unbind()
+                               print " Catalyst aborting...."
+                               failure = True
                                break
 
+               if failure:
+                       print "Cleaning up... Running unbind()"
+                       self.unbind()
+                       return False
+               return True
+
 
        def unmerge(self):
                if "autoresume" in self.settings["options"] \

diff --git a/catalyst/main.py b/catalyst/main.py
index 2a5bdd3..dfa0609 100644
--- a/catalyst/main.py
+++ b/catalyst/main.py
@@ -21,7 +21,6 @@ import catalyst.config
 import catalyst.util
 from catalyst.defaults import confdefaults, option_messages
 from catalyst.hash_utils import HashMap, HASH_DEFINITIONS
-from catalyst.lock import LockInUse
 from catalyst.support import CatalystError, find_binary
 from catalyst.version import get_version
 
@@ -164,8 +163,8 @@ def build_target(addlargs):
                        "Target \"%s\" not available." % target,
                        print_traceback=True)
        except CatalystError:
-               return
-       target.run()
+               return False
+       return target.run()
 
 
 def main():
@@ -345,12 +344,12 @@ def main():
 
        # everything is setup, so the build is a go
        try:
-               build_target(addlargs)
+               success = build_target(addlargs)
        except KeyboardInterrupt:
                print "\nCatalyst build aborted due to user interrupt ( Ctrl-C 
)"
                print
                print "Catalyst aborting...."
                sys.exit(2)
-       except LockInUse:
-               print "Catalyst aborting...."
+       if not success:
                sys.exit(2)
+       sys.exit(0)

Reply via email to