summaryrefslogtreecommitdiff
path: root/src/buildstream/_frontend/widget.py
diff options
context:
space:
mode:
authorRebecca Grayson <becky.grayson1@hotmail.co.uk>2019-08-08 10:48:52 +0100
committerRebecca Grayson <becky.grayson1@hotmail.co.uk>2019-08-16 11:52:25 +0100
commit6a5529504db7e28c7af12ddf28d5ac9200334eee (patch)
tree9ce233aace35db5bc71e4e30a18947195fbda297 /src/buildstream/_frontend/widget.py
parent2d670f1963f83ffbf146e90500b517e77b24db62 (diff)
downloadbuildstream-becky/artifact_list_contents.tar.gz
Addition of bst artifact list-contents:becky/artifact_list_contents
this commit introduces the bst artifact list-contents command. When used it provides the user with a list of the contents within the artifact. Tests and a NEWS entry have also been added for the command.
Diffstat (limited to 'src/buildstream/_frontend/widget.py')
-rw-r--r--src/buildstream/_frontend/widget.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/buildstream/_frontend/widget.py b/src/buildstream/_frontend/widget.py
index fbde249a9..b0472bd45 100644
--- a/src/buildstream/_frontend/widget.py
+++ b/src/buildstream/_frontend/widget.py
@@ -801,3 +801,39 @@ class LogLine(Widget):
text += '\n'
return text
+
+ # _pretty_print_dictionary()
+ #
+ # Formats a dictionary so it can be easily read by the user
+ #
+ # Args:
+ # values: A dictionary
+ # style_value: Whether to use the content profile for the values
+ #
+ # Returns:
+ # (str): The formatted values
+ #
+ def _pretty_print_dictionary(self, values, style_value=True):
+ text = ''
+ max_key_len = 0
+ for key, value in values.items():
+ max_key_len = max(len(key), max_key_len)
+
+ for key, value in values.items():
+ if isinstance(value, str) and '\n' in value:
+ text += self.format_profile.fmt(" {}:".format(key))
+ text += textwrap.indent(value, self._indent)
+ continue
+
+ text += self.format_profile.fmt(" {}:{}".format(key, ' ' * (max_key_len - len(key))))
+
+ value_list = ''
+ for item in value:
+ value_list += "\n\t{}".format(item)
+ if style_value:
+ text += self.content_profile.fmt(value_list)
+ else:
+ text += value_list
+ text += '\n'
+
+ return text