Ejemplo n.º 1
0
 def on_terminal_post(self, input, sig):
     if self.client:
         msg = proto.InputResponse(input, sig)
         try:
             self.client.sendmsg(msg)
         except:
             self.disconnected.emit(self)
             self.terminal.setEnabled(False)
Ejemplo n.º 2
0
    def run(self):
        readline.parse_and_bind("tab: complete")
        readline.set_completer(self.complete)
        self.running = True
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
        self.socket.connect((self.host, self.port))
        self.on_connect()
        while self.running:
            msg = None
            try:
                msg = self.recvmsg()
            except ConnectionClosed:
                self.socket.close()
                print("session closed")
                break

            if isinstance(msg, proto.InputRequest):
                response = proto.InputResponse('')
                try:
                    line = input(msg.prompt)
                except KeyboardInterrupt:
                    response.sig = 'int'
                except EOFError:
                    response.sig = 'eof'
                else:
                    response.input = line

                try:
                    self.sendmsg(response)
                except ConnectionClosed:
                    print("session closed")
                    self.socket.close()
                    # self.fp.flush()
                    # self.fp.close()
                    break
            elif isinstance(msg, proto.ShellOutputResponse):
                print(msg.output, end='')
            # self.fp.close()
        self.on_disconnect()
        return 0