+def do_command(parsed_args, target, cmdargs, sigdict, inbuf, verbose):
+ ''' Validate a command, and handle the polling flag '''
+
+ valid_dict = validate_command(sigdict, cmdargs, verbose)
+ # Validate input args against list of sigs
+ if valid_dict:
+ if parsed_args.output_format:
+ valid_dict['format'] = parsed_args.output_format
+ if verbose:
+ print("Submitting command: ", valid_dict, file=sys.stderr)
+ else:
+ return -errno.EINVAL, '', 'invalid command'
+
+ next_header_print = 0
+ # Set extra options for polling commands only:
+ if valid_dict.get('poll', False):
+ valid_dict['width'] = Termsize().cols
+ while True:
+ try:
+ # Only print the header for polling commands
+ if next_header_print == 0 and valid_dict.get('poll', False):
+ valid_dict['print_header'] = True
+ next_header_print = Termsize().rows - 3
+ next_header_print -= 1
+ ret, outbuf, outs = json_command(cluster_handle, target=target,
+ argdict=valid_dict, inbuf=inbuf, verbose=verbose)
+ if valid_dict.get('poll', False):
+ valid_dict['print_header'] = False
+ if not valid_dict.get('poll', False):
+ # Don't print here if it's not a polling command
+ break
+ if ret:
+ ret = abs(ret)
+ print('Error: {0} {1}'.format(ret, errno.errorcode.get(ret, 'Unknown')),
+ file=sys.stderr)
+ break
+ if outbuf:
+ print(outbuf.decode('utf-8'))
+ if outs:
+ print(outs, file=sys.stderr)
+ if parsed_args.period <= 0:
+ break
+ sleep(parsed_args.period)
+ except KeyboardInterrupt:
+ print('Interrupted')
+ return errno.EINTR, '', ''
+ if ret == errno.ETIMEDOUT:
+ ret = -ret
+ if not outs:
+ outs = ("Connection timed out. Please check the client's " +
+ "permission and connection.")
+ return ret, outbuf, outs
+
+
+def new_style_command(parsed_args,
+ cmdargs,
+ target,
+ sigdict,
+ inbuf, verbose) -> Tuple[int, bytes, str]: