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 selected_shells(command): """Iterator over the shells with names matching the patterns. An empty patterns matches all the shells""" if not command or command == '*': for i in dispatchers.all_instances(): yield i return selected = set() instance_found = False for pattern in command.split(): found = False for expanded_pattern in expand_syntax(pattern): for i in dispatchers.all_instances(): instance_found = True if fnmatch(i.display_name, expanded_pattern): found = True if i not in selected: selected.add(i) yield i if instance_found and not found: console_output('{} not found\n'.format(pattern).encode())
def selected_shells(command): """Iterator over the shells with names matching the patterns. An empty patterns matches all the shells""" if not command or command == '*': for i in dispatchers.all_instances(): yield i return selected = set() instance_found = False for pattern in command.split(): found = False for expanded_pattern in expand_syntax(pattern): for i in dispatchers.all_instances(): instance_found = True if fnmatch(i.display_name, expanded_pattern): found = True if i not in selected: selected.add(i) yield i if instance_found and not found: console_output('%s not found\n' % pattern)
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)
def selected_shells( command: str) -> Iterator[remote_dispatcher.RemoteDispatcher]: """Iterator over the shells with names matching the patterns. An empty patterns matches all the shells""" if not command or command == '*': for i in dispatchers.all_instances(): yield i return selected = set() # type: Set[remote_dispatcher.RemoteDispatcher] instance_found = False for pattern in command.split(): found = False for expanded_pattern in expand_syntax(pattern): for i in dispatchers.all_instances(): instance_found = True if (fnmatch(i.display_name, expanded_pattern) or fnmatch( str(i.last_printed_line), expanded_pattern)): found = True if i not in selected: selected.add(i) yield i if instance_found and not found: console_output('{} not found\n'.format(pattern).encode())