Restore correct coloring to selective callback (#30528)

* Restore correct coloring to selective callback

This fixes the bug raised in #30506

* Fix format issues for Python 2.6 & indent

Removed the zero length fields to support format under Python 2.6

Fixed E128 continuation line under-indented for visual indent issue
pull/30631/head
Patrick Ogenstad 7 years ago committed by Brian Coca
parent 07f5a186fb
commit d74c871559

@ -41,18 +41,18 @@ import difflib
from ansible import constants as C from ansible import constants as C
from ansible.plugins.callback import CallbackBase from ansible.plugins.callback import CallbackBase
from ansible.module_utils._text import to_text from ansible.module_utils._text import to_text
from ansible.utils.color import codeCodes
DONT_COLORIZE = False DONT_COLORIZE = False
COLORS = { COLORS = {
'normal': '\033[0m', 'normal': '\033[0m',
'ok': C.COLOR_OK, 'ok': '\033[{0}m'.format(codeCodes[C.COLOR_OK]),
'bold': '\033[1m', 'bold': '\033[1m',
'not_so_bold': '\033[1m\033[34m', 'not_so_bold': '\033[1m\033[34m',
'changed': C.COLOR_CHANGED, 'changed': '\033[{0}m'.format(codeCodes[C.COLOR_CHANGED]),
'failed': C.COLOR_ERROR, 'failed': '\033[{0}m'.format(codeCodes[C.COLOR_ERROR]),
'endc': '\033[0m', 'endc': '\033[0m',
'skipped': C.COLOR_SKIP, 'skipped': '\033[{0}m'.format(codeCodes[C.COLOR_SKIP]),
} }
@ -145,19 +145,19 @@ class CallbackModule(CallbackBase):
change_string = colorize('FAILED!!!', color) change_string = colorize('FAILED!!!', color)
else: else:
color = 'changed' if changed else 'ok' color = 'changed' if changed else 'ok'
change_string = colorize("changed={}".format(changed), color) change_string = colorize("changed={0}".format(changed), color)
msg = colorize(msg, color) msg = colorize(msg, color)
line_length = 120 line_length = 120
spaces = ' ' * (40 - len(name) - indent_level) spaces = ' ' * (40 - len(name) - indent_level)
line = "{} * {}{}- {}".format(' ' * indent_level, name, spaces, change_string) line = "{0} * {1}{2}- {3}".format(' ' * indent_level, name, spaces, change_string)
if len(msg) < 50: if len(msg) < 50:
line += ' -- {}'.format(msg) line += ' -- {0}'.format(msg)
print("{} {}---------".format(line, '-' * (line_length - len(line)))) print("{0} {1}---------".format(line, '-' * (line_length - len(line))))
else: else:
print("{} {}".format(line, '-' * (line_length - len(line)))) print("{0} {1}".format(line, '-' * (line_length - len(line))))
print(self._indent_text(msg, indent_level + 4)) print(self._indent_text(msg, indent_level + 4))
if diff: if diff:
@ -240,7 +240,7 @@ class CallbackModule(CallbackBase):
else: else:
color = 'ok' color = 'ok'
msg = '{} : ok={}\tchanged={}\tfailed={}\tunreachable={}'.format( msg = '{0} : ok={1}\tchanged={2}\tfailed={3}\tunreachable={4}'.format(
host, s['ok'], s['changed'], s['failures'], s['unreachable']) host, s['ok'], s['changed'], s['failures'], s['unreachable'])
print(colorize(msg, color)) print(colorize(msg, color))
@ -253,17 +253,17 @@ class CallbackModule(CallbackBase):
line_length = 120 line_length = 120
spaces = ' ' * (31 - len(result._host.name) - 4) spaces = ' ' * (31 - len(result._host.name) - 4)
line = " * {}{}- {}".format(colorize(result._host.name, 'not_so_bold'), line = " * {0}{1}- {2}".format(colorize(result._host.name, 'not_so_bold'),
spaces, spaces,
colorize("skipped", 'skipped'),) colorize("skipped", 'skipped'),)
reason = result._result.get('skipped_reason', '') or \ reason = result._result.get('skipped_reason', '') or \
result._result.get('skip_reason', '') result._result.get('skip_reason', '')
if len(reason) < 50: if len(reason) < 50:
line += ' -- {}'.format(reason) line += ' -- {0}'.format(reason)
print("{} {}---------".format(line, '-' * (line_length - len(line)))) print("{0} {1}---------".format(line, '-' * (line_length - len(line))))
else: else:
print("{} {}".format(line, '-' * (line_length - len(line)))) print("{0} {1}".format(line, '-' * (line_length - len(line))))
print(self._indent_text(reason, 8)) print(self._indent_text(reason, 8))
print(reason) print(reason)

Loading…
Cancel
Save