Merge pull request #15035 from UtahDave/2014.7fixhighstateoutputter

use unicode strings
This commit is contained in:
Thomas S Hatch 2014-08-19 15:03:23 -06:00
commit 6dff3a1ef1

View File

@ -85,12 +85,12 @@ def _format_host(host, data):
if isinstance(data, list):
# Errors have been detected, list them in RED!
hcolor = colors['RED_BOLD']
hstrs.append((' {0}Data failed to compile:{1[ENDC]}'
hstrs.append((u' {0}Data failed to compile:{1[ENDC]}'
.format(hcolor, colors)))
for err in data:
if strip_colors:
err = salt.output.strip_esc_sequence(err)
hstrs.append(('{0}----------\n {1}{2[ENDC]}'
hstrs.append((u'{0}----------\n {1}{2[ENDC]}'
.format(hcolor, err, colors)))
if isinstance(data, dict):
# Strip out the result: True, without changes returns if
@ -100,7 +100,7 @@ def _format_host(host, data):
# Verify that the needed data is present
for tname, info in data.items():
if '__run_num__' not in info:
err = ('The State execution failed to record the order '
err = (u'The State execution failed to record the order '
'in which all states were executed. The state '
'return missing data is:')
hstrs.insert(0, pprint.pformat(info))
@ -185,37 +185,37 @@ def _format_host(host, data):
hstrs.append(msg)
continue
state_lines = [
'{tcolor}----------{colors[ENDC]}',
' {tcolor} ID: {comps[1]}{colors[ENDC]}',
' {tcolor}Function: {comps[0]}.{comps[3]}{colors[ENDC]}',
' {tcolor} Result: {ret[result]!s}{colors[ENDC]}',
' {tcolor} Comment: {comment}{colors[ENDC]}',
' {tcolor} Started: {ret[start_time]!s}{colors[ENDC]}',
' {tcolor} Duration: {ret[duration]!s}{colors[ENDC]}'
u'{tcolor}----------{colors[ENDC]}',
u' {tcolor} ID: {comps[1]}{colors[ENDC]}',
u' {tcolor}Function: {comps[0]}.{comps[3]}{colors[ENDC]}',
u' {tcolor} Result: {ret[result]!s}{colors[ENDC]}',
u' {tcolor} Comment: {comment}{colors[ENDC]}',
u' {tcolor} Started: {ret[start_time]!s}{colors[ENDC]}',
u' {tcolor} Duration: {ret[duration]!s}{colors[ENDC]}'
]
# This isn't the prettiest way of doing this, but it's readable.
if comps[1] != comps[2]:
state_lines.insert(
3, ' {tcolor} Name: {comps[2]}{colors[ENDC]}')
3, u' {tcolor} Name: {comps[2]}{colors[ENDC]}')
try:
comment = ret['comment'].strip().replace(
'\n',
'\n' + ' ' * 14)
u'\n',
u'\n' + u' ' * 14)
except AttributeError: # Assume comment is a list
try:
comment = ret['comment'].join(' ').replace(
'\n',
'\n' + ' ' * 13)
u'\n',
u'\n' + u' ' * 13)
except AttributeError:
# Comment isn't a list either, just convert to string
comment = str(ret['comment'])
comment = comment.strip().replace(
'\n',
'\n' + ' ' * 14)
u'\n',
u'\n' + u' ' * 14)
for detail in ['start_time', 'duration']:
ret.setdefault(detail, '')
ret.setdefault(detail, u'')
if ret['duration'] != '':
ret['duration'] = '{0} ms'.format(ret['duration'])
ret['duration'] = u'{0} ms'.format(ret['duration'])
svars = {
'tcolor': tcolor,
'comps': comps,
@ -225,26 +225,26 @@ def _format_host(host, data):
'colors': colors
}
hstrs.extend([sline.format(**svars) for sline in state_lines])
changes = ' Changes: ' + ctext
hstrs.append(('{0}{1}{2[ENDC]}'
changes = u' Changes: ' + ctext
hstrs.append((u'{0}{1}{2[ENDC]}'
.format(tcolor, changes, colors)))
# Append result counts to end of output
colorfmt = '{0}{1}{2[ENDC]}'
rlabel = {True: 'Succeeded', False: 'Failed', None: 'Not Run'}
colorfmt = u'{0}{1}{2[ENDC]}'
rlabel = {True: u'Succeeded', False: u'Failed', None: u'Not Run'}
count_max_len = max([len(str(x)) for x in rcounts.values()] or [0])
label_max_len = max([len(x) for x in rlabel.values()] or [0])
line_max_len = label_max_len + count_max_len + 2 # +2 for ': '
hstrs.append(
colorfmt.format(
colors['CYAN'],
'\nSummary\n{0}'.format('-' * line_max_len),
u'\nSummary\n{0}'.format('-' * line_max_len),
colors
)
)
def _counts(label, count):
return '{0}: {1:>{2}}'.format(
return u'{0}: {1:>{2}}'.format(
label,
count,
line_max_len - (len(label) + 2)
@ -257,7 +257,7 @@ def _format_host(host, data):
changestats.append(
colorfmt.format(
colors['YELLOW'],
'unchanged={0}'.format(rcounts.get(None, 0)),
u'unchanged={0}'.format(rcounts.get(None, 0)),
colors
)
)
@ -265,14 +265,14 @@ def _format_host(host, data):
changestats.append(
colorfmt.format(
colors['GREEN'],
'changed={0}'.format(nchanges),
u'changed={0}'.format(nchanges),
colors
)
)
if changestats:
changestats = ' ({0})'.format(', '.join(changestats))
changestats = u' ({0})'.format(', '.join(changestats))
else:
changestats = ''
changestats = u''
hstrs.append(
colorfmt.format(
colors['GREEN'],
@ -294,15 +294,15 @@ def _format_host(host, data):
)
)
totals = '{0}\nTotal states run: {1:>{2}}'.format('-' * line_max_len,
totals = u'{0}\nTotal states run: {1:>{2}}'.format('-' * line_max_len,
sum(rcounts.values()),
line_max_len - 7)
hstrs.append(colorfmt.format(colors['CYAN'], totals, colors))
if strip_colors:
host = salt.output.strip_esc_sequence(host)
hstrs.insert(0, ('{0}{1}:{2[ENDC]}'.format(hcolor, host, colors)))
return '\n'.join(hstrs), nchanges > 0
hstrs.insert(0, (u'{0}{1}:{2[ENDC]}'.format(hcolor, host, colors)))
return u'\n'.join(hstrs), nchanges > 0
def _format_changes(changes):
@ -312,18 +312,18 @@ def _format_changes(changes):
global __opts__ # pylint: disable=W0601
if not changes:
return False, ''
return False, u''
if not isinstance(changes, dict):
return True, 'Invalid Changes data: {0}'.format(changes)
return True, u'Invalid Changes data: {0}'.format(changes)
ret = changes.get('ret')
if ret is not None and changes.get('out') == 'highstate':
ctext = ''
ctext = u''
changed = False
for host, hostdata in ret.iteritems():
s, c = _format_host(host, hostdata)
ctext += '\n' + '\n'.join((' ' * 14 + l) for l in s.splitlines())
ctext += u'\n' + u'\n'.join((u' ' * 14 + l) for l in s.splitlines())
changed = changed or c
else:
changed = True
@ -331,9 +331,9 @@ def _format_changes(changes):
# Pass the __opts__ dict. The loader will splat this modules __opts__ dict
# anyway so have to restore it after the other outputter is done
if __opts__['color']:
__opts__['color'] = 'CYAN'
__opts__['color'] = u'CYAN'
__opts__['nested_indent'] = 14
ctext = '\n'
ctext = u'\n'
ctext += salt.output.out_format(
changes,
'nested',
@ -360,19 +360,19 @@ def _format_terse(tcolor, comps, ret, colors, tabular):
'''
Terse formatting of a message.
'''
result = "Clean"
result = u'Clean'
if ret['changes']:
result = "Changed"
result = u'Changed'
if ret['result'] is False:
result = "Failed"
result = u'Failed'
elif ret['result'] is None:
result = "Differs"
result = u'Differs'
if tabular is True:
fmt_string = '{0}{2:>10}.{3:<10} {4:7} Name: {1}{5}'
fmt_string = u'{0}{2:>10}.{3:<10} {4:7} Name: {1}{5}'
elif isinstance(tabular, str):
fmt_string = tabular
else:
fmt_string = ' {0} Name: {1} - Function: {2}.{3} - Result: {4}{5}'
fmt_string = u' {0} Name: {1} - Function: {2}.{3} - Result: {4}{5}'
msg = fmt_string.format(tcolor,
comps[2],
comps[0],