Esempio n. 1
0
def shell_thread(**kwargs):
    hist_loc = ".overwatch_shell.history"
    console = InteractiveConsole()
    console.locals = locals()
    console.locals.update(kwargs)
    console.locals.update(globals())
    console.push("import sys")
    console.push("import os")
    console.push("sys.path.append(os.getcwd())")
    readline.set_completer(rlcompleter.Completer(console.locals).complete)
    readline.parse_and_bind("tab: complete")
    if not os.path.isfile(hist_loc):
        f = open(hist_loc, "x")
        f.write("\n")
        f.close()
    readline.read_history_file(hist_loc)
    # Opens a Python shell

    todo = TodoPointer()

    def snip(location, _todo=todo):
        _todo.location = location

    console.locals["snip"] = snip

    buf = []

    def get_input(prompt):
        if len(buf) > 0:
            l = buf.pop(0)
            print("::: " + l.rstrip("\n"))
            return l
        else:
            return input(prompt)

    while True:
        try:
            c = get_input(">>> ")
            if (not c == ""):
                if console.push(
                        c
                ):  # console.push(c) executes the string c in the console.
                    # if it is True, it means it expects more input
                    # (for example a function definition)
                    _input = ' '
                    totalcommand = ''
                    while _input != '':
                        _input = get_input('... ')
                        totalcommand += _input + '\n'
                    console.push(totalcommand)

                if todo.location is not None:
                    with open(todo.location, 'r') as f:
                        code = f.readlines()
                        buf.extend(code)
                        buf.append("")
                    todo.location = None
        except (EOFError, KeyboardInterrupt):
            print("\nShell ended.")
            break
        except Exception as e:
            console.showtraceback()
        readline.write_history_file(hist_loc)
Esempio n. 2
0
 def showtraceback(self):
     InteractiveConsole.showtraceback(self)
     self.handler.handle_error(*sys.exc_info())
Esempio n. 3
0
 def showtraceback(self):
     self.exception_happened = True
     InteractiveConsole.showtraceback(self)
Esempio n. 4
0
 def showtraceback(self):
     self.write("Error occured!")
     InteractiveConsole.showtraceback(self)