Improve readability

pull/18539/head
Dag Wieers 9 years ago committed by Brian Coca
parent 326bb24a89
commit 67c57a9b6b

@ -110,6 +110,7 @@ class ansi:
default = '\033[0;0m' default = '\033[0;0m'
colors = dict(ok=ansi.darkgreen, changed=ansi.darkyellow, failed=ansi.darkred, unreachable=ansi.darkred)
class CallbackModule(CallbackModule_default): class CallbackModule(CallbackModule_default):
@ -138,24 +139,31 @@ class CallbackModule(CallbackModule_default):
self.super_ref = super(CallbackModule, self) self.super_ref = super(CallbackModule, self)
self.super_ref.__init__() self.super_ref.__init__()
if self._display.verbosity > 1: # When using -vv or higher, simply do the default action
if self._display.verbosity >= 2:
return return
self.hosts = [] self.hosts = []
self.keep = False self.keep = False
self.shown_title = False self.shown_title = False
self.tasknr = 0 self.tasknr = 0
self.playnr = 0 self.playnr = 0
# Start immediately on the first line
sys.stdout.write(ansi.save + ansi.clearline) sys.stdout.write(ansi.save + ansi.clearline)
sys.stdout.flush() sys.stdout.flush()
def _add_host(self, result, status): def _add_host(self, result, status):
self.hosts.append((result._host.get_name(), status)) self.hosts.append((result._host.get_name(), status))
self._display_progress() self._display_progress(result)
# Ensure that tasks with changes/failures stay on-screen
if status in ['changed', 'failed', 'unreachable']: if status in ['changed', 'failed', 'unreachable']:
# Ensure that tasks with changes/failures stay on-screen
self.keep = True self.keep = True
if self._display.verbosity == 1: if self._display.verbosity == 1:
self._display_task_banner() self._display_task_banner()
# TODO: clean up result output, eg. remove changed, delta, end, start, ... # TODO: clean up result output, eg. remove changed, delta, end, start, ...
if status == 'changed': if status == 'changed':
self.super_ref.v2_runner_on_ok(result) self.super_ref.v2_runner_on_ok(result)
@ -174,7 +182,7 @@ class CallbackModule(CallbackModule_default):
else: else:
sys.stdout.write(ansi.restore + ansi.clearline) sys.stdout.write(ansi.restore + ansi.clearline)
def _display_progress(self): def _display_progress(self, host=False):
# Always rewrite the complete line # Always rewrite the complete line
sys.stdout.write(ansi.restore + ansi.clearline + ansi.underline) sys.stdout.write(ansi.restore + ansi.clearline + ansi.underline)
sys.stdout.write('task %d:' % self.tasknr) sys.stdout.write('task %d:' % self.tasknr)
@ -183,19 +191,7 @@ class CallbackModule(CallbackModule_default):
# Print out each host with its own status-color # Print out each host with its own status-color
for name, status in self.hosts: for name, status in self.hosts:
if status == 'ok': sys.stdout.write(colors[status] + name + ansi.default + ' ')
color = ansi.darkgreen
elif status == 'changed':
color = ansi.darkyellow
elif status == 'skipped':
color = ansi.darkcyan
elif status == 'failed':
color = ansi.darkred
elif status == 'unreachable':
color = ansi.white + ansi.redbg
# if self.hosts and self.hosts[-1][1] in ['changed', 'failed']:
# sys.stdout.write('<-' + ansi.restore + '\n' + ansi.save)
sys.stdout.write(color + name + ansi.default + ' ')
sys.stdout.flush() sys.stdout.flush()
# Place cursor at start of the line # Place cursor at start of the line
@ -206,20 +202,23 @@ class CallbackModule(CallbackModule_default):
self.super_ref.v2_playbook_on_play_start(play) self.super_ref.v2_playbook_on_play_start(play)
return return
# Reset counters at the start of each play
self.tasknr = 0 self.tasknr = 0
self.playnr += 1 self.playnr += 1
self.play = play self.play = play
# Leave the previous task on screen (as it has changes/errors) # Leave the previous task on screen (as it has changes/errors)
if self.keep: if self.keep:
sys.stdout.write(ansi.restore + '\n' + ansi.save + ansi.clearline + ansi.bold) sys.stdout.write(ansi.restore + '\n' + ansi.save + ansi.clearline + ansi.bold)
else: else:
sys.stdout.write(ansi.restore + ansi.clearline + ansi.bold) sys.stdout.write(ansi.restore + ansi.clearline + ansi.bold)
sys.stdout.flush()
# Write the next play on screen IN UPPERCASE, and make it permanent
name = play.get_name().strip() name = play.get_name().strip()
if name: if not name:
sys.stdout.write('PLAY %d: %s' % (self.playnr, name.upper())) name = 'unnamed'
else: sys.stdout.write('PLAY %d: %s' % (self.playnr, name.upper()))
sys.stdout.write('PLAY %d' % self.playnr)
# Always leave the PLAY output on screen
sys.stdout.write(ansi.restore + '\n' + ansi.save + ansi.reset + ansi.clearline) sys.stdout.write(ansi.restore + '\n' + ansi.save + ansi.reset + ansi.clearline)
sys.stdout.flush() sys.stdout.flush()
@ -232,7 +231,7 @@ class CallbackModule(CallbackModule_default):
if self._display.verbosity == 0 and self.keep: if self._display.verbosity == 0 and self.keep:
sys.stdout.write(ansi.restore + '\n' + ansi.save + ansi.clearline) sys.stdout.write(ansi.restore + '\n' + ansi.save + ansi.clearline)
# Reset counters at the start of each new task # Reset counters at the start of each task
self.keep = False self.keep = False
self.shown_title = False self.shown_title = False
self.hosts = [] self.hosts = []
@ -241,22 +240,23 @@ class CallbackModule(CallbackModule_default):
# Enumerate task if not setup (task names are too long for dense output) # Enumerate task if not setup (task names are too long for dense output)
if task.get_name() != 'setup': if task.get_name() != 'setup':
self.tasknr += 1 self.tasknr += 1
# self.task = task.get_name().strip()
# Write the next task on screen (behind the prompt is the previous output) # Write the next task on screen (behind the prompt is the previous output)
sys.stdout.write(ansi.restore + ansi.underline) sys.stdout.write(ansi.restore + ansi.underline)
sys.stdout.write('task %d' % self.tasknr) sys.stdout.write('task %d:' % self.tasknr)
sys.stdout.write(ansi.reset) sys.stdout.write(ansi.reset)
sys.stdout.flush() sys.stdout.flush()
# self._display_progress()
def v2_runner_on_failed(self, result, ignore_errors=False): def v2_runner_on_failed(self, result, ignore_errors=False):
if self._display.verbosity > 1: if self._display.verbosity >= 2:
self.super_ref.v2_runner_on_failed(result, ignore_errors) self.super_ref.v2_runner_on_failed(result, ignore_errors)
return return
self._add_host(result, 'failed') self._add_host(result, 'failed')
def v2_runner_on_ok(self, result): def v2_runner_on_ok(self, result):
if self._display.verbosity > 1: if self._display.verbosity >= 2:
self.super_ref.v2_runner_on_ok(result) self.super_ref.v2_runner_on_ok(result)
return return
@ -266,48 +266,48 @@ class CallbackModule(CallbackModule_default):
self._add_host(result, 'ok') self._add_host(result, 'ok')
def v2_runner_on_skipped(self, result): def v2_runner_on_skipped(self, result):
if self._display.verbosity > 1: if self._display.verbosity >= 2:
self.super_ref.v2_runner_on_skipped(result) self.super_ref.v2_runner_on_skipped(result)
return return
self._add_host(result, 'skipped') self._add_host(result, 'skipped')
def v2_runner_on_unreachable(self, result): def v2_runner_on_unreachable(self, result):
if self._display.verbosity > 1: if self._display.verbosity >= 2:
self.super_ref.v2_runner_on_unreachable(result) self.super_ref.v2_runner_on_unreachable(result)
return return
self._add_host(result, 'unreachable') self._add_host(result, 'unreachable')
def v2_runner_on_include(self, included_file): def v2_runner_on_include(self, included_file):
if self._display.verbosity > 1: if self._display.verbosity >= 2:
self.super_ref.v2_runner_on_include(included_file) self.super_ref.v2_runner_on_include(included_file)
def v2_playbook_item_on_ok(self, result): def v2_playbook_item_on_ok(self, result):
if self._display.verbosity > 1: if self._display.verbosity >= 2:
self.super_ref.v2_playbook_item_on_ok(result) self.super_ref.v2_playbook_item_on_ok(result)
# TBD # TBD
def v2_playbook_item_on_failed(self, result): def v2_playbook_item_on_failed(self, result):
if self._display.verbosity > 1: if self._display.verbosity >= 2:
self.super_ref.v2_playbook_item_on_failed(result) self.super_ref.v2_playbook_item_on_failed(result)
# TBD # TBD
def v2_playbook_item_on_skipped(self, result): def v2_playbook_item_on_skipped(self, result):
if self._display.verbosity > 1: if self._display.verbosity >= 2:
self.super_ref.v2_playbook_item_on_skipped(result) self.super_ref.v2_playbook_item_on_skipped(result)
# TBD # TBD
def v2_playbook_on_no_hosts_remaining(self): def v2_playbook_on_no_hosts_remaining(self):
if self._display.verbosity > 1: if self._display.verbosity >= 2:
self.super_ref.v2_runner_on_no_hosts_remaining() self.super_ref.v2_runner_on_no_hosts_remaining()
return return
# TBD # TBD
if self.keep: if self._display.verbosity == 0 and self.keep:
sys.stdout.write(ansi.restore + '\n' + ansi.save + ansi.clearline) sys.stdout.write(ansi.restore + '\n' + ansi.save + ansi.clearline)
else: else:
sys.stdout.write(ansi.restore + ansi.clearline) sys.stdout.write(ansi.restore + ansi.clearline)

Loading…
Cancel
Save