Do not display None in pretty tables for fields with no value

Fields that are present but unset in a backend (like the email field for
a user created with no email in the KVS backend with the keystone
command line) will appear as "None" when listed, instead of as an empty
field.

Change-Id: I86dc0a204847518e61ba9f6f46d4637d897cfac1
This commit is contained in:
Vincent Untz 2012-06-26 11:08:24 +02:00
parent 44a1ee32e2
commit 3813abcf20

@ -31,6 +31,8 @@ def print_list(objs, fields, formatters={}):
else:
field_name = field.lower().replace(' ', '_')
data = getattr(o, field_name, '')
if data is None:
data = ''
row.append(data)
pt.add_row(row)
@ -40,7 +42,10 @@ def print_list(objs, fields, formatters={}):
def print_dict(d):
pt = prettytable.PrettyTable(['Property', 'Value'], caching=False)
pt.aligns = ['l', 'l']
[pt.add_row(list(r)) for r in d.iteritems()]
for (prop, value) in d.iteritems():
if value is None:
value = ''
pt.add_row((prop, value))
print pt.get_string(sortby='Property')