summaryrefslogtreecommitdiff
path: root/python/qpid
diff options
context:
space:
mode:
authorTed Ross <tross@apache.org>2009-02-25 19:41:17 +0000
committerTed Ross <tross@apache.org>2009-02-25 19:41:17 +0000
commit91dd5b774d42e35fb8b3d94f65dbfd12f6bed915 (patch)
treefdcb24b4243c70a99f520dea5506aafff20fda30 /python/qpid
parent4a3e1f228d9fb9e5198d6ef779031c61e6eaaa2c (diff)
downloadqpid-python-91dd5b774d42e35fb8b3d94f65dbfd12f6bed915.tar.gz
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
Diffstat (limited to 'python/qpid')
-rw-r--r--python/qpid/disp.py29
1 files changed, 26 insertions, 3 deletions
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