cli.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:cumin 作者: wikimedia 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号