def main_wrapper(module, args):
    """This wraps the main method of an action so that:
    * when an exception is raised that derived from ``qisys.error.Error``,
        simply dispaly the error message and exit
    * when sys.exit() or ui.fatal() is called, just exit
    * also handle KeyboardInterrupt
    * Other cases imply there's a bug in qiBuild, so either:
        * Generate a full backtrace or using cgitb
        * Start a debugging session if ``--pdb`` was used
    """
    try:
        module.do(args)
    except qisys.error.Error as e:
        # Normal exception raised from qibuild, display a message
        # and exit
        message = message_from_exception(e)
        ui.error(message)
        sys.exit(2)
    except SystemExit as e:
        # sys.exit() or ui.fatal() has been called, assume
        # message has already been displayed and exit
        sys.exit(e.code)
    except __HOLE__:
        ui.info("Interrupted by user, quitting")
        sys.exit(2)
    except Exception as e:
        tb = sys.exc_info()[2]
        # Oh, oh we have an crash:
        if args.pdb:
            print ""
            print "### Exception:", e
            print "### Starting a debugger"
            try:
                #pylint: disable-msg=F0401
                import ipdb
                ipdb.post_mortem(tb)
                sys.exit(0)
            except ImportError:
                import pdb
                pdb.post_mortem(tb)
                sys.exit(0)
        # Raise, this will be caught by cgitb that was enabled in qisys.main
        raise
dataset/ETHPy150Open aldebaran/qibuild/python/qisys/script.py/main_wrapper