def completedefault(self, text, line, begidx, endidx): """ This shows the list in case , the auto complete is not able to complete the full command. """ completed_portion = line[:begidx] completed_tokens = vps_cli.cmd_tokenize(completed_portion, cmd_line_complete=False) output = command_ref.cmdCompletion(completed_tokens, text) if not output: output = [text] output.sort() return output
def completedefault(self, text, line, begidx, endidx): ''' This shows the list in case , the auto complete is not able to complete the full command. ''' completed_portion = line[:begidx] completed_tokens = vps_cli.cmd_tokenize(completed_portion, cmd_line_complete=False) output = command_ref.cmdCompletion(completed_tokens, text) if not output: output = [text] output.sort() return output
def default(self, command): """ All the processing goes in here. This is the central point of the intrepreter.py """ xml_output = lib.output.XMLoutput() try: # Tokenization of the command if not vps_cli.vps_tokenized: tokens = vps_cli.cmd_tokenize(command, cmd_line_complete=True) else: tokens = [] for arg in command: tokens.append(lib.escape.unescape(arg)) # configure terminal is handled here. currentmode = vps_cli.get_current_prompt() for token in tokens: if token == 'terminal': modifier, cmd, command_name, tokens = \ command_ref.cmdToMode(command, tokens) command_name = "configure terminal" return self.__invokeConfig(modifier, cmd, command_name, tokens) # vadapter <vadapter-name> type commands handled here. if len(tokens) == 2 and tokens[0] in command_ref.NON_SUB_CMD_MOD: modifier, cmd, command_name, tokens = \ command_ref.cmdToMode(command, tokens) return self.__invokeConfig(modifier, cmd, command_name, tokens) # vadapter [ So when length is 1 then is an error] if len(tokens) == 1 and tokens[0] in command_ref.NON_SUB_CMD_MOD: raise NameError( " \n '%s' Not a valid command. \n Please type : 'help %s' \n " % (tokens[0], tokens[0])) return # # So when len is 1 and the modifier is "show" [now] .Later add [edit] # in here. if len(tokens) == 1 and command == "show" \ and "config" in currentmode : modifier, cmd, command_name = command_ref.cmdToModifier( tokens, currentmode) token = currentmode.split("-") mode = token[1].split(")") if mode[0] in command_ref.NON_SUB_CMD_MOD and command == "show": tokens = [] tokens.insert(0, vps_current_module) elif tokens[0] == "edit" and "config" in currentmode: token = currentmode.split("-") mode = token[1].split(")") command_name = "commands." + mode[0] cmd = mode[0] modifier = tokens[0] index = tokens.index('edit') tokens.pop(index) tokens.insert(0, vps_current_module) else: # Get the command from the command_ref. All other command handled here. modifier, cmd, command_name = \ command_ref.cmdToPlugin(tokens, currentmode) if command_name == 'exit': return self.__invokeExit(modifier, cmd, command_name, tokens) elif command_name == 'set': return self.__invokeSet(modifier, cmd, command_name, tokens) elif command_name == 'enable': return self.__invokeLoginExec() elif command_name == 'end': return self.__invokeDisable() # Invoke the actual command #print "modifier", modifier #print "cmd" , cmd #print "command_name", command_name #print "tokens", tokens xml_output = self.__invokeExecuteCommand(modifier, cmd, command_name, tokens) except (lib.errorhandler.StringUnspecial_characterException, command_ref.UnknownPluginException, lib.errorhandler.ModifierDoesntExistException, NameError), ex: xml_output.completeOutputError(ex)
def default(self, command): """ All the processing goes in here. This is the central point of the intrepreter.py """ xml_output = lib.output.XMLoutput() try: # Tokenization of the command if not vps_cli.vps_tokenized: tokens = vps_cli.cmd_tokenize(command, cmd_line_complete=True) else: tokens = [] for arg in command: tokens.append(lib.escape.unescape(arg)) # configure terminal is handled here. currentmode = vps_cli.get_current_prompt() for token in tokens: if token == "terminal": modifier, cmd, command_name, tokens = command_ref.cmdToMode(command, tokens) command_name = "configure terminal" return self.__invokeConfig(modifier, cmd, command_name, tokens) # vadapter <vadapter-name> type commands handled here. if len(tokens) == 2 and tokens[0] in command_ref.NON_SUB_CMD_MOD: modifier, cmd, command_name, tokens = command_ref.cmdToMode(command, tokens) return self.__invokeConfig(modifier, cmd, command_name, tokens) # vadapter [ So when length is 1 then is an error] if len(tokens) == 1 and tokens[0] in command_ref.NON_SUB_CMD_MOD: raise NameError(" \n '%s' Not a valid command. \n Please type : 'help %s' \n " % (tokens[0], tokens[0])) return # # So when len is 1 and the modifier is "show" [now] .Later add [edit] # in here. if len(tokens) == 1 and command == "show" and "config" in currentmode: modifier, cmd, command_name = command_ref.cmdToModifier(tokens, currentmode) token = currentmode.split("-") mode = token[1].split(")") if mode[0] in command_ref.NON_SUB_CMD_MOD and command == "show": tokens = [] tokens.insert(0, vps_current_module) elif tokens[0] == "edit" and "config" in currentmode: token = currentmode.split("-") mode = token[1].split(")") command_name = "commands." + mode[0] cmd = mode[0] modifier = tokens[0] index = tokens.index("edit") tokens.pop(index) tokens.insert(0, vps_current_module) else: # Get the command from the command_ref. All other command handled here. modifier, cmd, command_name = command_ref.cmdToPlugin(tokens, currentmode) if command_name == "exit": return self.__invokeExit(modifier, cmd, command_name, tokens) elif command_name == "set": return self.__invokeSet(modifier, cmd, command_name, tokens) elif command_name == "enable": return self.__invokeLoginExec() elif command_name == "end": return self.__invokeDisable() # Invoke the actual command # print "modifier", modifier # print "cmd" , cmd # print "command_name", command_name # print "tokens", tokens xml_output = self.__invokeExecuteCommand(modifier, cmd, command_name, tokens) except ( lib.errorhandler.StringUnspecial_characterException, command_ref.UnknownPluginException, lib.errorhandler.ModifierDoesntExistException, NameError, ), ex: xml_output.completeOutputError(ex)