mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Optimize the code for the callback module (#56827)
* Optimize the code for the callback module * fix pep error * Restore incorrectly submitted code * fix pep error * fix pep error * Restore incorrectly submitted code * Restore incorrectly submitted code * fix condition * fix condition * fix pep error
This commit is contained in:
parent
b9b0b23015
commit
95882faca6
4 changed files with 12 additions and 11 deletions
|
@ -98,6 +98,10 @@ class CallbackBase(AnsiblePlugin):
|
|||
# load from config
|
||||
self._plugin_options = C.config.get_plugin_options(get_plugin_class(self), self._load_name, keys=task_keys, variables=var_options, direct=direct)
|
||||
|
||||
def _run_is_verbose(self, result, verbosity=0):
|
||||
return ((self._display.verbosity > verbosity or result._result.get('_ansible_verbose_always', False) is True)
|
||||
and result._result.get('_ansible_verbose_override', False) is False)
|
||||
|
||||
def _dump_results(self, result, indent=None, sort_keys=True, keep_invocation=False):
|
||||
|
||||
if not indent and (result.get('_ansible_verbose_always') or self._display.verbosity > 2):
|
||||
|
|
|
@ -178,7 +178,7 @@ class CallbackModule(CallbackBase):
|
|||
else:
|
||||
self._clean_results(result._result, result._task.action)
|
||||
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
if self._run_is_verbose(result):
|
||||
msg += " => %s" % (self._dump_results(result._result),)
|
||||
self._display.display(msg, color=color)
|
||||
|
||||
|
@ -226,7 +226,7 @@ class CallbackModule(CallbackBase):
|
|||
self._process_items(result)
|
||||
else:
|
||||
msg = "skipping: %d/%d [%s]" % (self._host_counter, self._host_total, result._host.get_name())
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
if self._run_is_verbose(result):
|
||||
msg += " => %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=C.COLOR_SKIP)
|
||||
|
||||
|
|
|
@ -131,7 +131,7 @@ class CallbackModule(CallbackBase):
|
|||
else:
|
||||
self._clean_results(result._result, result._task.action)
|
||||
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
if self._run_is_verbose(result):
|
||||
msg += " => %s" % (self._dump_results(result._result),)
|
||||
self._display.display(msg, color=color)
|
||||
|
||||
|
@ -148,7 +148,7 @@ class CallbackModule(CallbackBase):
|
|||
self._process_items(result)
|
||||
else:
|
||||
msg = "skipping: [%s]" % result._host.get_name()
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
if self._run_is_verbose(result):
|
||||
msg += " => %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=C.COLOR_SKIP)
|
||||
|
||||
|
@ -287,7 +287,7 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
msg += " => (item=%s)" % (self._get_item_label(result._result),)
|
||||
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
if self._run_is_verbose(result):
|
||||
msg += " => %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=color)
|
||||
|
||||
|
@ -315,7 +315,7 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
self._clean_results(result._result, result._task.action)
|
||||
msg = "skipping: [%s] => (item=%s) " % (result._host.get_name(), self._get_item_label(result._result))
|
||||
if (self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
if self._run_is_verbose(result):
|
||||
msg += " => %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=C.COLOR_SKIP)
|
||||
|
||||
|
@ -397,7 +397,7 @@ class CallbackModule(CallbackBase):
|
|||
def v2_runner_retry(self, result):
|
||||
task_name = result.task_name or result._task
|
||||
msg = "FAILED - RETRYING: %s (%d retries left)." % (task_name, result._result['retries'] - result._result['attempts'])
|
||||
if (self._display.verbosity > 2 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
if self._run_is_verbose(result, verbosity=2):
|
||||
msg += "Result was: %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=C.COLOR_DEBUG)
|
||||
|
||||
|
|
|
@ -48,9 +48,6 @@ class CallbackModule(CallbackBase):
|
|||
CALLBACK_TYPE = 'stdout'
|
||||
CALLBACK_NAME = 'unixy'
|
||||
|
||||
def _run_is_verbose(self, result):
|
||||
return ((self._display.verbosity > 0 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result)
|
||||
|
||||
def _get_task_display_name(self, task):
|
||||
self.task_display_name = None
|
||||
display_name = task.get_name().strip().split(" : ")
|
||||
|
@ -216,6 +213,6 @@ class CallbackModule(CallbackBase):
|
|||
|
||||
def v2_runner_retry(self, result):
|
||||
msg = " Retrying... (%d of %d)" % (result._result['attempts'], result._result['retries'])
|
||||
if (self._display.verbosity > 2 or '_ansible_verbose_always' in result._result) and '_ansible_verbose_override' not in result._result:
|
||||
if self._run_is_verbose(result, verbosity=2):
|
||||
msg += "Result was: %s" % self._dump_results(result._result)
|
||||
self._display.display(msg, color=C.COLOR_DEBUG)
|
||||
|
|
Loading…
Reference in a new issue