From 1d39033c8e6fae42de0f5bff9b00790c6d4c4052 Mon Sep 17 00:00:00 2001 From: liyingjun <yingjun.li@kylin-cloud.com> Date: Wed, 22 Jul 2015 10:01:44 +0800 Subject: [PATCH] Fixes table when there are multiline in result data The table doesn't display right when there are multiple line in result data. Fixes this by replace "\r" with "". Change-Id: Ia3ca4146f17c3ae097a2aad0092c25f6807fcbab Closes-bug: #1476462 --- novaclient/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/novaclient/utils.py b/novaclient/utils.py index 1f4df7a57..ae4894db5 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -97,6 +97,8 @@ def print_list(objs, fields, formatters={}, sortby_index=None): data = getattr(o, field_name, '') if data is None: data = '-' + # '\r' would break the table, so remove it. + data = str(data).replace("\r", "") row.append(data) pt.add_row(row) @@ -163,7 +165,10 @@ def print_dict(d, dict_property="Property", dict_value="Value", wrap=0): v = textwrap.fill(str(v), wrap) # if value has a newline, add in multiple rows # e.g. fault with stacktrace - if v and isinstance(v, six.string_types) and r'\n' in v: + if v and isinstance(v, six.string_types) and (r'\n' in v or '\r' in v): + # '\r' would break the table, so remove it. + if '\r' in v: + v = v.replace('\r', '') lines = v.strip().split(r'\n') col1 = k for line in lines: