Sync cliutils from oslo-incubator
Contains two changes: f4b09ce Sort keys in table output in print_dict 0753799 Allow specifying a table header for the value column in print_dict Related to blueprint print-table-archived-rows Change-Id: I176e7ec2727397fa5d6679830a6bfe23455054e9
This commit is contained in:
parent
5135c54d01
commit
58057fe477
@ -186,16 +186,17 @@ def print_list(objs, fields, formatters=None, sortby_index=0,
|
||||
print(encodeutils.safe_encode(pt.get_string(**kwargs)))
|
||||
|
||||
|
||||
def print_dict(dct, dict_property="Property", wrap=0):
|
||||
def print_dict(dct, dict_property="Property", wrap=0, dict_value='Value'):
|
||||
"""Print a `dict` as a table of two columns.
|
||||
|
||||
:param dct: `dict` to print
|
||||
:param dict_property: name of the first column
|
||||
:param wrap: wrapping for the second column
|
||||
:param dict_value: header label for the value (second) column
|
||||
"""
|
||||
pt = prettytable.PrettyTable([dict_property, 'Value'])
|
||||
pt = prettytable.PrettyTable([dict_property, dict_value])
|
||||
pt.align = 'l'
|
||||
for k, v in six.iteritems(dct):
|
||||
for k, v in sorted(dct.items()):
|
||||
# convert dict to str to check length
|
||||
if isinstance(v, dict):
|
||||
v = six.text_type(v)
|
||||
|
Loading…
Reference in New Issue
Block a user