Author: justi9
Date: 2007-11-05 13:15:43 -0500 (Mon, 05 Nov 2007)
New Revision: 1235
Modified:
mgmt/cumin/python/cumin/broker.py
mgmt/cumin/python/cumin/brokercluster.py
mgmt/cumin/python/cumin/brokergroup.py
mgmt/cumin/python/cumin/brokerprofile.py
mgmt/cumin/python/cumin/client.py
mgmt/cumin/python/cumin/exchange.py
mgmt/cumin/python/cumin/measurement.py
mgmt/cumin/python/cumin/queue.py
mgmt/cumin/python/cumin/virtualhost.py
mgmt/cumin/python/cumin/widgets.py
Log:
Refactors format functions. Adds a formats.py
Modified: mgmt/cumin/python/cumin/broker.py
===================================================================
--- mgmt/cumin/python/cumin/broker.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/broker.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -1,5 +1,6 @@
from wooly import *
from wooly.widgets import *
+from random import random
from configproperty import *
from virtualhost import *
@@ -8,8 +9,8 @@
from client import *
from widgets import *
from parameters import *
+from formats import *
from util import *
-from random import random
strings = StringCatalog(__file__)
@@ -23,7 +24,7 @@
def render_item_link(self, session, broker):
branch = session.branch()
self.page().show_broker(branch, broker).show_view(branch)
- return mlink(branch.marshal(), "Broker", broker.name)
+ return fmt_olink(branch, broker)
def render_item_group_link(self, session, broker):
group = broker.get_broker_group()
@@ -31,9 +32,9 @@
if group:
branch = session.branch()
self.page().show_broker_group(branch, group).show_view(branch)
- return mlink(branch.marshal(), "BrokerGroup", group.name)
+ return fmt_olink(branch, group)
else:
- return none()
+ return fmt_none()
def render_item_profile_link(self, session, broker):
profile = broker.get_broker_profile()
@@ -41,9 +42,9 @@
if profile:
branch = session.branch()
self.page().show_broker_profile(branch, profile).show_view(branch)
- return mlink(branch.marshal(), "BrokerProfile", profile.name)
+ return fmt_olink(branch, profile)
else:
- return none()
+ return fmt_none()
def render_item_cluster_link(self, session, broker):
cluster = broker.get_broker_cluster()
@@ -51,12 +52,12 @@
if cluster:
branch = session.branch()
self.page().show_broker_cluster(branch, cluster).show_view(branch)
- return mlink(branch.marshal(), "Cluster", cluster.name)
+ return fmt_olink(branch, cluster)
else:
- return none()
+ return fmt_none()
def render_item_status(self, session, broker):
- return status(len(broker.errors), len(broker.warnings))
+ return fmt_status(len(broker.errors), len(broker.warnings))
def render_item_load(self, session, broker):
return "%.2f" % random()
@@ -259,9 +260,9 @@
if cluster:
branch = session.branch()
self.page().show_broker_cluster(branch, cluster).show_view(branch)
- return mlink(branch.marshal(), "Cluster", cluster.name)
+ return fmt_olink(branch, cluster)
else:
- return none()
+ return fmt_none()
def render_profile_link(self, session, broker):
profile = broker.get_broker_profile()
@@ -269,9 +270,9 @@
if profile:
branch = session.branch()
self.page().show_broker_profile(branch, profile).show_view(branch)
- return mlink(branch.marshal(), "BrokerProfile", profile.name)
+ return fmt_olink(branch, profile)
else:
- return none()
+ return fmt_none()
def render_version(self, session, broker):
return "1.0"
@@ -391,7 +392,7 @@
return brokers
def render_none(self, session, model):
- return none()
+ return fmt_none()
def render_clear_filters_href(self, session, model):
branch = session.branch()
@@ -440,4 +441,4 @@
class_ = param.get(session) is object and "selected"
- return link(href, name, class_)
+ return fmt_link(href, name, class_)
Modified: mgmt/cumin/python/cumin/brokercluster.py
===================================================================
--- mgmt/cumin/python/cumin/brokercluster.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/brokercluster.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -6,6 +6,7 @@
from broker import *
from widgets import *
from parameters import *
+from formats import *
from util import *
strings = StringCatalog(__file__)
@@ -25,7 +26,7 @@
def render_item_link(self, session, cluster):
branch = session.branch()
self.page().show_broker_cluster(branch, cluster).show_view(branch)
- return mlink(branch.marshal(), "BrokerCluster", cluster.name)
+ return fmt_olink(branch, cluster)
def render_item_config(self, session, cluster):
count = len(cluster.broker_items())
@@ -35,7 +36,7 @@
writer = Writer()
for broker in sorted_by(cluster.broker_items()):
- writer.write(status(len(broker.errors), len(broker.warnings)))
+ writer.write(fmt_status(len(broker.errors), len(broker.warnings)))
return writer.to_string()
Modified: mgmt/cumin/python/cumin/brokergroup.py
===================================================================
--- mgmt/cumin/python/cumin/brokergroup.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/brokergroup.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -5,6 +5,7 @@
from model import *
from widgets import *
from parameters import *
+from formats import *
from util import *
strings = StringCatalog(__file__)
@@ -24,7 +25,7 @@
def render_item_link(self, session, group):
branch = session.branch()
self.page().show_broker_group(branch, group).show_view(branch)
- return mlink(branch.marshal(), "BrokerGroup", group.name)
+ return fmt_olink(branch, group)
def render_item_config(self, session, group):
count = len(group.broker_items())
@@ -34,12 +35,12 @@
writer = Writer()
for broker in sorted_by(group.broker_items()):
- writer.write(status(len(broker.errors), len(broker.warnings)))
+ writer.write(fmt_status(len(broker.errors), len(broker.warnings)))
return writer.to_string()
def render_none(self, session, group):
- return none()
+ return fmt_none()
class BrokerGroupFrame(CuminFrame):
def __init__(self, app, name):
Modified: mgmt/cumin/python/cumin/brokerprofile.py
===================================================================
--- mgmt/cumin/python/cumin/brokerprofile.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/brokerprofile.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -16,7 +16,7 @@
def render_item_link(self, session, profile):
branch = session.branch()
self.page().show_broker_profile(branch, profile).show_view(branch)
- return mlink(branch.marshal(), "BrokerProfile", profile.name)
+ return fmt_olink(branch, profile)
class BrokerProfileFrame(CuminFrame):
def __init__(self, app, name):
Modified: mgmt/cumin/python/cumin/client.py
===================================================================
--- mgmt/cumin/python/cumin/client.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/client.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -4,6 +4,7 @@
from measurement import *
from widgets import *
from parameters import *
+from formats import *
from util import *
strings = StringCatalog(__file__)
@@ -18,10 +19,10 @@
def render_item_link(self, session, client):
branch = session.branch()
self.page().show_client(branch, client).show_view(branch)
- return mlink(branch.marshal(), "Client", client.address)
+ return fmt_olink(branch, client.address)
def render_item_status(self, session, client):
- return status(len(client.errors), len(client.warnings))
+ return fmt_status(len(client.errors), len(client.warnings))
def render_item_messages_produced(self, session, client):
return client.get_measurement("msgsProduced").get_value()
Modified: mgmt/cumin/python/cumin/exchange.py
===================================================================
--- mgmt/cumin/python/cumin/exchange.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/exchange.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -7,6 +7,7 @@
from model import *
from widgets import *
from parameters import *
+from formats import *
from util import *
strings = StringCatalog(__file__)
@@ -50,7 +51,7 @@
def render_item_link(self, session, exchange):
branch = session.branch()
self.page().show_exchange(branch, exchange).show_view(branch)
- return mlink(branch.marshal(), "Exchange", exchange.name)
+ return fmt_olink(branch, exchange)
def render_item_producers(self, session, exchange):
return len(exchange.producer_items())
@@ -74,7 +75,7 @@
return exchange.get_measurement(key).get_value()
def render_item_status(self, session, exchange):
- return status(len(exchange.errors), len(exchange.warnings))
+ return fmt_status(len(exchange.errors), len(exchange.warnings))
def show_producers(page, session, exchange):
frame = page.show_exchange(session, exchange).show_view(session)
Modified: mgmt/cumin/python/cumin/measurement.py
===================================================================
--- mgmt/cumin/python/cumin/measurement.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/measurement.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -4,6 +4,7 @@
from widgets import *
from parameters import *
from util import *
+from formats import *
strings = StringCatalog(__file__)
@@ -38,7 +39,7 @@
if measure.link_cb:
branch = session.branch()
measure.link_cb(self.page(), branch, self.object.get(session))
- return link(branch.marshal(), measure.get_value())
+ return fmt_link(branch.marshal(), measure.get_value())
else:
return measure.get_value()
@@ -48,7 +49,7 @@
% (measure.get_high() or 0, measure.get_low() or 0)
else:
unit = self.unit_abbrevs.get(measure.unit, measure.unit)
- return rate(measure.get_rate(), unit, "sec")
+ return fmt_rate(measure.get_rate(), unit, "sec")
def render_item_average(self, session, measure):
return "%0.2f" % (sum(measure.values) / float(len(measure.values)))
Modified: mgmt/cumin/python/cumin/queue.py
===================================================================
--- mgmt/cumin/python/cumin/queue.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/queue.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -8,6 +8,7 @@
from measurement import *
from widgets import *
from parameters import *
+from formats import *
from util import *
strings = StringCatalog(__file__)
@@ -34,7 +35,7 @@
def render_item_link(self, session, queue):
branch = session.branch()
self.page().show_queue(branch, queue).show_view(branch)
- return mlink(branch.marshal(), "Queue", queue.name)
+ return fmt_olink(branch, queue)
def render_item_name(self, session, queue):
return queue.name
@@ -49,13 +50,13 @@
unit = self.unit.get(session)
key = unit == "b" and "byteTotalEnqueues" or
"msgTotalEnqueues"
value = queue.get_measurement(key).get_rate()
- return rate(value, unit == "b" and "byte" or "msg",
"sec")
+ return fmt_rate(value, unit == "b" and "byte" or
"msg", "sec")
def render_item_dequeued(self, session, queue):
unit = self.unit.get(session)
key = unit == "b" and "byteTotalDequeues" or
"msgTotalDequeues"
value = queue.get_measurement(key).get_rate()
- return rate(value, unit == "b" and "byte" or "msg",
"sec")
+ return fmt_rate(value, unit == "b" and "byte" or
"msg", "sec")
def render_item_depth(self, session, queue):
key = self.unit.get(session) == "b" and "byteDepth" or
"msgDepth"
@@ -65,10 +66,10 @@
unit = self.unit.get(session)
key = unit == "b" and "byteDepth" or "msgDepth"
value = queue.get_measurement(key).get_rate()
- return rate(value, unit == "b" and "byte" or "msg",
"sec")
+ return fmt_rate(value, unit == "b" and "byte" or
"msg", "sec")
def render_item_status(self, session, queue):
- return status(len(queue.errors), len(queue.warnings))
+ return fmt_status(len(queue.errors), len(queue.warnings))
def show_consumers(page, session, queue):
frame = page.show_queue(session, queue).show_view(session)
@@ -109,33 +110,33 @@
def render_message_enqueues(self, session, queue):
value = queue.get_measurement("msgTotalEnqueues").get_rate()
- return rate(value, "msg", "sec")
+ return fmt_rate(value, "msg", "sec")
def render_message_dequeues(self, session, queue):
value = queue.get_measurement("msgTotalDequeues").get_rate()
- return rate(value, "msg", "sec")
+ return fmt_rate(value, "msg", "sec")
def render_message_depth(self, session, queue):
return queue.get_measurement("msgDepth").get_value()
def render_message_depth_accel(self, session, queue):
value = queue.get_measurement("msgDepth").get_rate()
- return rate(value, "msg", "sec")
+ return fmt_rate(value, "msg", "sec")
def render_byte_enqueues(self, session, queue):
value = queue.get_measurement("byteTotalEnqueues").get_rate()
- return rate(value, "byte", "sec")
+ return fmt_rate(value, "byte", "sec")
def render_byte_dequeues(self, session, queue):
value = queue.get_measurement("byteTotalDequeues").get_rate()
- return rate(value, "byte", "sec")
+ return fmt_rate(value, "byte", "sec")
def render_byte_depth(self, session, queue):
return queue.get_measurement("byteDepth").get_value()
def render_byte_depth_accel(self, session, queue):
value = queue.get_measurement("byteDepth").get_rate()
- return rate(value, "byte", "sec")
+ return fmt_rate(value, "byte", "sec")
class QueueView(Widget):
def __init__(self, app, name):
@@ -168,10 +169,10 @@
return queue.name
def render_durable(self, session, queue):
- return yes_no(queue.is_durable)
+ return fmt_predicate(queue.is_durable)
def render_exclusive(self, session, queue):
- return yes_no(queue.is_exclusive)
+ return fmt_predicate(queue.is_exclusive)
def render_created_deleted(self, session, queue):
return "%s - %s" % (fmt_datetime(datetime.utcnow()), "")
Modified: mgmt/cumin/python/cumin/virtualhost.py
===================================================================
--- mgmt/cumin/python/cumin/virtualhost.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/virtualhost.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -6,6 +6,7 @@
from client import *
from widgets import *
from parameters import *
+from formats import *
from util import *
strings = StringCatalog(__file__)
@@ -20,7 +21,7 @@
def render_item_link(self, session, vhost):
branch = session.branch()
self.page().show_virtual_host(branch, vhost).show_view(branch)
- return mlink(branch.marshal(), "VirtualHost", vhost.name)
+ return fmt_olink(branch, vhost)
class VirtualHostFrame(CuminFrame):
def __init__(self, app, name):
@@ -81,9 +82,9 @@
if broker:
branch = session.branch()
self.page().show_broker(branch, broker).show_view(branch)
- return mlink(branch.marshal(), "Broker", broker.name)
+ return fmt_olink(branch, broker)
else:
- return none()
+ return fmt_none()
def render_cluster_link(self, session, vhost):
cluster = vhost.get_broker_cluster()
@@ -91,6 +92,6 @@
if cluster:
branch = session.branch()
self.page().show_broker_cluster(branch, cluster).show_view(branch)
- return mlink(branch.marshal(), "Cluster", cluster.name)
+ return fmt_olink(branch, cluster)
else:
- return none()
+ return fmt_none()
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2007-11-05 17:41:37 UTC (rev 1234)
+++ mgmt/cumin/python/cumin/widgets.py 2007-11-05 18:15:43 UTC (rev 1235)
@@ -1,53 +1,13 @@
from wooly import *
from wooly.widgets import *
from wooly.forms import *
-from datetime import datetime
-from util import *
from charts import *
+from formats import *
+from util import *
strings = StringCatalog(__file__)
-def link(href, content, class_=""):
- return "<a%shref=\"%s\">%s</a>" % \
- (class_ and " class=\"%s\" " % class_ or " ",
href, content)
-
-def mlink(href, variety, name, selected=False):
- return link(href, name, selected and "selected")
-
-def none():
- return "<span class=\"none\">None</span>"
-
-def status(errors, warnings, active=True):
- count = errors + warnings
-
- if count == 0:
- number = " "
- elif count > 9:
- number = "+"
- else:
- number = str(count)
-
- if active:
- if count == 0:
- class_ = "green"
- else:
- class_ = errors and "red" or "yellow"
- else:
- class_ = "inactive"
-
- return "<div class=\"statuslight %s\">%s</div>" %
(class_, number)
-
-def yes_no(predicate):
- return predicate and "Yes" or "No"
-
-def rate(value, unit1, unit2):
- #return "%i <small>%s/%s</small>" % (value, unit1, unit2)
- return "%i<small>/%s</small>" % (value, unit2)
-
-def fmt_datetime(dtime):
- return dtime.strftime("%d %b %Y %H:%M")
-
class CuminFrame(Frame, ModeSet):
def __init__(self, app, name):
super(CuminFrame, self).__init__(app, name)
@@ -232,7 +192,7 @@
class_ = self.get(session) == "m" and "selected"
- return link(branch.marshal(), "Messages", class_)
+ return fmt_link(branch.marshal(), "Messages", class_)
def render_bytes_link(self, session, vhost):
branch = session.branch()
@@ -240,4 +200,4 @@
class_ = self.get(session) == "b" and "selected"
- return link(branch.marshal(), "Bytes", class_)
+ return fmt_link(branch.marshal(), "Bytes", class_)