Esempio n. 1
0
 def __init__(self, completekey='tab', stdin=None, stdout=None):
     cmd.Cmd.__init__(self, completekey, stdin, stdout)
     for funcname, func in blotish.__dict__.iteritems():
         if funcname[0] == '_' or not inspect.isfunction(func): continue
         if not func.__doc__ or not len(func.__doc__):
             raise blotish.BlotishError("Method %s is undocumented." % funcname)
         self._blotish_commands[funcname] = func
     # Insert dummy commands for help.
     self._blotish_commands['exit'] = _PVBlotInterp.do_exit
     self._error_flag = False
Esempio n. 2
0
 def get_unique_command(self, command_name):
     """Given a command name, returns the function that implements it.
     The command name should be in all lower case.  The command name
     need only cover the first part of the command uniquely.  If no
     command is found, or more than one command is found, raises a
     BlotishError."""
     valid_commands = []
     for existing_command in self._blotish_commands.keys():
         if existing_command.startswith(command_name):
             valid_commands.append(existing_command)
     if not valid_commands:
         # If no command was found, maybe the command name is a variable name
         func = blotish._find_variable_command(command_name)
         if func is not None:
             return func
         else:
             raise blotish.BlotishError("No such command '%s'" % command_name)
     if len(valid_commands) > 1:
         raise blotish.BlotishError(
               "Command not found.  Possible commands: %s" % str(", ").join(valid_commands))
     return self._blotish_commands[valid_commands[0]]