#NEWLINE# def main( ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# cl_arg_namespace = utilities . get_cl_args ( ) #NEWLINE# log_handler = utilities . create_logging_handler ( cl_arg_namespace . verbose , config . settings [ 'logging directory' ] ) #NEWLINE# if cl_arg_namespace . debug : #NEWLINE# #INDENT# engine = engineio . DebugEngine ( cl_arg_namespace . debug_delay ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# engine = config . settings [ 'engine' ] #NEWLINE# #UNINDENT# gram_handler = grammarhandler . GrammarHandler ( ) #NEWLINE# print ( 'Loading grammars...' ) #NEWLINE# gram_handler . load_grammars ( ) #NEWLINE# utilities . log_message ( log_handler , 'info' , 'Started listening for input' ) #NEWLINE# command_history = history . CommandHistory ( ) #NEWLINE# print ( 'Ready!' ) #NEWLINE# while True : #NEWLINE# #INDENT# for line in engine . get_lines ( ) : #NEWLINE# #INDENT# utilities . log_message ( e , 'info' , 'Received input "{}"' . format ( line ) ) #NEWLINE# current_command = commands . Command ( line . split ( ' ' ) ) #NEWLINE# try : #NEWLINE# #INDENT# current_command . set_results ( gram_handler , log_handler ) #NEWLINE# command_history . run_command ( current_command ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# if cl_arg_namespace . permissive_mode : #NEWLINE# #INDENT# utilities . log_message ( log_handler , 'exception' , e ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise e #NEWLINE# #UNINDENT# #UNINDENT# platformhandler . flush_io_buffer ( ) #NEWLINE# #UNINDENT# time . sleep ( constants . MAIN_LOOP_DELAY ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# utilities . log_message ( log_handler , 'exception' , e ) #NEWLINE# raise e #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# engine . cleanup ( ) #NEWLINE# utilities . log_message ( log_handler , 'info' , 'Stopped listening for input' )