def echo_output(func):
"""if the wrapped function is the sole task being run, then it's output is
printed to stdout. this wrapper first attempts to pass the keyword
'verbose' to the function and, if it fails, calls it without.
"""
@wraps(func)
def _wrapper(*args, **kwargs):
if _sole_task(func.__name__):
res = func(*args, **kwargs)
errcho('output:') # printing to stderr avoids corrupting structured data
if isinstance(res, str) or isinstance(res, unicode):
print res
else:
print pformat(remove_ordereddict(res))
return res
return func(*args, **kwargs)
return _wrapper
# avoid circular dependencies.
# TODO: this is a design smell. refactor.
评论列表
文章目录