diff options
Diffstat (limited to 'python/qpid/disp.py')
| -rw-r--r-- | python/qpid/disp.py | 29 |
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 |
