From 3813abcf20fa5451c2df8b1b3f252e6b5a3bf6f4 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Tue, 26 Jun 2012 11:08:24 +0200 Subject: [PATCH] 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 --- keystoneclient/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/keystoneclient/utils.py b/keystoneclient/utils.py index fa2790270..863f03ea6 100644 --- a/keystoneclient/utils.py +++ b/keystoneclient/utils.py @@ -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')