def print_output(output_format, worker):
"""Print the execution results in a specific format.
Arguments:
output_format: the output format to use, one of: 'txt', 'json'.
worker: the Transport worker instance to retrieve the results from.
"""
if output_format not in OUTPUT_FORMATS:
raise cumin.CuminError("Got invalid output format '{fmt}', expected one of {allowed}".format(
fmt=output_format, allowed=OUTPUT_FORMATS))
out = {}
for nodeset, output in worker.get_results():
for node in nodeset:
if output_format == 'txt':
out[node] = '\n'.join(['{node}: {line}'.format(node=node, line=line) for line in output.lines()])
elif output_format == 'json':
out[node] = output.message()
if output_format == 'txt':
for node in sorted(out.keys()):
tqdm.write(out[node])
elif output_format == 'json':
tqdm.write(json.dumps(out, indent=4, sort_keys=True))
评论列表
文章目录