You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by mr...@apache.org on 2009/07/20 19:13:21 UTC
svn commit: r795960 - /incubator/tashi/trunk/src/tashi/client/tashi-client.py
Author: mryan3
Date: Mon Jul 20 19:13:21 2009
New Revision: 795960
URL: http://svn.apache.org/viewvc?rev=795960&view=rev
Log:
Console width detection, minor cleanups in output
Modified:
incubator/tashi/trunk/src/tashi/client/tashi-client.py
Modified: incubator/tashi/trunk/src/tashi/client/tashi-client.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/client/tashi-client.py?rev=795960&r1=795959&r2=795960&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/tashi-client.py (original)
+++ incubator/tashi/trunk/src/tashi/client/tashi-client.py Mon Jul 20 19:13:21 2009
@@ -347,6 +347,14 @@
return keys
def makeTable(list, keys=None):
+ (consoleWidth, consoleHeight) = (9999, 9999)
+ try:
+ stdout = os.popen("stty size")
+ r = stdout.read()
+ stdout.close()
+ (consoleHeight, consoleWidth) = map(lambda x: int(x.strip()), r.split())
+ except:
+ pass
for obj in list:
transformState(obj)
if (keys == None):
@@ -371,9 +379,19 @@
maxWidth[k] = max(maxWidth[k], len(str(row.__dict__[k])))
if (keys == []):
return
+ totalWidth = reduce(lambda x, y: x + y + 1, maxWidth.values(), 0)
+ while (totalWidth > consoleWidth):
+ widths = maxWidth.items()
+ widths.sort(cmp=lambda x, y: cmp(x[1], y[1]))
+ widths.reverse()
+ maxWidth[widths[0][0]] = widths[0][1]-1
+ totalWidth = reduce(lambda x, y: x + y + 1, maxWidth.values(), 0)
line = ""
for k in keys:
- line += (" %-" + str(maxWidth[k]) + "." + str(maxWidth[k]) + "s") % (k)
+ if (len(str(k)) > maxWidth[k]):
+ line += (" %-" + str(maxWidth[k]-3) + "." + str(maxWidth[k]-3) + "s...") % (k)
+ else:
+ line += (" %-" + str(maxWidth[k]) + "." + str(maxWidth[k]) + "s") % (k)
print line
line = ""
for k in keys:
@@ -393,7 +411,10 @@
line = ""
for k in keys:
row.__dict__[k] = row.__dict__.get(k, "")
- line += (" %-" + str(maxWidth[k]) + "." + str(maxWidth[k]) + "s") % (str(row.__dict__[k]))
+ if (len(str(row.__dict__[k])) > maxWidth[k]):
+ line += (" %-" + str(maxWidth[k]-3) + "." + str(maxWidth[k]-3) + "s...") % (str(row.__dict__[k]))
+ else:
+ line += (" %-" + str(maxWidth[k]) + "." + str(maxWidth[k]) + "s") % (str(row.__dict__[k]))
print line
def simpleType(obj):
@@ -490,6 +511,8 @@
makeTable(res, keys)
else:
pprint(res)
+ except IOError:
+ pass
except Exception, e:
print e
except TashiException, e: