示例#1
0
文件: main.py 项目: uuudoc111/polysh
def run() -> None:
    """Launch polysh"""
    locale.setlocale(locale.LC_ALL, '')
    atexit.register(kill_all)
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    args = parse_cmdline()

    args.command = find_non_interactive_command(args.command)
    args.exit_code = 0
    args.interactive = (not args.command and sys.stdin.isatty()
                        and sys.stdout.isatty())
    if args.interactive:
        restore_tty_on_exit()

    remote_dispatcher.options = args

    hosts = []  # type: List[str]
    for host in args.host_names:
        hosts.extend(expand_syntax(host))

    try:
        # stdin, stdout, stderr for polysh and each ssh connection
        new_soft = 3 + len(hosts) * 3
        old_soft, old_hard = resource.getrlimit(resource.RLIMIT_NOFILE)
        if new_soft > old_soft:
            # We are allowed to change the soft limit as we please but must be
            # root to change the hard limit.
            new_hard = max(new_soft, old_hard)
            resource.setrlimit(resource.RLIMIT_NOFILE, (new_soft, new_hard))
    except OSError as e:
        print(
            'Failed to change RLIMIT_NOFILE from soft={} hard={} to soft={} '
            'hard={}: {}'.format(old_soft, old_hard, new_soft, new_hard, e),
            file=sys.stderr,
        )
        sys.exit(1)

    dispatchers.create_remote_dispatchers(hosts)

    signal.signal(signal.SIGWINCH,
                  lambda signum, frame: dispatchers.update_terminal_size())

    stdin.the_stdin_thread = stdin.StdinThread(args.interactive)

    if args.profile:

        def safe_loop() -> None:
            try:
                loop(args.interactive)
            except BaseException:
                pass

        _profile(safe_loop)
    else:
        loop(args.interactive)
示例#2
0
def do_reconnect(command: str) -> None:
    selec = selected_shells(command)
    to_reconnect = [
        i for i in selec if i.state == remote_dispatcher.STATE_DEAD
    ]
    for i in to_reconnect:
        i.disconnect()
        i.close()

    hosts = [i.hostname for i in to_reconnect]
    dispatchers.create_remote_dispatchers(hosts)
示例#3
0
def do_reconnect(command):
    """
    Usage: :reconnect [SHELLS...]
    Try to reconnect to disconnected remote shells.
    The special characters * ? and [] work as expected.
    """
    selec = selected_shells(command)
    to_reconnect = [i for i in selec if i.state == remote_dispatcher.STATE_DEAD]
    for i in to_reconnect:
        i.disconnect()
        i.close()

    hosts = [i.hostname for i in to_reconnect]
    dispatchers.create_remote_dispatchers(hosts)
示例#4
0
def main():
    """Launch polysh"""
    locale.setlocale(locale.LC_ALL, '')
    setprocname('polysh')
    options, args = parse_cmdline()

    atexit.register(kill_all)
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)
    options.command = find_non_interactive_command(options.command)
    options.exit_code = 0
    options.interactive = not options.command and sys.stdin.isatty() and \
                          sys.stdout.isatty()
    if options.interactive:
        def handler(sig, frame):
            global next_signal
            next_signal = sig
        signal.signal(signal.SIGINT, handler)
        signal.signal(signal.SIGTSTP, handler)
        restore_tty_on_exit()
    else:
      def handler(sig, frame):
        signal.signal(sig, signal.SIG_DFL)
        kill_all()
        os.kill(0, sig)
      signal.signal(signal.SIGINT, handler)

    remote_dispatcher.options = options

    hosts = []
    for arg in args:
        hosts.extend(expand_syntax(arg))

    dispatchers.create_remote_dispatchers(hosts)

    signal.signal(signal.SIGWINCH, lambda signum, frame:
                                            dispatchers.update_terminal_size())

    the_stdin_thread.activate(options.interactive)

    if options.profile:
        def safe_main_loop():
            try:
                main_loop()
            except:
                pass
        _profile(safe_main_loop)
    else:
        main_loop()
示例#5
0
def do_reconnect(command):
    """
    Usage: :reconnect [SHELLS...]
    Try to reconnect to disconnected remote shells.
    The special characters * ? and [] work as expected.
    """
    selec = selected_shells(command)
    to_reconnect = [
        i for i in selec if i.state == remote_dispatcher.STATE_DEAD
    ]
    for i in to_reconnect:
        i.disconnect()
        i.close()

    hosts = [i.hostname for i in to_reconnect]
    dispatchers.create_remote_dispatchers(hosts)
示例#6
0
文件: main.py 项目: bhyvex/polysh
def run():
    """Launch polysh"""
    locale.setlocale(locale.LC_ALL, '')
    atexit.register(kill_all)
    signal.signal(signal.SIGPIPE, signal.SIG_DFL)

    args = parse_cmdline()

    args.command = find_non_interactive_command(args.command)
    args.exit_code = 0
    args.interactive = (
        not args.command
        and sys.stdin.isatty()
        and sys.stdout.isatty())
    if args.interactive:
        restore_tty_on_exit()

    remote_dispatcher.options = args

    hosts = []
    for host in args.host_names:
        hosts.extend(expand_syntax(host))

    dispatchers.create_remote_dispatchers(hosts)

    signal.signal(signal.SIGWINCH, lambda signum, frame:
                  dispatchers.update_terminal_size())

    stdin.the_stdin_thread = stdin.StdinThread(args.interactive)

    if args.profile:
        def safe_loop():
            try:
                loop(args.interactive)
            except BaseException:
                pass
        _profile(safe_loop)
    else:
        loop(args.interactive)
示例#7
0
def do_add(command: str) -> None:
    dispatchers.create_remote_dispatchers(command.split())
示例#8
0
def do_add(command):
    """
    Usage: :add NAMES...
    Add one or many remote shells.
    """
    dispatchers.create_remote_dispatchers(command.split())
示例#9
0
def do_add(command):
    """
    Usage: :add NAMES...
    Add one or many remote shells.
    """
    dispatchers.create_remote_dispatchers(command.split())
示例#10
0
def do_add(command):
    dispatchers.create_remote_dispatchers(command.split())