From 91dd5b774d42e35fb8b3d94f65dbfd12f6bed915 Mon Sep 17 00:00:00 2001 From: Ted Ross Date: Wed, 25 Feb 2009 19:41:17 +0000 Subject: Added a new utility for viewing broker stats. Fixed a bug in qpid-cluster that causes failure when username/password are included in the broker URL. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@747897 13f79535-47bb-0310-9956-ffa450edef68 --- python/qpid/disp.py | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'python/qpid') diff --git a/python/qpid/disp.py b/python/qpid/disp.py index e46cb33c60..eb55616f32 100644 --- a/python/qpid/disp.py +++ b/python/qpid/disp.py @@ -24,13 +24,20 @@ from time import strftime, gmtime class Display: """ Display formatting for QPID Management CLI """ - def __init__ (self): - self.tableSpacing = 2 - self.tablePrefix = " " + def __init__ (self, spacing=2, prefix=" "): + self.tableSpacing = spacing + self.tablePrefix = prefix self.timestampFormat = "%X" def table (self, title, heads, rows): """ Print a formatted table with autosized columns """ + + # Pad the rows to the number of heads + for row in rows: + diff = len(heads) - len(row) + for idx in range(diff): + row.append("") + print title if len (rows) == 0: return @@ -77,3 +84,19 @@ class Display: def timestamp (self, nsec): """ Format a nanosecond-since-the-epoch timestamp for printing """ return strftime (self.timestampFormat, gmtime (nsec / 1000000000)) + + def duration(self, nsec): + if nsec < 0: nsec = 0 + sec = nsec / 1000000000 + min = sec / 60 + hour = min / 60 + day = hour / 24 + result = "" + if day > 0: + result = "%dd " % day + if hour > 0 or result != "": + result += "%dh " % (hour % 24) + if min > 0 or result != "": + result += "%dm " % (min % 60) + result += "%ds" % (sec % 60) + return result -- cgit v1.2.1