[rhmessaging-commits] rhmessaging commits: r3802 - in mgmt/trunk: cumin/python/cumin/account and 3 other directories.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Fri Jan 15 13:21:06 EST 2010
Author: justi9
Date: 2010-01-15 13:21:06 -0500 (Fri, 15 Jan 2010)
New Revision: 3802
Modified:
mgmt/trunk/cumin/python/cumin/account/widgets.py
mgmt/trunk/cumin/python/cumin/grid/submission.py
mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py
mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py
mgmt/trunk/cumin/python/cumin/messaging/exchange.py
mgmt/trunk/cumin/python/cumin/messaging/queue.py
mgmt/trunk/cumin/python/cumin/widgets.py
mgmt/trunk/wooly/python/wooly/__init__.py
mgmt/trunk/wooly/python/wooly/forms.py
Log:
* Improve logging in wooly, especially in the setup phase
* Now that we have proper logging, Widget.test is not needed to
clarify where an assertion failure comes from; stop using it in
favor of simple assertions
* Refactor the init methods on Widget, Page, and Form
* Reclaim the name validate for form input checking; later we'll use
"check" for the post-init check
Modified: mgmt/trunk/cumin/python/cumin/account/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/account/widgets.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/account/widgets.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -109,7 +109,7 @@
name = self.user_name.get(session)
password = self.password.get(session)
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
try:
@@ -169,8 +169,8 @@
self.new1.input.size = 20
self.add_field(self.new1)
- def check(self, session):
- super(ChangePasswordForm, self).check(session)
+ def validate(self, session):
+ super(ChangePasswordForm, self).validate(session)
current = self.current.get(session)
new0 = self.new0.get(session)
@@ -188,7 +188,7 @@
self.errors.add(session, error)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
user = session.client_session.attributes["login_session"].user
Modified: mgmt/trunk/cumin/python/cumin/grid/submission.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/submission.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/grid/submission.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -169,12 +169,12 @@
self.attributes_.input.columns = 50
self.extra_fields.add_field(self.attributes_)
- def check(self, session):
- self.main_fields.check(session)
- self.extra_fields.check(session)
+ def validate(self, session):
+ self.main_fields.validate(session)
+ self.extra_fields.validate(session)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
scheduler = self.scheduler.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -100,7 +100,7 @@
class BrokerGroupAddForm(BrokerGroupForm):
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
name = self.group_name.get(session)
@@ -119,7 +119,7 @@
self.add_parameter(self.group)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
group = self.group.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -379,7 +379,7 @@
pass
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
link = self.link.get(session)
@@ -532,7 +532,7 @@
return self.task.get_description(session, vhost)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
vhost = self.vhost.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/exchange.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/exchange.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/messaging/exchange.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -367,7 +367,7 @@
self.extra_fields.add_field(self.args)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
vhost = self.vhost.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/queue.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -292,11 +292,6 @@
self.bindings = ExchangeKeysField(app, "bindings", self.vhost)
self.add_field(self.bindings)
- def validate(self, session, queue_name):
- super_error = super(QueueAddForm, self).validate(session)
- (errors, form_binding_info) = self.bindings.get_binding_errors(session, queue_name)
- return (errors or super_error, form_binding_info)
-
class AdvancedOptions(MoreFieldSet):
def render_title(self, session):
return "Advanced Options"
@@ -451,9 +446,17 @@
durable = self.durable.get(session)
policy = self.policy.get(session)
- errors, binding_info = self.validate(session, name)
+ self.validate(session)
+ errors = self.errors.get(session)
+
+ binding_errors, binding_info = self.bindings.get_binding_errors \
+ (session, name)
+
if not errors:
+ errors = binding_errors
+
+ if not errors:
invoc = self.task.start(session, vhost)
try:
@@ -531,7 +534,7 @@
return self.task.get_description(session, queue)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
queue = self.queue.get(session)
@@ -820,7 +823,7 @@
self.add_field(self.count)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
queue = self.queue.get(session)
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -303,9 +303,7 @@
# XXX get rid of this!
class CuminFieldForm(FieldSubmitForm, Frame):
- def validate(self, session):
- self.check(session)
- return self.errors.get(session)
+ pass
class CuminEditableProperties(PropertySet):
def __init__(self, app, name):
@@ -1094,7 +1092,7 @@
def render_title(self, session):
return "Name"
- def check(self, session):
+ def validate(self, session):
name = self.get(session)
if name == "" and self.required:
@@ -1145,8 +1143,8 @@
def set_object_attr(self, attr):
self.__object = attr
- def check(self, session):
- super(UniqueNameField, self).check(session)
+ def validate(self, session):
+ super(UniqueNameField, self).validate(session)
name = self.get(session)
Modified: mgmt/trunk/wooly/python/wooly/__init__.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/__init__.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/wooly/python/wooly/__init__.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -13,6 +13,7 @@
from resources import ResourceFinder, StringCatalog
from util import *
+log = logging.getLogger("wooly")
strings = StringCatalog(__file__)
class SessionAttribute(object):
@@ -55,13 +56,16 @@
self.path = None
def init(self):
- #print "Initializing %s" % str(self)
+ log.debug("Initializing %s", self)
if self.widget and self.widget.path:
self.path = ".".join((self.widget.path, self.name))
else:
self.path = self.name
+ def check_me_merrily(self):
+ log.debug("Checking %s", self)
+
def validate(self, session):
value = self.get(session)
@@ -145,7 +149,7 @@
self.update_enabled = False
self.defer_enabled = False
- # These are set in the init() pass
+ # These are computed later in the init pass
self.ancestors = None
self.path = None
self.page = None
@@ -154,18 +158,27 @@
self.__main_tmpl = Template(self, "html")
self.__defer_tmpl = Template(self, "deferred_html")
- def test(self, expr, message=None):
- if not expr:
- if not message:
- message = "Correctness breached"
+ def init(self):
+ log.debug("Initializing %s" % self)
- raise Exception("[%s] %s" % (self, message))
+ self.init_computed_values()
- def init(self):
- #print "Initializing %s" % str(self)
+ if self.page:
+ self.page.init_widget(self)
- self.test(not self.sealed)
+ for attr in self.attributes:
+ attr.init()
+ for param in self.parameters:
+ param.init()
+
+ for child in self.children:
+ child.init()
+
+ assert not self.sealed
+ self.sealed = True
+
+ def init_computed_values(self):
ancestors = list()
widget = self.parent
@@ -173,11 +186,6 @@
ancestors.append(widget)
widget = widget.parent
- for widget in ancestors:
- if isinstance(widget, Frame):
- self.frame = widget
- break
-
self.ancestors = tuple(ancestors)
pelems = [x.name for x in reversed(ancestors)]
@@ -185,49 +193,45 @@
self.path = ".".join(pelems[1:])
self.page = self.ancestors[-1]
- self.page.init_widget(self)
- self.sealed = True
+ for widget in ancestors:
+ if isinstance(widget, Frame):
+ self.frame = widget
+ break
- self.init_children()
+ def check_me_merrily(self):
+ assert self.sealed
+ assert self.path is not None
+ assert isinstance(self.page, Page)
- def init_children(self):
for attr in self.attributes:
- attr.init()
+ attr.check_me_merrily()
- for param in self.parameters:
- param.init()
+ for param in self.attributes:
+ param.check_me_merrily()
for child in self.children:
- child.init()
-
- def check_me_merrily(self):
- self.test(self.sealed)
- self.test(self.path is not None)
- self.test(isinstance(self.page, Page))
-
- for child in self.children:
child.check_me_merrily()
def add_child(self, child):
- self.test(not self.sealed)
- self.test(isinstance(child, Widget))
- self.test(child is not self)
+ assert not self.sealed
+ assert isinstance(child, Widget)
+ assert child is not self
self.children.append(child)
self.children_by_name[child.name] = child
child.parent = self
def add_attribute(self, attribute):
- self.test(not self.sealed)
- self.test(isinstance(attribute, Attribute))
+ assert not self.sealed
+ assert isinstance(attribute, Attribute)
self.attributes.append(attribute)
attribute.widget = self
def add_parameter(self, parameter):
- self.test(not self.sealed)
- self.test(isinstance(parameter, Parameter))
+ assert not self.sealed
+ assert isinstance(parameter, Parameter)
self.parameters.append(parameter)
parameter.widget = self
@@ -262,7 +266,7 @@
return str
def show(self, session):
- self.test(self.parent)
+ assert self.parent
self.parent.show_child(session, self)
self.parent.show(session)
@@ -396,30 +400,22 @@
self.profile = self.ProfileAttribute(app, "profile")
self.add_attribute(self.profile)
- def init(self):
- self.test(not self.sealed)
- self.test(self.parent is None)
-
+ def init_computed_values(self):
self.ancestors = ()
self.path = ""
self.page = self
self.frame = self
- self.init_widget(self)
- self.init_children()
-
- self.sealed = True
-
def init_widget(self, widget):
- self.test(not self.sealed)
- self.test(isinstance(widget, Widget))
+ assert not self.sealed
+ assert isinstance(widget, Widget)
self.page_widgets.append(widget)
self.page_widgets_by_path[widget.path] = widget
def init_parameter(self, param):
- self.test(not self.sealed)
- self.test(isinstance(param, Parameter))
+ assert not self.sealed
+ assert isinstance(param, Parameter)
self.page_parameters.append(param)
self.page_parameters_by_path[param.path] = param
Modified: mgmt/trunk/wooly/python/wooly/forms.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/forms.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/wooly/python/wooly/forms.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -1,8 +1,10 @@
-from wooly import *
from parameters import *
from resources import *
+from util import *
from widgets import ItemSet, escape_entity
+from wooly import *
+log = logging.getLogger("wooly.forms")
strings = StringCatalog(__file__)
class Form(Widget):
@@ -14,8 +16,8 @@
self.form_params = set()
- def check(self, session):
- pass
+ def validate(self, session):
+ log.debug("Validating %s", self)
def render_hidden_inputs(self, session, *args):
writer = Writer()
@@ -64,7 +66,7 @@
if isinstance(anc, Form):
self.form = anc
- self.test(self.form, "Not inside a form")
+ assert self.form # Not inside a form
def get_items(self, session, *args):
return self.form.errors.get(session)
@@ -91,15 +93,14 @@
def init(self):
super(FormInput, self).init()
- self.test(self.param, "Parameter not set")
-
+ assert self.param # Parameter not set
assert isinstance(self.param, Parameter)
for anc in self.ancestors:
if isinstance(anc, Form):
self.form = anc
- self.test(self.form, "Not inside a form")
+ assert self.form # Not inside a form
self.form.form_params.add(self.param)
@@ -327,16 +328,19 @@
self.required = False
self.help = None
- def init(self):
- super(FormField, self).init()
+ def init_computed_values(self):
+ super(FormField, self).init_computed_values()
for anc in self.ancestors:
if isinstance(anc, Form):
self.form = anc
- self.test(self.form, "Not inside a form")
+ def check_me_merrily(self):
+ super(FormField, self).check_me_merrily()
- def check(self, session):
+ assert self.form # Not inside a form
+
+ def validate(self, session):
pass
def render_required(self, session, *args):
@@ -362,9 +366,9 @@
self.fields.append(field)
self.add_child(field)
- def check(self, session):
+ def validate(self, session):
for field in self.fields:
- field.check(session)
+ field.validate(session)
def render_message(self, session, *args):
pass
@@ -399,7 +403,7 @@
def set(self, session, value):
return self.input.set(session, value)
- def check(self, session):
+ def validate(self, session):
value = self.get(session)
if value in ("", None) and self.required:
@@ -437,7 +441,7 @@
self.input = IntegerInput(app, "input")
self.add_child(self.input)
- def check(self, session):
+ def validate(self, session):
value = self.get(session)
if value:
@@ -631,10 +635,10 @@
def add_field(self, field):
self.content.add_field(field)
- def check(self, session):
- super(FieldSubmitForm, self).check(session)
+ def validate(self, session):
+ super(FieldSubmitForm, self).validate(session)
- self.content.check(session)
+ self.content.validate(session)
def render_content(self, session, *args):
return self.content.render(session, *args)
@@ -652,11 +656,11 @@
self.extra_fields = ShowableFieldSet(app, "extra")
self.content.add_child(self.extra_fields)
- def check(self, session):
- super(FoldingFieldSubmitForm, self).check(session)
+ def validate(self, session):
+ super(FoldingFieldSubmitForm, self).validate(session)
- self.main_fields.check(session)
- self.extra_fields.check(session)
+ self.main_fields.validate(session)
+ self.extra_fields.validate(session)
def render_content(self, session, *args):
return self.content.render(session, *args)
More information about the rhmessaging-commits
mailing list