<s> import sys <EOL> import traceback <EOL> from imapfw import runtime <EOL> from imapfw . conf import ImapfwConfig , Parser <EOL> from imapfw . toolkit import runHook <EOL> class Imapfw ( object ) : <EOL> def run ( self ) : <EOL> config = ImapfwConfig ( ) <EOL> try : <EOL> config . parseCLI ( ) <EOL> config . setupConcurrency ( ) <EOL> config . setupUI ( ) <EOL> except Exception as e : <EOL> traceback . print_exc ( file = sys . stderr ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> try : <EOL> config . loadRascal ( ) <EOL> except FileNotFoundError as e : <EOL> runtime . ui . critical ( e ) <EOL> except Exception : <EOL> raise <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> rascal = runtime . rascal <EOL> if rascal is not None : <EOL> rascalConfigure = rascal . getFunction ( '<STR_LIT>' ) <EOL> rascalConfigure ( runtime . ui ) <EOL> try : <EOL> actionName , cls_action = config . getAction ( ) <EOL> except KeyError as e : <EOL> runtime . ui . critical ( "<STR_LIT>" % e ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> action = cls_action ( ) <EOL> if action . requireRascal is True and rascal is None : <EOL> runtime . ui . critical ( <EOL> "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> try : <EOL> if action . honorHooks is True : <EOL> timedout = runHook ( rascal . getPreHook ( ) , actionName , Parser ) <EOL> if timedout : <EOL> runtime . ui . critical ( "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:4> ) <EOL> action . init ( Parser ) <EOL> action . run ( ) <EOL> if action . honorHooks is True : <EOL> timedout = runHook ( rascal . getPostHook ( ) ) <EOL> if timedout : <EOL> runtime . ui . error ( '<STR_LIT>' ) <EOL> except Exception as e : <EOL> def outputException ( error , message ) : <EOL> runtime . ui . critical ( message ) <EOL> import traceback , sys <EOL> runtime . ui . exception ( error ) <EOL> traceback . print_exc ( file = sys . stdout ) <EOL> try : <EOL> if action . honorHooks is True : <EOL> timedout = runHook ( rascal . getExceptionHook ( ) , e ) <EOL> if timedout : <EOL> runtime . ui . error ( '<STR_LIT>' ) <EOL> except Exception as hookError : <EOL> outputException ( hookError , "<STR_LIT>" <EOL> "<STR_LIT>" % str ( hookError ) ) <EOL> try : <EOL> action . exception ( e ) <EOL> except Exception as actionError : <EOL> outputException ( actionError , "<STR_LIT>" <EOL> "<STR_LIT>" % str ( actionError ) ) <EOL> raise <EOL> sys . exit ( action . getExitCode ( ) ) </s>
