def test_runPreHookEmpty(self): from imapfw.toolkit import runHook stop = runHook(self.rascal.getPreHook(), 'actionName', {'action': 'actionName'}) self.assertFalse(stop)
def run(self): config = ImapfwConfig() try: config.parseCLI() # Parse CLI options. config.setupConcurrency() # Exports concurrency to runtime module. config.setupUI() # Exports ui to the runtime module. ui = config.getUI() except Exception as e: traceback.print_exc(file=sys.stderr) sys.exit(1) if config.listActions(): ui.info("Available actions:") for action in sorted(list(Actions.keys())): ui.info("- %s: %s"% (action, Action(action).__doc__)) sys.exit(0) try: config.loadRascal() # Exports the rascal to the runtime module. except FileNotFoundError as e: ui.critical(e) except Exception: raise sys.exit(2) rascal = config.getRascal() # The rascal must use the thread-safe ui, too! if rascal is not None: rascalConfigure = rascal.getFunction('configure') rascalConfigure(ui) # "Action", you said? Do you really want action? # Fine... actionName = config.getAction() actionOptions = config.getActionOptions() action = Action(actionName) if action.requireRascal is True and rascal is None: ui.critical("a rascal is required but is not defined, use '-r'.") sys.exit(2) try: if action.honorHooks is True: timedout = runHook(rascal.getPreHook(), actionName, actionOptions) if timedout: sys.exit(4) action.init(actionOptions) action.run() if action.honorHooks is True: timedout = runHook(rascal.getPostHook()) if timedout: ui.error('postHook reached timed out') except Exception as e: def outputException(error, message): ui.critical(message) import traceback, sys ui.exception(error) traceback.print_exc(file=sys.stdout) # Rascal's exceptionHook. try: if action.honorHooks is True: timedout = runHook(rascal.getExceptionHook(), e) if timedout: ui.error('postHook reached timed out') except Exception as hookError: outputException(hookError, "exception occured while running" " exceptionHook: %s"% str(hookError)) # Let the Action instance know the exception. try: action.exception(e) except Exception as actionError: outputException(actionError, "exception occured while running" " internal 'action.exception()': %s"% str(actionError)) raise #TODO: raise only unkown errors. sys.exit(action.getExitCode())
def run(self): config = ImapfwConfig() try: config.parseCLI() # Parse CLI options. config.setupConcurrency() # Exports concurrency to runtime module. config.setupUI() # Exports ui to the runtime module. except Exception as e: traceback.print_exc(file=sys.stderr) sys.exit(1) try: config.loadRascal() # Exports the rascal to the runtime module. except FileNotFoundError as e: runtime.ui.critical(e) except Exception: raise #FIXME sys.exit(2) rascal = runtime.rascal # The rascal must use the thread-safe ui, too! if rascal is not None: rascalConfigure = rascal.getFunction('configure') rascalConfigure(runtime.ui) # "Action", you said? Do you really want action? # Fine... try: actionName, cls_action = config.getAction() except KeyError as e: runtime.ui.critical("unkown action: %s" % e) sys.exit(1) action = cls_action() if action.requireRascal is True and rascal is None: runtime.ui.critical( "a rascal is required but is not defined, use '-r'.") sys.exit(2) try: # PreHook. if action.honorHooks is True: timedout = runHook(rascal.getPreHook(), actionName, Parser) if timedout: runtime.ui.critical("preHook reached timeout") sys.exit(4) # Doing the job. action.init(Parser) action.run() # PostHook. if action.honorHooks is True: timedout = runHook(rascal.getPostHook()) if timedout: runtime.ui.error('postHook reached timed out') except Exception as e: def outputException(error, message): runtime.ui.critical(message) import traceback, sys runtime.ui.exception(error) traceback.print_exc(file=sys.stdout) # ExceptionHook. try: if action.honorHooks is True: timedout = runHook(rascal.getExceptionHook(), e) if timedout: runtime.ui.error('exceptionHook reached timeout') except Exception as hookError: outputException( hookError, "exception occured while running" " exceptionHook: %s" % str(hookError)) # Let the Action instance know the exception. try: # This way, exceptions can be handled in a per-action basis. action.exception(e) except Exception as actionError: outputException( actionError, "exception occured while running" " internal 'action.exception()': %s" % str(actionError)) raise #TODO: raise only unkown errors. sys.exit(action.getExitCode())
def run(self): config = ImapfwConfig() try: config.parseCLI() # Parse CLI options. config.setupConcurrency() # Exports concurrency to runtime module. config.setupUI() # Exports ui to the runtime module. except Exception as e: traceback.print_exc(file=sys.stderr) sys.exit(1) try: config.loadRascal() # Exports the rascal to the runtime module. except FileNotFoundError as e: runtime.ui.critical(e) except Exception: raise #FIXME sys.exit(2) rascal = runtime.rascal # The rascal must use the thread-safe ui, too! if rascal is not None: rascalConfigure = rascal.getFunction('configure') rascalConfigure(runtime.ui) # "Action", you said? Do you really want action? # Fine... try: actionName, cls_action = config.getAction() except KeyError as e: runtime.ui.critical("unkown action: %s"% e) sys.exit(1) action = cls_action() if action.requireRascal is True and rascal is None: runtime.ui.critical( "a rascal is required but is not defined, use '-r'.") sys.exit(2) try: # PreHook. if action.honorHooks is True: timedout = runHook(rascal.getPreHook(), actionName, Parser) if timedout: runtime.ui.critical("preHook reached timeout") sys.exit(4) # Doing the job. action.init(Parser) action.run() # PostHook. if action.honorHooks is True: timedout = runHook(rascal.getPostHook()) if timedout: runtime.ui.error('postHook reached timed out') except Exception as e: def outputException(error, message): runtime.ui.critical(message) import traceback, sys runtime.ui.exception(error) traceback.print_exc(file=sys.stdout) # ExceptionHook. try: if action.honorHooks is True: timedout = runHook(rascal.getExceptionHook(), e) if timedout: runtime.ui.error('exceptionHook reached timeout') except Exception as hookError: outputException(hookError, "exception occured while running" " exceptionHook: %s"% str(hookError)) # Let the Action instance know the exception. try: # This way, exceptions can be handled in a per-action basis. action.exception(e) except Exception as actionError: outputException(actionError, "exception occured while running" " internal 'action.exception()': %s"% str(actionError)) raise #TODO: raise only unkown errors. sys.exit(action.getExitCode())
def run(self): config = ImapfwConfig() try: config.parseCLI() # Parse CLI options. config.setupConcurrency() # Exports concurrency to runtime module. config.setupUI() # Exports ui to the runtime module. ui = config.getUI() except Exception as e: traceback.print_exc(file=sys.stderr) sys.exit(1) if config.listActions(): ui.info("Available actions:") for action in sorted(list(Actions.keys())): ui.info("- %s: %s" % (action, Action(action).__doc__)) sys.exit(0) try: config.loadRascal() # Exports the rascal to the runtime module. except FileNotFoundError as e: ui.critical(e) except Exception: raise sys.exit(2) rascal = config.getRascal() # The rascal must use the thread-safe ui, too! if rascal is not None: rascalConfigure = rascal.getFunction('configure') rascalConfigure(ui) # "Action", you said? Do you really want action? # Fine... actionName = config.getAction() actionOptions = config.getActionOptions() action = Action(actionName) if action.requireRascal is True and rascal is None: ui.critical("a rascal is required but is not defined, use '-r'.") sys.exit(2) try: if action.honorHooks is True: timedout = runHook(rascal.getPreHook(), actionName, actionOptions) if timedout: sys.exit(4) action.init(actionOptions) action.run() if action.honorHooks is True: timedout = runHook(rascal.getPostHook()) if timedout: ui.error('postHook reached timed out') except Exception as e: def outputException(error, message): ui.critical(message) import traceback, sys ui.exception(error) traceback.print_exc(file=sys.stdout) # Rascal's exceptionHook. try: if action.honorHooks is True: timedout = runHook(rascal.getExceptionHook(), e) if timedout: ui.error('postHook reached timed out') except Exception as hookError: outputException( hookError, "exception occured while running" " exceptionHook: %s" % str(hookError)) # Let the Action instance know the exception. try: action.exception(e) except Exception as actionError: outputException( actionError, "exception occured while running" " internal 'action.exception()': %s" % str(actionError)) raise #TODO: raise only unkown errors. sys.exit(action.getExitCode())