Author: justi9
Date: 2007-11-06 12:01:35 -0500 (Tue, 06 Nov 2007)
New Revision: 1245
Modified:
mgmt/cumin/python/cumin/client.py
mgmt/cumin/python/cumin/formats.py
mgmt/notes/justin-todo.txt
Log:
Adds a duration formatting function and uses it for session remaining
lifespan.
Modified: mgmt/cumin/python/cumin/client.py
===================================================================
--- mgmt/cumin/python/cumin/client.py 2007-11-06 16:31:53 UTC (rev 1244)
+++ mgmt/cumin/python/cumin/client.py 2007-11-06 17:01:35 UTC (rev 1245)
@@ -140,7 +140,8 @@
return result and "Attached" or "Detached"
def render_item_remaining_lifespan(self, session, session_):
- return session_.get_measurement("remainingLifespan").get_value()
+ value = session_.get_measurement("remainingLifespan").get_value()
+ return fmt_duration(value)
def render_item_frames_outstanding(self, session, session_):
return session_.get_measurement("framesOutstanding").get_value()
Modified: mgmt/cumin/python/cumin/formats.py
===================================================================
--- mgmt/cumin/python/cumin/formats.py 2007-11-06 16:31:53 UTC (rev 1244)
+++ mgmt/cumin/python/cumin/formats.py 2007-11-06 17:01:35 UTC (rev 1245)
@@ -5,6 +5,26 @@
def fmt_datetime(dtime):
return dtime.strftime("%d %b %Y %H:%M")
+# XXX change this to millis or nanos? whatever python wants to give us
+def fmt_duration(secs):
+ """Takes a duration in seconds, which can be a
float"""
+
+ elems = list()
+ periods = (86400, 3600, 60, 1)
+ units = ("day", "hour", "min", "sec")
+
+ for period, unit in zip(periods, units):
+ if secs > period:
+ count = secs // period
+ elems.append("%i %s%s" % (count, unit, ess(count)))
+
+ if len(elems) == 2:
+ return ", ".join(elems)
+
+ secs = secs % period
+
+ return ", ".join(elems)
+
def fmt_rate(value, unit1, unit2):
#return "%i <small>%s/%s</small>" % (value, unit1, unit2)
return "%i<small>/%s</small>" % (value, unit2)
Modified: mgmt/notes/justin-todo.txt
===================================================================
--- mgmt/notes/justin-todo.txt 2007-11-06 16:31:53 UTC (rev 1244)
+++ mgmt/notes/justin-todo.txt 2007-11-06 17:01:35 UTC (rev 1245)
@@ -18,8 +18,6 @@
in the render_title calls. Perhaps introduce a get_title to solve
this.
- * Display the unit for session remaining lifespan
-
* Fix tab order in broker register
Deferred
Show replies by date