def _stdin_thread_start(stdin_port, display): """Standard input reader thread entry point.""" try: # Note: read length should be as large as possible for performance # yet not too large to not introduce artificial latency. # 64k seems to be perfect with an openssh backend (they issue 64k # reads) ; could consider making it an option for e.g. gsissh. bufsize = 64 * 1024 # thread loop: blocking read stdin + send messages to specified # port object buf = sys_stdin().read(bufsize) # use buffer in Python 3 while buf: # send message to specified port object (with ack) stdin_port.msg(buf) buf = sys_stdin().read(bufsize) except IOError as ex: display.vprint(VERB_VERB, "stdin: %s" % ex) # send a None message to indicate EOF stdin_port.msg(None)
def _stdin_thread_start(stdin_port, display): """Standard input reader thread entry point.""" try: # Note: read length should be as large as possible for performance # yet not too large to not introduce artificial latency. # 64k seems to be perfect with an openssh backend (they issue 64k # reads) ; could consider making it an option for e.g. gsissh. bufsize = 64 * 1024 # thread loop: blocking read stdin + send messages to specified # port object buf = sys_stdin().read(bufsize) # use buffer in Python 3 while buf: # send message to specified port object (with ack) stdin_port.msg(buf) buf = sys_stdin().read(bufsize) except IOError as ex: display.vprint(VERB_VERB, "stdin: %s" % ex) # send a None message to indicate EOF stdin_port.msg(None)
def clubak(): """script subroutine""" # Argument management parser = OptionParser("%prog [options]") parser.install_groupsconf_option() parser.install_display_options(verbose_options=True, separator_option=True, dshbak_compat=True, msgtree_mode=True) options = parser.parse_args()[0] set_std_group_resolver_config(options.groupsconf) if options.interpret_keys == THREE_CHOICES[-1]: # auto? enable_nodeset_key = None # AUTO else: enable_nodeset_key = (options.interpret_keys == THREE_CHOICES[1]) # Create new message tree if options.trace_mode: tree_mode = MODE_TRACE else: tree_mode = MODE_DEFER tree = MsgTree(mode=tree_mode) fast_mode = options.fast_mode if fast_mode: if tree_mode != MODE_DEFER or options.line_mode: parser.error("incompatible tree options") preload_msgs = {} separator = options.separator.encode() # Feed the tree from standard input lines for line in sys_stdin(): try: linestripped = line.rstrip(b'\r\n') if options.verbose or options.debug: sys_stdout().write(b'INPUT ' + linestripped + b'\n') key, content = linestripped.split(separator, 1) key = key.strip().decode() # NodeSet requires encoded string if not key: raise ValueError("no node found") if enable_nodeset_key is False: # interpret-keys=never? keyset = [key] else: try: keyset = NodeSet(key) except NodeSetParseError: if enable_nodeset_key: # interpret-keys=always? raise enable_nodeset_key = False # auto => switch off keyset = [key] if fast_mode: for node in keyset: preload_msgs.setdefault(node, []).append(content) else: for node in keyset: tree.add(node, content) except ValueError as ex: raise ValueError('%s: "%s"' % (ex, linestripped.decode())) if fast_mode: # Messages per node have been aggregated, now add to tree one # full msg per node for key, wholemsg in preload_msgs.items(): tree.add(key, b'\n'.join(wholemsg)) # Display results try: disp = Display(options) except ValueError as exc: parser.error("option mismatch (%s)" % exc) return if options.debug: std_group_resolver().set_verbosity(1) print("clubak: line_mode=%s gather=%s tree_depth=%d" % (bool(options.line_mode), bool(disp.gather), tree._depth()), file=sys.stderr) display(tree, disp, disp.gather or disp.regroup, \ options.trace_mode, enable_nodeset_key is not False)
def clubak(): """script subroutine""" # Argument management parser = OptionParser("%prog [options]") parser.install_groupsconf_option() parser.install_display_options(verbose_options=True, separator_option=True, dshbak_compat=True, msgtree_mode=True) options = parser.parse_args()[0] set_std_group_resolver_config(options.groupsconf) if options.interpret_keys == THREE_CHOICES[-1]: # auto? enable_nodeset_key = None # AUTO else: enable_nodeset_key = (options.interpret_keys == THREE_CHOICES[1]) # Create new message tree if options.trace_mode: tree_mode = MODE_TRACE else: tree_mode = MODE_DEFER tree = MsgTree(mode=tree_mode) fast_mode = options.fast_mode if fast_mode: if tree_mode != MODE_DEFER or options.line_mode: parser.error("incompatible tree options") preload_msgs = {} separator = options.separator.encode() # Feed the tree from standard input lines for line in sys_stdin(): try: linestripped = line.rstrip(b'\r\n') if options.verbose or options.debug: sys_stdout().write(b'INPUT ' + linestripped + b'\n') key, content = linestripped.split(separator, 1) key = key.strip().decode() # NodeSet requires encoded string if not key: raise ValueError("no node found") if enable_nodeset_key is False: # interpret-keys=never? keyset = [ key ] else: try: keyset = NodeSet(key) except NodeSetParseError: if enable_nodeset_key: # interpret-keys=always? raise enable_nodeset_key = False # auto => switch off keyset = [ key ] if fast_mode: for node in keyset: preload_msgs.setdefault(node, []).append(content) else: for node in keyset: tree.add(node, content) except ValueError as ex: raise ValueError('%s: "%s"' % (ex, linestripped.decode())) if fast_mode: # Messages per node have been aggregated, now add to tree one # full msg per node for key, wholemsg in preload_msgs.items(): tree.add(key, b'\n'.join(wholemsg)) # Display results try: disp = Display(options) if options.debug: std_group_resolver().set_verbosity(1) print("clubak: line_mode=%s gather=%s tree_depth=%d" % (bool(options.line_mode), bool(disp.gather), tree._depth()), file=sys.stderr) display(tree, disp, disp.gather or disp.regroup, \ options.trace_mode, enable_nodeset_key is not False) except ValueError as exc: parser.error("option mismatch (%s)" % exc)