def __init__(self, exit_on_ctrl_c): ''' Initializes ''' self.session = login_context() self.exit_on_ctrl_c = exit_on_ctrl_c self.terminal = MyTerminal(exit_on_ctrl_c)
class cli_class_main: ''' Represents a DPS SERVER CLI Class ''' def __init__(self, exit_on_ctrl_c): ''' Initializes ''' self.session = login_context() self.exit_on_ctrl_c = exit_on_ctrl_c self.terminal = MyTerminal(exit_on_ctrl_c) def execute_user_input(self, cli_contexts, current_context, user_command): ''' Executes command entered by the user @param cli_contexts: The stack of cli_contexts @param cli_contexts: List @param current_context: The Current CLI Context @type current_context: Python Class @param user_command: The entire user command @param user_command: String @rtype: The new CLI context if any, otherwise the same context ''' return_context = current_context while 1: user_commands = user_command.split() if user_commands[0] == '': #print '%s\r'%cli_base.user_help_output break command_id = user_commands[0].lower() #Don't allow EXIT OR HELP from login CLI if current_context != cli_login: if current_context.input_char_show: current_context.command_history.add_string(user_command) if command_id in current_context.help_strings: current_context.help(self.session.god_mode) break elif command_id in cli_base.cli_generic_exit.exit_strings: #Exiting current context try: current_context.cli_exit(self.session) finally: try: return_context = cli_contexts.pop() except Exception: self.terminal.release() print 'ALERT!!! CLI Error: PLEASE REPORT TO DOVE-DEV Exiting...\r' os._exit(1) break #Parse the Command cli_context, cli_object = current_context.parse(self.session.god_mode, self.terminal, user_command) if ((cli_context is not None) and (cli_context != current_context)): #CLI context changed cli_contexts.append(current_context) return_context = cli_context break if cli_context == current_context: #Nothing to execute break if type(cli_object) != cli_login and type(cli_object) == current_context: #Other than the Login Context - If the type of the cli_object is #the same as the current context it means there is nothing to execute cli_object = None if not cli_object: print "Invalid Command! Please try again...\r" break #self.terminal.release() try: new_context = cli_object.execute(self.session) if new_context is not None: cli_contexts.append(current_context) return_context = new_context except Exception, ex: print 'ERROR EXECUTE: %s\r'%ex #self.terminal.acquire() break return return_context