def parseline(self, line): if line == 'exit' or line == 'quit': ret = Cmd.parseline(self, line) return ret if self.mode == 'variable': data = self.var_dict[self.variable] data = data + line self.var_dict[self.variable] = data #self.prompt = self.variable+'_'+str(self.line_count)+'>' ret = Cmd.parseline(self, 'variable') return ret else: ret = Cmd.parseline(self, line) return ret
def default(self, line): print >>sys.stderr, 'Unknown command: "%s"' % line cmd, arg, ignore = Cmd.parseline(self, line) if cmd is not None: names = set(name[3:] for name in self.get_names() if name.startswith('do_' + cmd)) if len(names) > 0: print >>sys.stderr, 'Do you mean: %s?' % ', '.join(names) return 2
def parseline(self, line): """Patch to handle backslash cmd and EOF""" if not self.is_query: return Cmd.parseline(self, line) if line == 'EOF': print "^D" return ('quit', None, line) return (None, None, line)
def default(self, line): print('Unknown command: "%s"' % line, file=self.stderr) cmd, arg, ignore = Cmd.parseline(self, line) if cmd is not None: names = set(name[3:] for name in self.get_names() if name.startswith('do_' + cmd)) if len(names) > 0: print('Do you mean: %s?' % ', '.join(names), file=self.stderr) return 2
def parseline(self, line): """ Parses a line to command and arguments. For our uses we copy name of the command to arguments so that the man command knows what subcommands to run. """ cmd, arg, line = Cmd.parseline(self, line) if (cmd in self.admin_cli.get_command_names()) and (arg != None): arg = cmd + " " + arg return cmd, arg, line
def parseline(self, line): '''Record the command that was executed. This also allows us to transform dashes back to underscores. ''' (command, arg, line) = Cmd.parseline(self, line) self.command = command if command: command = command.replace('-', '_') return command, arg, line
def parseline(self, line): """ Parses a line to command and arguments. For our uses we copy name of the command to arguments so that the main command knows what subcommands to run. """ cmd, arg, line = Cmd.parseline(self, line) commands_and_sections = self.cli.root_section.commands.keys() + self.cli.root_section.subsections.keys() if (cmd in commands_and_sections) and (arg != None): arg = cmd + " " + arg return cmd, arg, line
def parseline(self, line): # keep this stateless command, arg, line = Cmd.parseline(self, line) if arg is not None: arg = arg.split() # we do this bc self.complete() is stateful commands = [c for c in sorted(self.completenames(''), key=len) if command and c.startswith(command)] if commands: command = commands[0] return command, arg, line
def parseline(self, line): # expand @target cmd to atssh target cmd if line and line[0] == '@': tokens = line.split() if len(tokens[0]) == 1: line = 'atssh * ' + line[1:] else: target = tokens[0][1:] line = 'atssh %s %s ' % (target, line[len(tokens[0]):]) ret = Cmd.parseline(self, line) return ret
def parseline(self, line): # expand @target cmd to atssh target cmd if line and line[0] == '@': tokens = line.split() if len(tokens[0]) == 1: line = 'atssh * ' + line[1:] else: target = tokens[0][1:] line = 'atssh %s %s ' % (target, line[len(tokens[0]):] ) ret = Cmd.parseline(self, line) return ret
def parseline(self, line): cmd, arg, line = Cmd.parseline(self, line) if cmd and cmd.strip() != '': dof = getattr(self, 'do_' + cmd, None) argf = getattr(self, 'args_' + cmd, None) else: argf = None if argf: parser = argparse.ArgumentParser( prog=cmd, description=getattr(dof, '__doc__', None)) argf(parser) try: arg = parser.parse_args(shlex.split(arg)) except SystemExit, e: return '', '', ''
def parseline(self, line): """ This REPL method is overrided to search "short" alias of commands """ cmd, arg, ignored = Cmd.parseline(self, line) if cmd is not None: names = set(name for name in self.get_names() if name.startswith('do_')) if 'do_' + cmd not in names: long = set(name for name in names if name.startswith('do_' + cmd)) # if more than one result, ambiguous command, do nothing (error will display suggestions) if len(long) == 1: cmd = long.pop()[3:] return cmd, arg, ignored
def onecmd(self, line): if line is None: return orig_line = line cmd, args, line = self.parseline(line) if cmd == 'exit' and not orig_line.strip() == 'exit': print('type "exit" to quit the console') return if os.getenv('OBJEX_DEBUG', '') and cmd not in self.completenames(''): command, arg, line = Cmd.parseline(self, line) if command is None: # empty line comes through as None not '' reader_func = None else: reader_func = getattr(self.reader, command, None) if reader_func: args = [] mark = 0 chunks = arg.split() for i in range(len(chunks) + 1): attempt = " ".join(chunks[mark:i]).strip() try: # ast.literal_eval takes 4 microseconds; no perf issue args.append(ast.literal_eval(attempt)) mark = i except SyntaxError: pass if mark < len(chunks): print("ERROR unparsed input: ", " ".join(chunks[mark:])) else: try: res = reader_func(*args) pprint.pprint(res) except Exception: import traceback; traceback.print_exc() print("args:", args) print() return if line and line != 'EOF' and cmd and self.completenames(cmd): self.cmd_history.append({'line': line, 'cmd': cmd, 'args': args, 'options': []}) try: return Cmd.onecmd(self, line) except Exception: # TODO: better exception handling can go here, maybe pdb with OBJEX_DEBUG=True self.cmd_history.pop() raise
def parseline(self, line): """ This REPL method is overridden to search "short" alias of commands """ cmd, arg, ignored = Cmd.parseline(self, line) if cmd is not None: names = set(name for name in self.get_names() if name.startswith('do_')) if 'do_' + cmd not in names: long = set(name for name in names if name.startswith('do_' + cmd)) # if more than one result, ambiguous command, do nothing (error will display suggestions) if len(long) == 1: cmd = long.pop()[3:] return cmd, arg, ignored
def parseline(self, line): """Parse the line into a command name and a string containing the arguments. Returns a tuple containing (command, args, line). 'command' and 'args' may be None if the line couldn't be parsed. """ line = line.strip() if not line: ret = (None, None, line) #return None, None, line else: # If the line starts with "!" execute as a system cmd if line.startswith('!'): line = 'sh {0}'.format(line.lstrip("!")) # If the line starts with a "?" execute as a help cmd elif '?' in line: if line[0] == '?': if len(line) == 1: return 'menu_summary', '', line elif len(line.split()) == 1: line = 'help ' + str(line).replace('?', '') ret = Cmd.parseline(self, line) return ret
def parseline(self, line): """Parse the line into a command name and a string containing the arguments. Returns a tuple containing (command, args, line). 'command' and 'args' may be None if the line couldn't be parsed. """ line = line.strip() if not line: ret = (None, None, line) #return None, None, line else: # If the line starts with "!" execute as a system cmd if line.startswith('!'): line = 'sh {0}'.format(line.lstrip("!")) # If the line starts with a "?" execute as a help cmd elif '?' in line: if line[0] == '?': if len(line) == 1: return 'menu_summary', '', line elif len(line.split()) == 1: line = 'help ' + str(line).replace('?','') ret = Cmd.parseline(self, line) return ret
def parseline(self, line): if '|' in line: return 'pipe', line.split('|'), line return Cmd.parseline(self, line)
def parseline(self, line): cmd, arg, line = Cmd.parseline(self, line) if cmd: cmd = self.shortCommandName(cmd) line = cmd + " " + arg return cmd, arg, line
def parseline(self, line): """Hook to transform '..' in 'back'""" # Hack for '..' to be considered as 'back'. if line.strip().startswith('..'): return ('back', '', 'back') return Cmd.parseline(self, line)
def parseline(self, line): """Hook to transform '..' in 'back'""" # Hack for '..' to be considered as 'back'. if line.strip().startswith(".."): return ("back", "", "back") return Cmd.parseline(self, line)
def parseline(self, line): cmd, arg, line = Cmd.parseline(self, line) if (cmd in self.admin_cli.command_names()) and (arg != None): arg = cmd + " " + arg return cmd, arg, line
def parseline(self, line): """ This function sets the line attribute with the complete command, which is used at the preprocessing stage""" self.line = line return Cmd.parseline(self, line)