From fc97af8ab17a91e6bdfca69a2b261ff775e31884 Mon Sep 17 00:00:00 2001 From: Patrick Ogenstad Date: Wed, 20 Sep 2017 15:14:59 +0200 Subject: [PATCH] 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 (cherry picked from commit d74c8715599651b0f9993909bd71753d88fbd312) updated clog --- CHANGELOG.md | 1 + lib/ansible/plugins/callback/selective.py | 34 +++++++++++------------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3494d5e2499..67221069e7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ Ansible Changes By Release * Corrected and added missing feature and porting docs for 2.4 * Fix for Ansible.ModuleUtils.CamelConversion to handle empty lists and lists with one entry * Fix nxos terminal regex to parse username correctly. +* Fix colors for selective callback diff --git a/lib/ansible/plugins/callback/selective.py b/lib/ansible/plugins/callback/selective.py index 47851290117..b4575cbc7b0 100644 --- a/lib/ansible/plugins/callback/selective.py +++ b/lib/ansible/plugins/callback/selective.py @@ -41,18 +41,18 @@ import difflib from ansible import constants as C from ansible.plugins.callback import CallbackBase from ansible.module_utils._text import to_text - +from ansible.utils.color import codeCodes DONT_COLORIZE = False COLORS = { 'normal': '\033[0m', - 'ok': C.COLOR_OK, + 'ok': '\033[{0}m'.format(codeCodes[C.COLOR_OK]), 'bold': '\033[1m', 'not_so_bold': '\033[1m\033[34m', - 'changed': C.COLOR_CHANGED, - 'failed': C.COLOR_ERROR, + 'changed': '\033[{0}m'.format(codeCodes[C.COLOR_CHANGED]), + 'failed': '\033[{0}m'.format(codeCodes[C.COLOR_ERROR]), '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) else: 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) line_length = 120 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: - line += ' -- {}'.format(msg) - print("{} {}---------".format(line, '-' * (line_length - len(line)))) + line += ' -- {0}'.format(msg) + print("{0} {1}---------".format(line, '-' * (line_length - len(line)))) 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)) if diff: @@ -240,7 +240,7 @@ class CallbackModule(CallbackBase): else: 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']) print(colorize(msg, color)) @@ -253,17 +253,17 @@ class CallbackModule(CallbackBase): line_length = 120 spaces = ' ' * (31 - len(result._host.name) - 4) - line = " * {}{}- {}".format(colorize(result._host.name, 'not_so_bold'), - spaces, - colorize("skipped", 'skipped'),) + line = " * {0}{1}- {2}".format(colorize(result._host.name, 'not_so_bold'), + spaces, + colorize("skipped", 'skipped'),) reason = result._result.get('skipped_reason', '') or \ result._result.get('skip_reason', '') if len(reason) < 50: - line += ' -- {}'.format(reason) - print("{} {}---------".format(line, '-' * (line_length - len(line)))) + line += ' -- {0}'.format(reason) + print("{0} {1}---------".format(line, '-' * (line_length - len(line)))) else: - print("{} {}".format(line, '-' * (line_length - len(line)))) + print("{0} {1}".format(line, '-' * (line_length - len(line)))) print(self._indent_text(reason, 8)) print(reason)