From b690cc2ade23960e884082a55e1020eaff45fefa Mon Sep 17 00:00:00 2001 From: Tristan Van Berkom Date: Mon, 1 May 2017 15:41:18 +0900 Subject: widget.py: TimeCode widget support to render without brackets Also fix to CacheKey widget, fix display for elements before pipeline is fully resolved (avoids exceptions thrown in debug mode) --- buildstream/_frontend/widget.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'buildstream/_frontend/widget.py') diff --git a/buildstream/_frontend/widget.py b/buildstream/_frontend/widget.py index 18b094a20..835f1ac78 100644 --- a/buildstream/_frontend/widget.py +++ b/buildstream/_frontend/widget.py @@ -98,6 +98,10 @@ class Debug(Widget): # A widget for rendering the time codes class TimeCode(Widget): + def __init__(self, content_profile, format_profile, brackets=True): + self.brackets = brackets + super(TimeCode, self).__init__(content_profile, format_profile) + def render(self, message): return self.render_time(message.elapsed) @@ -115,9 +119,15 @@ class TimeCode(Widget): for field in [hours, minutes, seconds] ] - return self.format_profile.fmt('[') + \ - self.format_profile.fmt(':').join(fields) + \ - self.format_profile.fmt(']') + text = '' + if self.brackets: + text += self.format_profile.fmt('[') + + text += self.format_profile.fmt(':').join(fields) + if self.brackets: + text += self.format_profile.fmt(']') + + return text # A widget for rendering the action name @@ -202,12 +212,17 @@ class CacheKey(Widget): super(CacheKey, self).__init__(content_profile, format_profile) self.err_profile = err_profile + self.key_length = 0 def size_request(self, pipeline): self.key_length = pipeline.context.log_key_length def render(self, message): + # This can only happen when logging before initialization in debug mode + if not self.key_length: + return self.format_profile.fmt('[') + (' ' * 8) + self.format_profile.fmt(']') + key = ' ' * self.key_length if message.unique_id is not None: plugin = _plugin_lookup(message.unique_id) -- cgit v1.2.1