def start(): shell = KeykitShell() completer = Completer(shell=shell) # Load history try: readline.read_history_file(PYCONSOLE_HIST_FILE) except IOError: warn("Can't read history file") # Load help system in background thread doc_thread = Thread(target=load_keykit_library) doc_thread.start() # Start Input loop try: shell.cmdloop() except KeyboardInterrupt: warn("Ctrl+C pressed. Quitting keykit shell.") shell.close() except TypeError: warn("Type error. Quitting keykit shell.") shell.close() finally: shell.close() # Write history try: readline.set_history_length(100000) readline.write_history_file(".pyconsole.history") except IOError: warn("Can't write history file")
def __init__(self, rootclass, prompt='> ', histfile=os.path.join(os.environ.get('HOME', ''), '.icmd_hist'), welcometext='Type \'help\' for help.', helptext_prefix='The following commands are available:\n', helptext_suffix='\n(type \'help <command>\' for details)\n', batch=False): """ Create a new interactive commandline interface to rootclass by creating an instance of rootclass (your class must derive from ICmdBase). Use ICmd.run() or run_once() to start the commandline client. `batch` indicates wether to run in batch mode. If so, ICmd is silent (except for errors) and non-interactive; instead reading from stdin and executing each line as a command. It will exit after no more lines are available. """ self.rootclass = rootclass self.prompt = prompt self.welcometext = welcometext self.batch = batch self.histfile = histfile self.instclass = self.rootclass(helptext_prefix, helptext_suffix, self.batch) # Initialize readline, but only if we we're able to load the module. if 'readline' in sys.modules or 'pyreadline' in sys.modules: logging.info("Using readline") try: readline.read_history_file(self.histfile) except IOError: pass logging.info("Setting readline completer") readline.set_completer(self._completer) readline.parse_and_bind("tab: complete") if not self.batch: sys.stdout.write(welcometext + '\n')
def __read_input(self): readline.set_completer(rlcompleter.Completer(self.__vars).complete) readline.parse_and_bind("tab: complete") if os.path.exists(self.HistoryFile.value): readline.read_history_file(self.HistoryFile.value) while (True): try: line = raw_input('\001' + print_green + '\002' + self.Prompt.value + '\001' + print_reset + '\002') self.__input_queue.put(line) except: print "Exiting GuaVe, press Ctrl-C to kill guacamole..." #sys.exit(0) break
def __read_input(self): readline.set_completer(rlcompleter.Completer(self.__vars).complete) readline.parse_and_bind("tab: complete") if os.path.exists(self.HistoryFile.value): readline.read_history_file(self.HistoryFile.value) while True: try: line = input("\001" + print_green + "\002" + self.Prompt.value + "\001" + print_reset + "\002") self.__input_queue.put(line) except EOFError: print("Bye") # , press Ctrl-C to kill guacamole...") os._exit(0) except IOError as err: print("I/O error: {0}".format(err)) os._exit(1) except: print("Unexpected error:", sys.exc_info()[0]) os._exit(1)
def __read_input(self): readline.set_completer(rlcompleter.Completer(self.__vars).complete) readline.parse_and_bind("tab: complete") if os.path.exists(self.HistoryFile.value): readline.read_history_file(self.HistoryFile.value) while (True): try: line = input('\001' + print_green + '\002' + self.Prompt.value + '\001' + print_reset + '\002') self.__input_queue.put(line) except EOFError: print("Bye") #, press Ctrl-C to kill guacamole...") os._exit(0) except IOError as err: print("I/O error: {0}".format(err)) os._exit(1) except: print("Unexpected error:", sys.exc_info()[0]) os._exit(1)
Use: FILE or CLIPBOARD function for importing data OUTPUT or CLIPOUT function for exporting data""" if 'HOME' not in os.environ: # Windows systems if 'HOMEDRIVE' in os.environ and 'HOMEPATH' in os.environ: os.environ['HOME'] = os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH']) else: os.environ['HOME'] = "C:\\" histfile = os.path.join(os.environ["HOME"], ".mterm") automatic_reload=False if not pipedinput: try: readline.read_history_file(histfile) except IOError: pass import atexit atexit.register(readline.write_history_file, histfile) automatic_reload=True readline.set_completer(mcomplete) readline.parse_and_bind("tab: complete") readline.set_completer_delims(' \t\n`!@#$^&*()=+[{]}|;:\'",<>?') separator = "|" allquote = False beeping = False db = "" language, output_encoding = locale.getdefaultlocale()
Use: FILE or CLIPBOARD function for importing data OUTPUT or CLIPOUT function for exporting data""" if 'HOME' not in os.environ: # Windows systems if 'HOMEDRIVE' in os.environ and 'HOMEPATH' in os.environ: os.environ['HOME'] = os.path.join(os.environ['HOMEDRIVE'], os.environ['HOMEPATH']) else: os.environ['HOME'] = "C:\\" histfile = os.path.join(os.environ["HOME"], ".mterm") automatic_reload = False if not pipedinput: try: readline.read_history_file(histfile) except IOError: pass import atexit atexit.register(readline.write_history_file, histfile) automatic_reload = True readline.set_completer(mcomplete) readline.parse_and_bind("tab: complete") readline.set_completer_delims(' \t\n`!@#$^&*()=+[{]}|;:\'",<>?') separator = "|" allquote = False beeping = False db = ""