def update_max_display_name_length() -> None: from polysh.dispatchers import update_terminal_size new_max = max(NR_ENABLED_DISPLAY_NAMES_BY_LENGTH.keys(), default=0) global max_display_name_length if new_max != max_display_name_length: max_display_name_length = new_max update_terminal_size()
def update_max_display_name_length(): from polysh import dispatchers if len(NR_ENABLED_DISPLAY_NAMES_BY_LENGTH) == 0: new_max = 0 else: new_max = NR_ENABLED_DISPLAY_NAMES_BY_LENGTH.lastNode().key global max_display_name_length if new_max != max_display_name_length: max_display_name_length = new_max dispatchers.update_terminal_size()
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)
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()
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)