[rhmessaging-commits] rhmessaging commits: r3804 - in mgmt/trunk: cumin/python/cumin and 4 other directories.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Fri Jan 15 14:57:38 EST 2010
Author: justi9
Date: 2010-01-15 14:57:37 -0500 (Fri, 15 Jan 2010)
New Revision: 3804
Added:
mgmt/trunk/wooly/python/wooly/template.py
Modified:
mgmt/trunk/basil/python/basil/widgets.py
mgmt/trunk/cumin/python/cumin/grid/job.py
mgmt/trunk/cumin/python/cumin/grid/negotiator.py
mgmt/trunk/cumin/python/cumin/grid/slot.py
mgmt/trunk/cumin/python/cumin/messaging/binding.py
mgmt/trunk/cumin/python/cumin/messaging/broker.py
mgmt/trunk/cumin/python/cumin/messaging/queue.py
mgmt/trunk/cumin/python/cumin/stat.py
mgmt/trunk/cumin/python/cumin/widgets.py
mgmt/trunk/misc/boneyard.py
mgmt/trunk/wooly/python/wooly/__init__.py
mgmt/trunk/wooly/python/wooly/pages.py
mgmt/trunk/wooly/python/wooly/sql.py
mgmt/trunk/wooly/python/wooly/tables.py
mgmt/trunk/wooly/python/wooly/widgets.py
Log:
Move template code to its own module, and get rid of a legacy template class
Modified: mgmt/trunk/basil/python/basil/widgets.py
===================================================================
--- mgmt/trunk/basil/python/basil/widgets.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/basil/python/basil/widgets.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -69,7 +69,7 @@
self.start.default = 0
self.add_parameter(self.start)
- self.column_tmpl = Template(self, "column_html")
+ self.column_tmpl = WidgetTemplate(self, "column_html")
def render_back_href(self, session):
branch = session.branch()
Modified: mgmt/trunk/cumin/python/cumin/grid/job.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/job.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/grid/job.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -521,7 +521,7 @@
self.job = job
- self.group_tmpl = Template(self, "group_html")
+ self.group_tmpl = WidgetTemplate(self, "group_html")
def render_groups(self, session):
job = self.job.get(session)
Modified: mgmt/trunk/cumin/python/cumin/grid/negotiator.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/negotiator.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/grid/negotiator.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -505,7 +505,7 @@
def __init__(self, app, name, task):
super(EditPrioFactorForm, self).__init__(app, name, task)
- self.field_tmpl = Template(self, "field_html")
+ self.field_tmpl = WidgetTemplate(self, "field_html")
factor = Parameter(app, "factor")
self.add_parameter(factor)
@@ -606,8 +606,8 @@
def __init__(self, app, name, task):
super(EditDynamicQuotaForm, self).__init__(app, name, task)
- self.field_tmpl = Template(self, "field_html")
- self.unclaimed_tmpl = Template(self, "unclaimed_html")
+ self.field_tmpl = WidgetTemplate(self, "field_html")
+ self.unclaimed_tmpl = WidgetTemplate(self, "unclaimed_html")
quota = Parameter(app, "quota")
self.add_parameter(quota)
@@ -692,7 +692,7 @@
def __init__(self, app, name, task):
super(EditStaticQuotaForm, self).__init__(app, name, task)
- self.field_tmpl = Template(self, "field_html")
+ self.field_tmpl = WidgetTemplate(self, "field_html")
quota = Parameter(app, "quota")
self.add_parameter(quota)
@@ -749,7 +749,7 @@
def __init__(self, app, name, task):
super(EditRegroupForm, self).__init__(app, name, task)
- self.field_tmpl = Template(self, "field_html")
+ self.field_tmpl = WidgetTemplate(self, "field_html")
self.regroup = DictParameter(app, "regroup")
self.add_parameter(self.regroup)
Modified: mgmt/trunk/cumin/python/cumin/grid/slot.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/slot.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/grid/slot.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -387,7 +387,7 @@
self.slot = Attribute(app, "slot")
self.add_attribute(self.slot)
- self.info_div_tmpl = Template(self, "bg_html")
+ self.info_div_tmpl = WidgetTemplate(self, "bg_html")
def do_render(self, session):
index = self.index.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/binding.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/binding.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/messaging/binding.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -1,6 +1,6 @@
import logging
-from wooly import Template, Writer, Attribute, Parameter, Widget
+from wooly import WidgetTemplate, Writer, Attribute, Parameter, Widget
from wooly.forms import FormInput, FormField, Form
from wooly.parameters import DictParameter
from wooly.resources import StringCatalog
@@ -100,8 +100,8 @@
self.exchange = None
self.instance_data = None
- self.name_tmpl = Template(self, "name_html")
- self.key_tmpl = Template(self, "key_html")
+ self.name_tmpl = WidgetTemplate(self, "name_html")
+ self.key_tmpl = WidgetTemplate(self, "key_html")
self.form = None
Modified: mgmt/trunk/cumin/python/cumin/messaging/broker.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/broker.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/messaging/broker.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -280,7 +280,7 @@
def __init__(self, app, name):
super(BrokerBrowser, self).__init__(app, name)
- self.group_tmpl = Template(self, "group_html")
+ self.group_tmpl = WidgetTemplate(self, "group_html")
self.brokers = BrokerSet(app, "brokers")
self.add_child(self.brokers)
Modified: mgmt/trunk/cumin/python/cumin/messaging/queue.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -568,7 +568,7 @@
self.sum_props = self.SummaryProperties(app, "properties", queue)
self.add_child(self.sum_props)
- self.prop_tmpl = Template(self, "properties_html")
+ self.prop_tmpl = WidgetTemplate(self, "properties_html")
class SummaryProperties(CuminProperties):
def do_get_items(self, session):
Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/stat.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -119,7 +119,7 @@
self.stats = ()
self.chart_type = None
- self.stats_tmpl = Template(self, "stat_html")
+ self.stats_tmpl = WidgetTemplate(self, "stat_html")
self.duration = JSDurationSwitch(app, "duration")
self.add_child(self.duration)
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -197,7 +197,7 @@
summary = CuminSummary(app, "summary", self.object)
self.add_child(summary)
- self.__frame_tmpl = Template(self, "frame_html")
+ self.__frame_tmpl = WidgetTemplate(self, "frame_html")
self.sticky_frame = None
def render_script(self, session):
@@ -322,12 +322,12 @@
def __init__(self, widget, template_key):
super(EditablePropertyRenderer, self).__init__(widget, template_key)
- self.__bool_template = Template(self, "bool_html")
- self.__string_template = Template(self, "string_html")
- self.__bigstring_template = Template(self, "bigstring_html")
- self.__number_template = Template(self, "number_html")
- self.__readonly_template = Template(self, "readonly_html")
- self.__orig_template = Template(self, "orig_html")
+ self.__bool_template = WidgetTemplate(self, "bool_html")
+ self.__string_template = WidgetTemplate(self, "string_html")
+ self.__bigstring_template = WidgetTemplate(self, "bigstring_html")
+ self.__number_template = WidgetTemplate(self, "number_html")
+ self.__readonly_template = WidgetTemplate(self, "readonly_html")
+ self.__orig_template = WidgetTemplate(self, "orig_html")
def render_title(self, session, item):
title = item["name"]
Modified: mgmt/trunk/misc/boneyard.py
===================================================================
--- mgmt/trunk/misc/boneyard.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/misc/boneyard.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -53,8 +53,8 @@
def __init__(self, app, name):
super(ServerBrowser.BrowserGroups, self).__init__(app, name)
- self.type_tmpl = Template(self, "type_html")
- self.group_tmpl = Template(self, "group_html")
+ self.type_tmpl = WidgetTemplate(self, "type_html")
+ self.group_tmpl = WidgetTemplate(self, "group_html")
def get_items(self, session, model):
return sorted_by(model.get_server_group_types())
Modified: mgmt/trunk/wooly/python/wooly/__init__.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/__init__.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/__init__.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -1,7 +1,3 @@
-import logging
-import os
-import sys
-
from parsley.threadingex import Lifecycle
from cStringIO import StringIO
from urllib import quote, unquote_plus, unquote
@@ -11,39 +7,12 @@
from wooly.profile import *
from resources import ResourceFinder, StringCatalog
+from template import *
from util import *
log = logging.getLogger("wooly")
strings = StringCatalog(__file__)
-class SessionAttribute(object):
- def __init__(self, object, name):
- self.object = object
- self.name = name
- self.default = None
-
- self.key = (self.object, self.name)
-
- def get_default(self, session):
- return copy(self.default)
-
- def get(self, session):
- value = session.get(self.key)
-
- if value is None:
- value = self.get_default(session)
-
- if value is not None:
- self.set(session, value)
-
- return value
-
- def add(self, session, value):
- self.set(session, value)
-
- def set(self, session, value):
- session.set(self.key, value)
-
# XXX make this more definitely WidgetAttribute
class Attribute(object):
def __init__(self, app, name):
@@ -155,8 +124,8 @@
self.page = None
self.frame = None
- self.__main_tmpl = Template(self, "html")
- self.__defer_tmpl = Template(self, "deferred_html")
+ self.__main_tmpl = WidgetTemplate(self, "html")
+ self.__defer_tmpl = WidgetTemplate(self, "deferred_html")
def init(self):
log.debug("Initializing %s" % self)
@@ -695,7 +664,8 @@
self.attributes = dict()
-class StringIOWriter(object):
+
+class Writer(object):
def __init__(self):
self.writer = StringIO()
@@ -709,137 +679,4 @@
return string
-class ListWriter(object):
- def __init__(self):
- self.strings = list()
-
- def write(self, string):
- self.strings.append(string)
-
- def to_string(self):
- return "".join(self.strings)
-
-class Writer(StringIOWriter):
- pass
-
-class ObjectTemplate(object):
- def __init__(self, obj, text):
- self.__object = obj
- self.__text = text
- self.__fragments = None
-
- def compile(self):
- return self.resolve(self.parse(self.__text))
-
- def parse(self, text):
- strings = list()
-
- start = 0
- end = text.find("{")
-
- while True:
- if (end == -1):
- strings.append(text[start:])
- break
-
- strings.append(text[start:end])
-
- ccurly = text.find("}", end + 1)
-
- if ccurly == -1:
- start = end
- end = -1
- else:
- ocurly = text.find("{", end + 1)
-
- if ocurly == -1:
- start = end
- end = ccurly + 1
- elif ocurly < ccurly:
- start = end
- end = ocurly
- else:
- strings.append("{" + text[end + 1:ccurly] + "}")
-
- start = ccurly + 1
- end = ocurly
-
- return strings
-
- def resolve(self, strings):
- fragments = list()
-
- for string in strings:
- if string.startswith("{") and string.endswith("}"):
- name = string[1:-1]
- method = self.find_method("render_" + name)
-
- if method:
- fragments.append(method)
- else:
- child = self.find_child(name)
-
- if child:
- fragments.append(child)
- else:
- fragments.append(string)
- else:
- fragments.append(string)
-
- return fragments
-
- def find_method(self, name):
- for cls in self.__object.__class__.__mro__:
- meth = getattr(cls, name, None)
-
- if meth and callable(meth):
- return meth
-
- def find_child(self, name):
- return None
-
- def render(self, writer, session, *args):
- # XXX do this in an init method instead
- if not self.__fragments:
- self.__fragments = self.compile()
-
- for frag in self.__fragments:
- if type(frag) is str:
- writer.write(frag)
- elif callable(frag):
- #print "tc", frag, args
-
- result = frag(self.__object, session, *args)
-
- if result is not None:
- writer.write(str(result))
- else:
- result = frag.render(session)
-
- if result is not None:
- writer.write(str(result))
-
- def __repr__(self):
- name = self.__object.__class__.__name__ + "." + self.key
- return "%s('%s')" % (self.__class__.__name__, name)
-
-class WidgetTemplate(ObjectTemplate):
- def __init__(self, widget, key):
- text = widget.get_string(key)
-
- if not text:
- raise Exception("Template '%s.%s' not found" \
- % (widget.__class__.__name__, key))
-
- super(WidgetTemplate, self).__init__(widget, text)
-
- self.widget = widget
-
- def find_child(self, name):
- return self.widget.children_by_name.get(name)
-
-# XXX eliminate this leftover alias
-class Template(WidgetTemplate):
- pass
-
from pages import ResourcePage
Modified: mgmt/trunk/wooly/python/wooly/pages.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/pages.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/pages.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -174,7 +174,7 @@
def __init__(self, app, name, html_page):
super(UpdatePage, self).__init__(app, name)
- self.widget_tmpl = Template(self, "widget_html")
+ self.widget_tmpl = WidgetTemplate(self, "widget_html")
self.html_page = html_page
Modified: mgmt/trunk/wooly/python/wooly/sql.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/sql.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/sql.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -1,10 +1,38 @@
-import logging
+from resources import *
+from template import *
+from util import *
-from wooly import *
-
strings = StringCatalog(__file__)
log = logging.getLogger("wooly.sql")
+class SessionAttribute(object):
+ def __init__(self, object, name):
+ self.object = object
+ self.name = name
+ self.default = None
+
+ self.key = (self.object, self.name)
+
+ def get_default(self, session):
+ return copy(self.default)
+
+ def get(self, session):
+ value = session.get(self.key)
+
+ if value is None:
+ value = self.get_default(session)
+
+ if value is not None:
+ self.set(session, value)
+
+ return value
+
+ def add(self, session, value):
+ self.set(session, value)
+
+ def set(self, session, value):
+ session.set(self.key, value)
+
class SqlOperation(object):
def __init__(self, app):
super(SqlOperation, self).__init__()
Modified: mgmt/trunk/wooly/python/wooly/tables.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/tables.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/tables.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -207,9 +207,9 @@
def __init__(self, app, name):
super(SqlTable, self).__init__(app, name)
- self.__sql_tmpl = Template(self, "sql")
- self.__count_sql_tmpl = Template(self, "count_sql")
- self.__find_sql_tmpl = Template(self, "find_sql")
+ self.__sql_tmpl = WidgetTemplate(self, "sql")
+ self.__count_sql_tmpl = WidgetTemplate(self, "count_sql")
+ self.__find_sql_tmpl = WidgetTemplate(self, "find_sql")
def render_sql(self, session, *args):
writer = Writer()
Added: mgmt/trunk/wooly/python/wooly/template.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/template.py (rev 0)
+++ mgmt/trunk/wooly/python/wooly/template.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -0,0 +1,117 @@
+from util import *
+
+class ObjectTemplate(object):
+ def __init__(self, obj, text):
+ self.__object = obj
+ self.__text = text
+ self.__fragments = None
+
+ def compile(self):
+ return self.resolve(self.parse(self.__text))
+
+ def parse(self, text):
+ strings = list()
+
+ start = 0
+ end = text.find("{")
+
+ while True:
+ if (end == -1):
+ strings.append(text[start:])
+ break
+
+ strings.append(text[start:end])
+
+ ccurly = text.find("}", end + 1)
+
+ if ccurly == -1:
+ start = end
+ end = -1
+ else:
+ ocurly = text.find("{", end + 1)
+
+ if ocurly == -1:
+ start = end
+ end = ccurly + 1
+ elif ocurly < ccurly:
+ start = end
+ end = ocurly
+ else:
+ strings.append("{" + text[end + 1:ccurly] + "}")
+
+ start = ccurly + 1
+ end = ocurly
+
+ return strings
+
+ def resolve(self, strings):
+ fragments = list()
+
+ for string in strings:
+ if string.startswith("{") and string.endswith("}"):
+ name = string[1:-1]
+ method = self.find_method("render_" + name)
+
+ if method:
+ fragments.append(method)
+ else:
+ child = self.find_child(name)
+
+ if child:
+ fragments.append(child)
+ else:
+ fragments.append(string)
+ else:
+ fragments.append(string)
+
+ return fragments
+
+ def find_method(self, name):
+ for cls in self.__object.__class__.__mro__:
+ meth = getattr(cls, name, None)
+
+ if meth and callable(meth):
+ return meth
+
+ def find_child(self, name):
+ return None
+
+ def render(self, writer, session, *args):
+ # XXX do this in an init method instead
+ if not self.__fragments:
+ self.__fragments = self.compile()
+
+ for frag in self.__fragments:
+ if type(frag) is str:
+ writer.write(frag)
+ elif callable(frag):
+ #print "tc", frag, args
+
+ result = frag(self.__object, session, *args)
+
+ if result is not None:
+ writer.write(str(result))
+ else:
+ result = frag.render(session)
+
+ if result is not None:
+ writer.write(str(result))
+
+ def __repr__(self):
+ name = self.__object.__class__.__name__ + "." + self.key
+ return "%s('%s')" % (self.__class__.__name__, name)
+
+class WidgetTemplate(ObjectTemplate):
+ def __init__(self, widget, key):
+ text = widget.get_string(key)
+
+ if not text:
+ raise Exception("Template '%s.%s' not found" \
+ % (widget.__class__.__name__, key))
+
+ super(WidgetTemplate, self).__init__(widget, text)
+
+ self.widget = widget
+
+ def find_child(self, name):
+ return self.widget.children_by_name.get(name)
Modified: mgmt/trunk/wooly/python/wooly/widgets.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/widgets.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/widgets.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -52,7 +52,7 @@
super(TabbedModeSet, self).__init__(app, name)
self.__tabs = list()
- self.__tab_tmpl = Template(self, "tab_html")
+ self.__tab_tmpl = WidgetTemplate(self, "tab_html")
def add_tab(self, tab):
self.__tabs.append(tab)
@@ -86,7 +86,7 @@
def __init__(self, app, name):
super(WidgetSet, self).__init__(app, name)
- self.__widget_tmpl = Template(self, "widget_html")
+ self.__widget_tmpl = WidgetTemplate(self, "widget_html")
def render_widgets(self, session, *args):
writer = Writer()
@@ -106,7 +106,7 @@
super(LinkSet, self).__init__(app, name)
self.__links = list()
- self.__link_tmpl = Template(self, "link_html")
+ self.__link_tmpl = WidgetTemplate(self, "link_html")
def add_link(self, link):
self.__links.append(link)
@@ -172,7 +172,7 @@
self.items = Attribute(app, "items")
self.add_attribute(self.items)
- self.item_tmpl = Template(self, "item_html")
+ self.item_tmpl = WidgetTemplate(self, "item_html")
def get_item_count(self, session, *args):
return len(self.get_items(session, *args))
More information about the rhmessaging-commits
mailing list