Ejemplo n.º 1
0
def failure(s):
    trace(''.join([' ', text.boldred('[-]'), ' ', s, '\n']))
Ejemplo n.º 2
0
 def failed(s = 'FAILED!'):
     _stop_spinner(text.boldred('[-]'), s)
Ejemplo n.º 3
0
 def failed(s = 'FAILED!'):
     trace(''.join([' ', text.boldred('[-]'), ' ', _message, ': ', s, '\n']))
Ejemplo n.º 4
0
def failure(s):
    trace(''.join([' ', text.boldred('[-]'), ' ', s, '\n']))
Ejemplo n.º 5
0
 def failed(s='FAILED!'):
     trace(''.join([' ',
                    text.boldred('[-]'), ' ', _message, ': ', s, '\n']))
Ejemplo n.º 6
0
 def failed(s='FAILED!'):
     _stop_spinner(text.boldred('[-]'), s)
Ejemplo n.º 7
0
    def interactive(self,
                    prompt=text.boldred('$') + ' ',
                    clean_sock=True,
                    flush_timeout=None):
        if clean_sock:
            self.clean_sock()
        log.info('Switching to interactive mode')
        import readline
        debug = self.debug
        timeout = self.timeout
        self.debug = False
        self.settimeout(0.1)

        def write(s):
            sys.stdout.write(s)

        def save():
            write('\x1b[s')

        def restore():
            write('\x1b[u')

        def reprompt():
            write(prompt)
            write(readline.get_line_buffer())
            sys.stdout.flush()

        running = [True]  # the old by-ref trick

        def loop():
            buf = ''
            buft = time.time()
            newline = True
            while running[0]:
                if not self.can_recv(0.1):
                    continue
                try:
                    data = self.recv()
                except EOFError:
                    write('\nConnection closed\n')
                    running[0] = False
                    break
                now = time.time()
                lines = data.split('\n')
                if len(lines) == 1:
                    buf += lines[0]
                    if buf == '':
                        continue
                    # 1. if the readline buffer is empty there is no position to
                    #    remember
                    # 2. if we are not just after a newline we already f****d
                    #    the readline buffer up
                    # 3. if the timeout is reached, screw it we'll f**k the
                    #    readline buffer up in exchange for some output
                    if readline.get_line_buffer() == '' or \
                      not newline or \
                      (flush_timeout <> None and now - buft >= flush_timeout):
                        if newline:
                            write('\x1b[1G')
                        else:
                            restore()
                        write(buf)
                        save()
                        reprompt()
                        buf = ''
                        buft = now
                        newline = False
                else:
                    lines[0] = buf + lines[0]
                    if newline:
                        save()
                        write('\x1b[1G\x1b[J')
                    else:
                        restore()
                        write('\x1b[J')
                    for line in lines[:-1]:
                        write(line + '\n')
                    buf = lines[-1]
                    buft = now
                    reprompt()
                    if newline:
                        restore()
                    newline = True

        save()
        t = Thread(target=loop)
        t.daemon = True
        t.start()
        try:
            while True:
                self.send(raw_input(prompt) + '\n')
                if not running[0]:
                    t.join()
                    break
        except (KeyboardInterrupt, EOFError):
            if running[0]:
                running[0] = False
                t.join()
                write('\nInterrupted\n')
            else:
                t.join()
        except IOError:
            running[0] = False
            t.join()
            write('Connection closed\n')
        self.debug = debug
        self.settimeout(timeout)
Ejemplo n.º 8
0
    def interactive(self, prompt = text.boldred('$') + ' ', clean_sock = True,
                    flush_timeout = None):
        if clean_sock:
            self.clean_sock()
        log.info('Switching to interactive mode')
        import readline
        debug = self.debug
        timeout = self.timeout
        self.debug = False
        self.settimeout(0.1)

        def write(s):
            sys.stdout.write(s)
        def save():
            write('\x1b[s')
        def restore():
            write('\x1b[u')
        def reprompt():
            write(prompt)
            write(readline.get_line_buffer())
            sys.stdout.flush()

        running = [True] # the old by-ref trick
        def loop():
            buf = ''
            buft = time.time()
            newline = True
            while running[0]:
                if not self.can_recv(0.1):
                    continue
                try:
                    data = self.recv()
                except EOFError:
                    write('\nConnection closed\n')
                    running[0] = False
                    break
                now = time.time()
                lines = data.split('\n')
                if len(lines) == 1:
                    buf += lines[0]
                    if buf == '':
                        continue
                    # 1. if the readline buffer is empty there is no position to
                    #    remember
                    # 2. if we are not just after a newline we already f****d
                    #    the readline buffer up
                    # 3. if the timeout is reached, screw it we'll f**k the
                    #    readline buffer up in exchange for some output
                    if readline.get_line_buffer() == '' or \
                      not newline or \
                      (flush_timeout <> None and now - buft >= flush_timeout):
                        if newline:
                            write('\x1b[1G')
                        else:
                            restore()
                        write(buf)
                        save()
                        reprompt()
                        buf = ''
                        buft = now
                        newline = False
                else:
                    lines[0] = buf + lines[0]
                    if newline:
                        save()
                        write('\x1b[1G\x1b[J')
                    else:
                        restore()
                        write('\x1b[J')
                    for line in lines[:-1]:
                        write(line + '\n')
                    buf = lines[-1]
                    buft = now
                    reprompt()
                    if newline:
                        restore()
                    newline = True

        save()
        t = Thread(target = loop)
        t.daemon = True
        t.start()
        try:
            while True:
                self.send(raw_input(prompt) + '\n')
                if not running[0]:
                    t.join()
                    break
        except (KeyboardInterrupt, EOFError):
            if running[0]:
                running[0] = False
                t.join()
                write('\nInterrupted\n')
            else:
                t.join()
        except IOError:
            running[0] = False
            t.join()
            write('Connection closed\n')
        self.debug = debug
        self.settimeout(timeout)