Sync with oslo-incubator

As noted in the email below, the oslo-incubator code is going away.
This is expected to be a last sync from that repo. We will need to
figure out how this code should be maintained in our repo later.

http://lists.openstack.org/pipermail/openstack-dev/2015-November/079343.html

Change-Id: I6da40c4035895f0d47f5e482c11ec01fedc4f23e
This commit is contained in:
tengqm
2015-11-14 23:28:43 -05:00
parent f6935eacc7
commit f15c450f5d

View File

@@ -140,7 +140,7 @@ def isunauthenticated(func):
def print_list(objs, fields, formatters=None, sortby_index=0,
mixed_case_fields=None, field_labels=None):
"""Print a list or objects as a table, one row per object.
"""Print a list of objects as a table, one row per object.
:param objs: iterable of :class:`Resource`
:param fields: attributes that correspond to columns, in order
@@ -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)