From 4aaba266605512fe92abc501e0117169670e61d0 Mon Sep 17 00:00:00 2001 From: tengqm Date: Wed, 14 Oct 2015 03:03:33 -0400 Subject: [PATCH] Strips off the quotes when showing nested table When showing a nested table, the current formatting logic preserves the quote marks when displaying a JSON or sometimes a string. This patch proposes a change to strip of the quotes so the values are shown in more consistent way. Change-Id: Ib4b6cd0e941afee456469e1ce2986c1dddb5134f --- senlinclient/common/utils.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/senlinclient/common/utils.py b/senlinclient/common/utils.py index eadad7a4..d9c93345 100644 --- a/senlinclient/common/utils.py +++ b/senlinclient/common/utils.py @@ -14,7 +14,6 @@ # under the License. from heatclient.common import template_utils - from oslo_serialization import jsonutils from oslo_utils import importutils import prettytable @@ -54,13 +53,12 @@ def format_nested_dict(d, fields, column_names): for n in column_names: pt.align[n] = 'l' - for field in d.keys(): + keys = sorted(d.keys()) + for field in keys: value = d[field] - if value is six.string_types: - pt.add_row([field, value]) - else: - pt.add_row([field, jsonutils.dumps(value, indent=2, - ensure_ascii=False)]) + if not isinstance(value, six.string_types): + value = jsonutils.dumps(value, indent=2, ensure_ascii=False) + pt.add_row([field, value.strip('"')]) return pt.get_string()