diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-07-12 17:36:59 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-07-12 17:36:59 +0900 |
commit | 703b28c822295fc668af1c380c7fae7ae33b10bf (patch) | |
tree | eb4b3cb6307babf313f2a55d61d30d0895ad6c00 | |
parent | aa0ec80255bee0771a0d0fe5d9401b9f34d7036f (diff) | |
download | buildstream-703b28c822295fc668af1c380c7fae7ae33b10bf.tar.gz |
widget.py: Added LogLine.print_summary()
Used to print a summary at the end of a scheduler session, prints
the status of queues in order.
-rw-r--r-- | buildstream/_frontend/widget.py | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py index 4fa0addbf..cd4cbdcbb 100644 --- a/buildstream/_frontend/widget.py +++ b/buildstream/_frontend/widget.py @@ -272,7 +272,7 @@ class LogFile(Widget): # A widget for formatting a log line class LogLine(Widget): - def __init__(self, content_profile, format_profile, err_profile, detail_profile, + def __init__(self, content_profile, format_profile, success_profile, err_profile, detail_profile, indent=4, log_lines=10, message_lines=10, @@ -280,6 +280,7 @@ class LogLine(Widget): super(LogLine, self).__init__(content_profile, format_profile) self.columns = [] + self.success_profile = success_profile self.err_profile = err_profile self.detail_profile = detail_profile self.indent = ' ' * indent @@ -454,7 +455,51 @@ class LogLine(Widget): if log_file: click.echo(text, file=log_file, color=False, nl=False) - def format_values(self, values): + # Print queue summaries at the end of a scheduler run + # + def print_summary(self, pipeline, scheduler, log_file, styling=False): + + text = self.content_profile.fmt("Pipeline Summary\n", bold=True) + values = OrderedDict() + values['Total'] = self.content_profile.fmt(str(pipeline.total_elements)) + values['Session'] = self.content_profile.fmt(str(pipeline.session_elements)) + + processed_maxlen = 1 + skipped_maxlen = 1 + failed_maxlen = 1 + for queue in scheduler.queues: + processed_maxlen = max(len(str(len(queue.processed_elements))), processed_maxlen) + skipped_maxlen = max(len(str(len(queue.skipped_elements))), skipped_maxlen) + failed_maxlen = max(len(str(len(queue.failed_elements))), failed_maxlen) + + for queue in scheduler.queues: + processed = str(len(queue.processed_elements)) + skipped = str(len(queue.skipped_elements)) + failed = str(len(queue.failed_elements)) + + processed_align = ' ' * (processed_maxlen - len(processed)) + skipped_align = ' ' * (skipped_maxlen - len(skipped)) + failed_align = ' ' * (failed_maxlen - len(failed)) + + status_text = self.content_profile.fmt("processed ") + \ + self.success_profile.fmt(processed) + \ + self.format_profile.fmt(', ') + processed_align + + status_text += self.content_profile.fmt("skipped ") + \ + self.content_profile.fmt(skipped) + \ + self.format_profile.fmt(', ') + skipped_align + + status_text += self.content_profile.fmt("failed ") + \ + self.err_profile.fmt(failed) + ' ' + failed_align + values["{} Queue".format(queue.action_name)] = status_text + + text += self.format_values(values, style_value=False) + + click.echo(text, color=styling, nl=False) + if log_file: + click.echo(text, file=log_file, color=False, nl=False) + + def format_values(self, values, style_value=True): text = '' max_key_len = 0 for key, value in values.items(): @@ -462,7 +507,10 @@ class LogLine(Widget): for key, value in values.items(): text += self.format_profile.fmt(" {}: {}".format(key, ' ' * (max_key_len - len(key)))) - text += self.content_profile.fmt(str(value)) + if style_value: + text += self.content_profile.fmt(str(value)) + else: + text += str(value) text += '\n' return text |