

def radssh_tty(cluster, logdir, cmd, *args):
    'Invoke a TTY single session'
    (cols, lines) = terminal_size()
    if (not args):
        args = []
        for k in sorted(cluster.connections.keys()):
            if (k not in cluster.disabled):
                args.append(str(k))
    oldtty = termios.tcgetattr(sys.stdin)
    tty.setraw(sys.stdin.fileno())
    tty.setcbreak(sys.stdin.fileno())
    fcntl.fcntl(sys.stdin, fcntl.F_SETFL, os.O_NONBLOCK)
    prompt_delay = 3.0
    for x in args:
        if (not cluster.locate(x)):
            print(('Skipping TTY request for %s (not found)\r' % str(x)))
            continue
        try:
            print(('Starting TTY session for [%s] in %g seconds...\r' % (x, prompt_delay)))
            print("(Press 'S' to skip, 'X' to abort, any other key to connect immediately)", end='')
            sys.stdout.flush()
            (r, w, e) = select.select([sys.stdin], [], [], prompt_delay)
            print('\r\n')
            if r:
                keystroke = sys.stdin.read()
                if (keystroke in ('s', 'S')):
                    continue
                if (keystroke in ('x', 'X')):
                    break
        except Exception as e:
            print(e)
        try:
            session = None
            t = cluster.connections[cluster.locate(x)]
            if (not k.is_authenticated()):
                print(('Skipping TTY request for %s (not authenticated)\r' % str(x)))
                continue
            session = t.open_session()
            session.set_combine_stderr(True)
            session.get_pty(width=cols, height=lines)
            print(('Starting TTY session for %s\r' % str(x)))
            session.invoke_shell()
            posix_shell(session, cluster.defaults['character_encoding'])
            print(('TTY session for %s completed\r' % str(x)))
            session.close()
        except Exception as e:
            print(('Exception occurred while trying TTY for %s\r' % str(x)))
            print(repr(e))
            if session:
                session.close()
    termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty)

dataset/ETHPy150Open radssh/radssh/radssh/core_plugins/test_tty.py radssh_tty/VarMisuse@329/466 `t`->`k`