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
This commit is contained in:
liyingjun 2015-07-22 10:01:44 +08:00
parent 7570a8ab46
commit 1d39033c8e
1 changed files with 6 additions and 1 deletions

View File

@ -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: