Commit 5d342b1f authored by Stratos Psomadakis's avatar Stratos Psomadakis
Browse files

Fix print alignment for snf-mange cmds

pprint_table misbehaved when handling unicode 'strings', breaking the
alignment of the output of several snf-manage cmds, and raising a
unicode encode exception, when printing non 'ascii' unicode strings.

Calculate correctly the max column width by applying len() directly to
the unicode objects, and use the unicode rjust for the output
formatting, and use uenc to encode the output correctly, before
parent 79fd5318
......@@ -49,6 +49,8 @@ from synnefo.settings import (CYCLADES_ASTAKOS_SERVICE_TOKEN as ASTAKOS_TOKEN,
from synnefo.logic.rapi import GanetiApiError, GanetiRapiClient
from synnefo.lib import astakos
from synnefo.util.text import uenc
import logging
log = logging.getLogger(__name__)
......@@ -231,7 +233,7 @@ def pprint_table(out, table, headers=None, separator=None):
table.insert(0, headers)
# Find out the max width of each column
widths = [max(map(len, str(col))) for col in zip(*table)]
widths = [max(map(len, col)) for col in zip(*table)]
t_length = sum(widths) + len(sep) * (len(widths) - 1)
if headers:
......@@ -244,8 +246,8 @@ def pprint_table(out, table, headers=None, separator=None):
# print the rest table
for row in table:
print >> out, sep.join((str(val).rjust(width).encode('utf8')
for val, width in zip(row, widths)))
print >> out, sep.join(uenc(val.rjust(width))
for val, width in zip(row, widths))
class UserCache(object):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment