mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Generalize the fallback wrapper
This commit is contained in:
parent
b6faad4bdc
commit
a44bdb6e2b
@ -37,6 +37,22 @@ STATIC = (
|
||||
)
|
||||
|
||||
|
||||
def try_printout(data, out, opts):
|
||||
'''
|
||||
Safely get the string to print out, try the configured outputter, then
|
||||
fall back to nested and then to raw
|
||||
'''
|
||||
try:
|
||||
return get_printout(out, opts)(data).rstrip()
|
||||
except (KeyError, AttributeError):
|
||||
log.debug(traceback.format_exc())
|
||||
opts.pop('output', None)
|
||||
try:
|
||||
return get_printout('nested', opts)(data).rstrip()
|
||||
except (KeyError, AttributeError):
|
||||
return get_printout('raw', opts)(data).rstrip()
|
||||
|
||||
|
||||
def get_progress(opts, out, progress):
|
||||
'''
|
||||
Get the progress bar from the given outputter
|
||||
@ -74,12 +90,7 @@ def display_output(data, out=None, opts=None):
|
||||
'''
|
||||
if opts is None:
|
||||
opts = {}
|
||||
try:
|
||||
display_data = get_printout(out, opts)(data).rstrip()
|
||||
except (KeyError, AttributeError):
|
||||
log.debug(traceback.format_exc())
|
||||
opts.pop('output', None)
|
||||
display_data = get_printout('nested', opts)(data).rstrip()
|
||||
display_data = try_printout(data, out, opts)
|
||||
|
||||
output_filename = opts.get('output_file', None)
|
||||
log.trace('data = {0}'.format(data))
|
||||
@ -154,7 +165,7 @@ def out_format(data, out, opts=None):
|
||||
'''
|
||||
Return the formatted outputter string for the passed data
|
||||
'''
|
||||
return get_printout(out, opts)(data).rstrip()
|
||||
return try_printout(data, out, opts)
|
||||
|
||||
|
||||
def strip_esc_sequence(txt):
|
||||
|
Loading…
Reference in New Issue
Block a user