]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
override the safe default for cli.main()
authorAlfredo Deza <alfredo.deza@inktank.com>
Mon, 18 Aug 2014 20:32:08 +0000 (16:32 -0400)
committerAlfredo Deza <alfredo.deza@inktank.com>
Mon, 18 Aug 2014 20:32:08 +0000 (16:32 -0400)
Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
ceph_deploy/cli.py
ceph_deploy/util/decorators.py

index 7a9be03a51ced37283cf30f60bbd5da2df19d882..a6dfead8df42b95e2b204278ddf73aa0dadeb29c 100644 (file)
@@ -98,7 +98,7 @@ def get_parser():
     return parser
 
 
-@catches((KeyboardInterrupt, RuntimeError, exc.DeployError,))
+@catches((KeyboardInterrupt, RuntimeError, exc.DeployError,), handle_all=True)
 def main(args=None, namespace=None):
     parser = get_parser()
 
index 567d6060f6b8fd4704f41a50ec1578190a2b46fc..4c72bdc7bd1dede2417ece7fd0632c9f178f688b 100644 (file)
@@ -5,7 +5,7 @@ import traceback
 from functools import wraps
 
 
-def catches(catch=None, handler=None, exit=True):
+def catches(catch=None, handler=None, exit=True, handle_all=False):
     """
     Very simple decorator that tries any of the exception(s) passed in as
     a single exception class or tuple (containing multiple ones) returning the
@@ -52,6 +52,11 @@ def catches(catch=None, handler=None, exit=True):
     execution, otherwise the decorator would continue as a normal try/except
     block.
 
+
+    :param catch: A tuple with one (or more) Exceptions to catch
+    :param handler: Optional handler to have custom handling of exceptions
+    :param exit: Raise a ``SystemExit`` after handling exceptions
+    :param handle_all: Handle all other exceptions via logging.
     """
     catch = catch or Exception
     logger = logging.getLogger('ceph_deploy')
@@ -72,6 +77,8 @@ def catches(catch=None, handler=None, exit=True):
                         exit_from_catch = True
                         sys.exit(1)
             except Exception as err:  # anything else
+                if handle_all is False:  # re-raise if we are not supposed to handle everything
+                    raise
                 # Make sure we don't spit double tracebacks if we are raising
                 # SystemExit from the `except catch` block
                 if exit_from_catch:
@@ -84,21 +91,6 @@ def catches(catch=None, handler=None, exit=True):
                 else:  # if for whatever reason we can't get an err message
                     logger.error(make_exception_message(err))
 
-            finally:
-                # This block is crucial to avoid having issues with
-                # Python spitting non-sense thread exceptions. We have already
-                # handled what we could, so close stderr and stdout.
-                if not os.environ.get('CEPH_DEPLOY_TEST'):
-                    import sys
-                    try:
-                        sys.stdout.close()
-                    except:
-                        pass
-                    try:
-                        sys.stderr.close()
-                    except:
-                        pass
-
         return newfunc
 
     return decorate