def do_alias(self, cmd_line): from utils import config_json_read, config_json_write from onos_api.onos_utils import return_sw_names if cmd_line: switch_names = return_sw_names(self.file_path) if cmd_line in switch_names: print"Duplicated name, please input another name!!!" else: try: switches = config_json_read(self.file_path) switches[self.sw_dpid] = cmd_line config_json_write(self.file_path, switches) self.prompt = "#switch("+cmd_line+"): " except Exception: traceback.print_exc() return None else: print "Please input switch alias"
def complete(self, text, state): """Return the next possible completion for 'text'. If a command has not been entered, then complete against command list. Otherwise try to call complete_<command> to get list of completions. """ if state == 0: import readline origline = readline.get_line_buffer() line = origline.lstrip() stripped = len(origline) - len(line) begidx = readline.get_begidx() - stripped endidx = readline.get_endidx() - stripped if begidx>0: cmd, args, foo = self.parseline(line) if cmd == '': compfunc = self.completedefault elif cmd == 'show': compfunc = getattr(self, 'complete_' + cmd) self.sub_command = self.show_second_command elif cmd == 'switch': compfunc = getattr(self, 'complete_' + cmd) from onos_api.onos_utils import return_sw_names self.sub_command = return_sw_names(self.file_path) else: try: compfunc = getattr(self, 'complete_' + cmd) except AttributeError: #traceback.print_exc() compfunc = self.completedefault else: compfunc = self.completenames self.completion_matches = compfunc(text, line, begidx, endidx) try: return self.completion_matches[state] except IndexError: return None