def shell( self ): """ Launch an interactive shell. """ import completer from doc import doc self.shell_mode = True # everything that does not start with '_': cmds = [ x for x in dir( self ) if not x.startswith( '_' ) and x != "shell" ] # only functions: cmds = [ x.replace('_', '-') for x in cmds if type(getattr( self, x )) == type(self.shell) ] # add shell_cmds from doc: cmds += [ x.name for x in doc.shell_cmds ] jids = [ x.get_jid() for x in self.instances ] compl = completer.completer(cmds, jids) while( True ): try: words = raw_input( self._get_prompt() ).split() words = [ x.strip() for x in words ] if len( words ) == 0: continue cmd = words[0] if cmd == "exit": raise EOFError() # same as CTRL+D elif cmd == "load": try: if words[1] == "all": ret = self._load_instances() else: ret = self._load_instances( words[1] ) if ret == 0: print( "Error: no transports found." ) elif ret == 1: print( "%s loaded."%(self.instances[0].get_jid() ) ) else: print( "%s transports loaded."%(ret) ) compl.set_jids( [ x.get_jid() for x in self.instances ] ) except IndexError: print( "Error: Give a JID to load or 'all' to load all (enabled) files" ) elif cmd in cmds: getattr( self, cmd.replace('-','_') )( *words[1:] ) else: print( "Unknown command, try 'help'." ) print( cmd ) except TypeError, e: print( "Wrong number of arguments, try 'help <cmd>' for help." ) except KeyboardInterrupt: print continue
def run(self): #preload libraries self.core.coreModules.preloadModules() self.core.coreMain.outputHeader() readline.parse_and_bind("tab: complete") # Define escape commands exitCommands = ['quit', 'exit', 'stop'] # Register our completer function self.genList() readline.set_completer(completer.completer(self.autocomp).complete) # Use the tab key for completion # Initialize Input Container line = "" # Receive user input while line not in exitCommands: # Set the prompt if self.module != None: self.prompt = self.cstring('(', 'red')+self.cstring("unoRover", 'cyan', None, 'bright')+self.cstring("->", "red") + self.cstring(self.module.name, "white")+self.cstring(')', 'red') else: self.prompt = self.cstring('(', 'red')+self.cstring("unoRover", 'cyan', None, 'bright')+self.cstring(')', 'red') # Read user input sys.stdout.write(self.prompt) sys.stdout.write(' ') line = raw_input() # Parse user input if line == "" or line in exitCommands: continue self.parseInput(line)
def run(self): #preload libraries self.core.coreModules.preloadModules() self.core.coreMain.outputHeader() # Define escape commands exitCommands = ['quit', 'exit', 'stop'] # Register our completer function self.genList() readline.set_completer(completer.completer(self.autocomp).complete) # Use the tab key for completion readline.parse_and_bind('tab: complete') # Initialize Input Container line = "" # Receive user input while line not in exitCommands: # Set the prompt if self.module != None: self.prompt = self.cstring('(', 'red')+self.cstring("openWire", 'light_blue')+self.cstring("->", "red") + self.cstring(self.module.name, "white")+self.cstring(')', 'red') else: self.prompt = self.cstring('(', 'red')+self.cstring("openWire", 'light_blue')+self.cstring(')', 'red') # Read user input sys.stdout.write(self.prompt) sys.stdout.write(' ') line = raw_input() # Parse user input if line == "" or line in exitCommands: continue self.parseInput(line)