rhmessaging commits: r1048 - mgmt/cumin/python/cumin.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 15:06:31 -0400 (Sat, 13 Oct 2007)
New Revision: 1048
Modified:
mgmt/cumin/python/cumin/page.py
mgmt/cumin/python/cumin/page.strings
Log:
Use a child template instead of a widget to render the context nav
links.
Modified: mgmt/cumin/python/cumin/page.py
===================================================================
--- mgmt/cumin/python/cumin/page.py 2007-10-13 18:57:52 UTC (rev 1047)
+++ mgmt/cumin/python/cumin/page.py 2007-10-13 19:06:31 UTC (rev 1048)
@@ -20,8 +20,7 @@
self.modal = Attribute(app, "modal")
self.add_attribute(self.modal)
- self.citem = self.ContextItem(app, "citem")
- self.add_child(self.citem)
+ self.frame_tmpl = Template(self, "frame_html")
self.main = MainFrame(app, "main")
self.add_child(self.main)
@@ -81,9 +80,6 @@
frame = frame.show_exchange(session, exchange)
return self.set_current_frame(session, frame)
- def render_title(self, session, object):
- return "Cumin"
-
def render_class(self, session, object):
return self.modal.get(session) and "modal"
@@ -93,21 +89,19 @@
def get_frames(self, session):
return self.frames.get(session)
- def render_context_items(self, session, object):
+ def render_frames(self, session, object):
writer = Writer()
for frame in self.get_frames(session):
- writer.write(self.citem.render(session, frame))
+ self.frame_tmpl.render(session, frame, writer)
return writer.to_string()
- # XXX use a child template instead
- class ContextItem(Widget):
- def render_href(self, session, frame):
- return frame.render_href(session, frame.get_object(session))
+ def render_frame_href(self, session, frame):
+ return frame.render_href(session, frame.get_object(session))
- def render_content(self, session, frame):
- return frame.render_title(session, frame.get_object(session))
+ def render_frame_title(self, session, frame):
+ return frame.render_title(session, frame.get_object(session))
class MainFrame(CuminFrame):
def __init__(self, app, name):
Modified: mgmt/cumin/python/cumin/page.strings
===================================================================
--- mgmt/cumin/python/cumin/page.strings 2007-10-13 18:57:52 UTC (rev 1047)
+++ mgmt/cumin/python/cumin/page.strings 2007-10-13 19:06:31 UTC (rev 1048)
@@ -372,7 +372,7 @@
<li>Hi, <strong>nsantos</strong></li>
<li><a class="action" href="">Log Out</a></li>
</ul>
- <ul id="context">{context_items}</ul>
+ <ul id="context">{frames}</ul>
</div>
<div id="body">{content}</div>
<div id="foot">
@@ -380,8 +380,8 @@
</body>
</html>
-[ContextItem.html]
-<li><a href="{href}">{content}</a></li>
+[CuminPage.frame_html]
+<li><a href="{frame_href}">{frame_title}</a></li>
[MainView.html]
<div class="oblock">
17 years, 2 months
rhmessaging commits: r1047 - mgmt/cumin/python/wooly.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 14:57:52 -0400 (Sat, 13 Oct 2007)
New Revision: 1047
Modified:
mgmt/cumin/python/wooly/__init__.py
Log:
Use clock() instead of time for WidgetCall entry and exit.
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-13 18:56:00 UTC (rev 1046)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-13 18:57:52 UTC (rev 1047)
@@ -2,8 +2,7 @@
from cStringIO import StringIO
from urllib import quote, unquote
from copy import copy
-# XXX use clock instead
-from time import time
+from time import clock
from datetime import datetime
from resources import ResourceFinder, StringCatalog
@@ -711,10 +710,10 @@
self.stack.append(self)
- self.start = time()
+ self.start = clock()
def close(self):
- self.end = time()
+ self.end = clock()
if len(self.stack) > 1:
self.stack.pop()
17 years, 2 months
rhmessaging commits: r1046 - in mgmt: notes and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 14:56:00 -0400 (Sat, 13 Oct 2007)
New Revision: 1046
Modified:
mgmt/cumin/python/wooly/__init__.py
mgmt/notes/Todo
Log:
Checks that placeholders that match widget methods are actually
callable.
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-13 18:49:14 UTC (rev 1045)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-13 18:56:00 UTC (rev 1046)
@@ -671,12 +671,11 @@
return fragments
- # XXX Ought to make sure what we're returning is a method.
def find_method(self, name):
for cls in self.widget.__class__.__mro__:
method = getattr(cls, name, None)
- if method:
+ if method and callable(method):
return method
def render(self, session, object, writer):
Modified: mgmt/notes/Todo
===================================================================
--- mgmt/notes/Todo 2007-10-13 18:49:14 UTC (rev 1045)
+++ mgmt/notes/Todo 2007-10-13 18:56:00 UTC (rev 1046)
@@ -69,3 +69,5 @@
* Remove log messages from host template view
* Consider having a cssclass set on widgets
+
+ * Use page attributes for session errors, redirect
\ No newline at end of file
17 years, 2 months
rhmessaging commits: r1045 - mgmt/cumin/python/wooly.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 14:49:14 -0400 (Sat, 13 Oct 2007)
New Revision: 1045
Modified:
mgmt/cumin/python/wooly/__init__.py
Log:
Makes widget and parameter lookups faster.
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-13 17:59:35 UTC (rev 1044)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-13 18:49:14 UTC (rev 1045)
@@ -27,8 +27,6 @@
app.add_widget(self)
- self.strings = None
-
def ancestors(self):
if not self.cached_ancestors:
if not self.parent:
@@ -331,9 +329,11 @@
self.pages = dict()
self.default_page = None
- # Registration lists XXX get rid of?
self.widgets = list()
+ self.widget_index = None
+
self.parameters = list()
+ self.parameter_index = None
self.finder = ResourceFinder()
self.cached_css = None
@@ -362,24 +362,39 @@
self.default_page = page
def add_widget(self, widget):
+ if self.widget_index:
+ raise Exception()
+
self.widgets.append(widget)
def get_widget(self, key):
- # XXX not fast
- for widget in self.widgets:
- if widget.path() == key:
- return widget
+ if not self.widget_index:
+ index = dict()
+ for widget in self.widgets:
+ index[widget.path()] = widget
+
+ self.widget_index = index
+
+ return self.widget_index.get(key)
+
def add_parameter(self, param):
+ if self.parameter_index:
+ raise Exception()
+
self.parameters.append(param)
def get_parameter(self, key):
- # XXX not fast
- for param in self.parameters:
- # XXX I'm not sure the param.widget test is what I want
- if param.widget and param.path() == key:
- return param
+ if not self.parameter_index:
+ index = dict()
+ for param in self.parameters:
+ index[param.path()] = param
+
+ self.parameter_index = index
+
+ return self.parameter_index.get(key)
+
def add_resource_dir(self, dir):
self.finder.add_dir(dir)
17 years, 2 months
rhmessaging commits: r1044 - mgmt/cumin/python/wooly.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 13:59:35 -0400 (Sat, 13 Oct 2007)
New Revision: 1044
Removed:
mgmt/cumin/python/wooly/debug.py
Log:
Removes a file we no longer use.
Deleted: mgmt/cumin/python/wooly/debug.py
===================================================================
--- mgmt/cumin/python/wooly/debug.py 2007-10-13 16:46:50 UTC (rev 1043)
+++ mgmt/cumin/python/wooly/debug.py 2007-10-13 17:59:35 UTC (rev 1044)
@@ -1,158 +0,0 @@
-from wooly import *
-from wooly.widgets import *
-
-class WidgetInspector(Widget):
- css = """
- .WidgetInspector {
- background-color: white;
- padding: 1em;
- border: 1px solid #ccc;
- min-height: 60em;
- }
-
- .WidgetInspector .list {
- float: left;
- width: 20em;
- background-color: #f7f7f7;
- padding: 0.75em 1em;
- border: 1px dashed #ccc;
- margin: 0 1em 0 0;
- }
-
- """
-
- html = """
- <div class="WidgetInspector">
- <div class="list">{widgets}</div>
- {view}
- </div>
- """
-
- def __init__(self, app, name):
- super(WidgetInspector, self).__init__(app, name)
-
- self.widgets = WidgetList(app, "widgets")
- self.add_child(self.widgets)
-
- self.view = WidgetView(app, "view")
- self.add_child(self.view)
-
-class WidgetView(Widget):
- css = """
- """
-
- html = """
- <h2>{title}</h2>
- """
-
- def render_title(self, session, object):
- return self.parent.widgets.get_selected_widget(session).name
-
-class WidgetList(Widget):
- css = """
- .WidgetList ul {
- list-style: none;
- margin: 0;
- padding: 0 0 0 1.5em;
- }
-
- .WidgetList .selected {
- font-weight: bold;
- }
- """
-
- html = """
- <div class="WidgetList"><ul>{widgets}</ul></div>
- """
-
- def __init__(self, app, name):
- super(WidgetList, self).__init__(app, name)
-
- self.widget = Parameter(app, "widget")
- self.add_parameter(self.widget)
-
- self.item = self.WidgetItem(app, "item")
- self.add_child(self.item)
-
- def do_process(self, session, object):
- print "do_process"
-
- if not self.get_selected_widget(session):
- self.set_selected_widget(session, self.page())
-
- def get_selected_widget(self, session):
- return self.app.get_widget(self.widget.get(session))
-
- def set_selected_widget(self, session, widget):
- self.widget.set(session, widget.path())
-
- def render_title(self, session, object):
- return "Widgets"
-
- def render_widgets(self, session, object):
- return self.item.render(session, self.page())
-
- class WidgetItem(Widget):
- html = """
- <li class="{selected}">{class} <a href="{href}">{name}</a></li>
- {children}
- """
-
- def render_selected(self, session, widget):
- if widget == self.parent.get_selected_widget(session):
- return "selected"
-
- def render_href(self, session, widget):
- branch = session.branch()
- self.parent.set_selected_widget(branch, widget)
- return branch.marshal()
-
- def render_class(self, session, widget):
- return widget.__class__.__name__
-
- def render_name(self, session, widget):
- return widget.name
-
- def render_children(self, session, widget):
- if len(widget.children):
- writer = Writer()
- writer.write("<ul>")
-
- for child in widget.children:
- writer.write(self.parent.item.render(session, child))
-
- writer.write("</ul>")
-
- return writer.to_string()
-
- def xxx_render_widget(self, session, widget, depth, writer):
- spacer = ". "
- indent = spacer * depth
-
- try:
- cum_time = session.render_times[widget] * 1000
- self_time = cum_time
- for child in widget.children:
- self_time -= session.render_times[child] * 1000
-
- if widget.parent and cum_time > 0.2 * session.render_times[widget.parent] * 1000:
- hot = "hot"
- else:
- hot = ""
-
- stime = " (<span class='wooly debug timing %s'>%f, %f</span>)" % \
- (hot, cum_time, self_time)
- except KeyError:
- stime = ""
-
- writer.write("%s%s <b>%s</b>%s\n" % \
- (indent, widget.__class__.__name__, widget.name, \
- stime))
-
- for param in widget.parameters:
- writer.write("%s<span class='wooly debug param'>param %s <strong>%s</strong> = %s</span>\n" % \
- (indent + spacer, param.__class__.__name__, \
- param.name, param.get(session)))
-
- for child in widget.children:
- self.render_widget(session, child, depth + 1, writer)
17 years, 2 months
rhmessaging commits: r1043 - in mgmt/cumin: python/wooly and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 12:46:50 -0400 (Sat, 13 Oct 2007)
New Revision: 1043
Modified:
mgmt/cumin/bin/cumin-test
mgmt/cumin/python/wooly/__init__.py
Log:
Only url decode and encode the value part of url params. Save the
computed param path, since it's called very frequently.
Modified: mgmt/cumin/bin/cumin-test
===================================================================
--- mgmt/cumin/bin/cumin-test 2007-10-13 15:55:12 UTC (rev 1042)
+++ mgmt/cumin/bin/cumin-test 2007-10-13 16:46:50 UTC (rev 1043)
@@ -75,6 +75,11 @@
stats.sort_stats("cumulative").print_stats(15)
stats.sort_stats("time").print_stats(15)
+ #stats.print_callees("wooly/__init__.*\\(marshal_url_vars\\)")
+ #stats.print_callees("wooly/__init__.*\\(path\\)")
+ #stats.print_callees("wooly/__init__.*\\(get\\)")
+ #stats.print_callees("wooly/__init__.*\\(render\\)")
+
stats.strip_dirs()
else:
try:
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-13 15:55:12 UTC (rev 1042)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-13 16:46:50 UTC (rev 1043)
@@ -1,6 +1,6 @@
import sys, os
from cStringIO import StringIO
-from urllib import quote_plus, unquote_plus
+from urllib import quote, unquote
from copy import copy
# XXX use clock instead
from time import time
@@ -177,17 +177,17 @@
self.default = None
self.is_required = True
+ self.cached_path = None
+
def path(self):
- if not self.widget:
- raise Exception("Parameter has no widget")
+ if not self.cached_path:
+ if not self.widget.parent:
+ self.cached_path = self.name
+ else:
+ self.cached_path = self.widget.path() + "." + self.name
- if not self.widget.parent:
- return self.name
- else:
- path = self.widget.path() + "." + self.name
+ return self.cached_path
- return path
-
def set_required(self, is_required):
self.is_required = is_required
@@ -518,10 +518,9 @@
default = param.get_default(self)
if value not in (default, None):
- skey = quote_plus(key)
- svalue = quote_plus(param.marshal(value))
+ svalue = quote(param.marshal(value))
- vars.append("%s=%s" % (skey, svalue))
+ vars.append("%s=%s" % (key, svalue))
return separator.join(vars)
@@ -546,11 +545,9 @@
for var in vars:
try:
- skey, svalue = var.split("=")
+ key, svalue = var.split("=")
+ value = unquote(svalue)
- key = unquote_plus(skey)
- value = unquote_plus(svalue)
-
param = self.app.get_parameter(key)
if param:
17 years, 2 months
rhmessaging commits: r1042 - in mgmt/cumin/python: wooly and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 11:55:12 -0400 (Sat, 13 Oct 2007)
New Revision: 1042
Modified:
mgmt/cumin/python/cumin/page.py
mgmt/cumin/python/wooly/__init__.py
Log:
Adds a default frame method to Page, and uses it to make MainFrame the
default for CuminPage.
Modified: mgmt/cumin/python/cumin/page.py
===================================================================
--- mgmt/cumin/python/cumin/page.py 2007-10-13 15:48:25 UTC (rev 1041)
+++ mgmt/cumin/python/cumin/page.py 2007-10-13 15:55:12 UTC (rev 1042)
@@ -25,6 +25,7 @@
self.main = MainFrame(app, "main")
self.add_child(self.main)
+ self.set_default_frame(self.main)
class FramesAttribute(Attribute):
def get_default(self, session):
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-13 15:48:25 UTC (rev 1041)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-13 15:55:12 UTC (rev 1042)
@@ -285,8 +285,8 @@
super(Page, self).__init__(app, name)
self.frame = self.FrameParameter(app, "frame")
- self.frame.set_default(self)
self.add_parameter(self.frame)
+ self.set_default_frame(self)
self.cached_parameters = dict()
@@ -307,6 +307,9 @@
def get_current_frame(self, session):
return self.frame.get(session)
+ def set_default_frame(self, frame):
+ self.frame.set_default(frame)
+
def get_saved_parameters(self, session):
frame = self.get_current_frame(session)
17 years, 2 months
rhmessaging commits: r1041 - in mgmt/cumin/python: wooly and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 11:48:25 -0400 (Sat, 13 Oct 2007)
New Revision: 1041
Modified:
mgmt/cumin/python/cumin/page.py
mgmt/cumin/python/cumin/widgets.py
mgmt/cumin/python/wooly/__init__.py
Log:
Makes Page into a Frame. Renames get/set_frame to
get/set_current_frame. Fixes a bug in widget.ancestors()
Modified: mgmt/cumin/python/cumin/page.py
===================================================================
--- mgmt/cumin/python/cumin/page.py 2007-10-13 14:53:01 UTC (rev 1040)
+++ mgmt/cumin/python/cumin/page.py 2007-10-13 15:48:25 UTC (rev 1041)
@@ -46,15 +46,15 @@
else:
frame = self.main.show_server(session, server)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_server_group(self, session, sgroup):
frame = self.main.show_server_group(session, sgroup)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_cluster(self, session, cluster):
frame = self.main.show_cluster(session, cluster)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_virtual_host(self, session, vhost):
server = vhost.get_server()
@@ -68,17 +68,17 @@
frame = self.main
frame = frame.show_virtual_host(session, vhost)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_queue(self, session, queue):
frame = self.show_virtual_host(session, queue.virtual_host)
frame = frame.show_queue(session, queue)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def show_exchange(self, session, exchange):
frame = self.show_virtual_host(session, exchange.virtual_host)
frame = frame.show_exchange(session, exchange)
- return self.set_frame(session, frame)
+ return self.set_current_frame(session, frame)
def render_title(self, session, object):
return "Cumin"
Modified: mgmt/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/cumin/python/cumin/widgets.py 2007-10-13 14:53:01 UTC (rev 1040)
+++ mgmt/cumin/python/cumin/widgets.py 2007-10-13 15:48:25 UTC (rev 1041)
@@ -25,7 +25,7 @@
def render_href(self, session, vhost):
branch = session.branch()
- self.page().set_frame(branch, self)
+ self.page().set_current_frame(branch, self)
self.show_view(branch)
return branch.marshal()
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-13 14:53:01 UTC (rev 1040)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-13 15:48:25 UTC (rev 1041)
@@ -35,7 +35,8 @@
self.cached_ancestors = tuple()
else:
ancs = list(self.parent.ancestors())
- ancs.append(self)
+ ancs.append(self.parent)
+
self.cached_ancestors = tuple(ancs)
return self.cached_ancestors
@@ -161,7 +162,7 @@
writer = Writer()
for child in self.children:
- writer.write(child.render(session, object))
+ writer.write(child.render(session, object))
return writer.to_string()
@@ -246,7 +247,34 @@
def do_unmarshal(self, string):
return string
-class Page(Widget):
+class Frame(Widget):
+ def __init__(self, app, name):
+ super(Frame, self).__init__(app, name)
+
+ self.object = None
+
+ def set_object_attribute(self, attribute):
+ self.object = attribute
+
+ def get_object(self, session):
+ if self.object:
+ return self.object.get(session)
+
+ def get_saved_parameters(self, session):
+ frame = self.page().get_current_frame(session)
+
+ if self is frame or self in frame.ancestors():
+ return super(Frame, self).get_saved_parameters(session)
+
+ def do_process(self, session, object):
+ new_object = self.get_object(session)
+ super(Frame, self).do_process(session, new_object)
+
+ def do_render(self, session, object):
+ new_object = self.get_object(session)
+ return super(Frame, self).do_render(session, new_object)
+
+class Page(Frame):
xml_content_type = "text/xml"
html_content_type = "text/html"
xml_1_0_declaration = """<?xml version="1.0"?>"""
@@ -257,6 +285,7 @@
super(Page, self).__init__(app, name)
self.frame = self.FrameParameter(app, "frame")
+ self.frame.set_default(self)
self.add_parameter(self.frame)
self.cached_parameters = dict()
@@ -270,26 +299,23 @@
def save_session(self, session):
pass
- def set_frame(self, session, frame):
+ def set_current_frame(self, session, frame):
self.frame.set(session, frame)
return frame
- def get_frame(self, session):
+ def get_current_frame(self, session):
return self.frame.get(session)
def get_saved_parameters(self, session):
- frame = self.get_frame(session)
+ frame = self.get_current_frame(session)
- if frame:
- if frame not in self.cached_parameters:
- params = super(Page, self).get_saved_parameters(session)
- self.cached_parameters[frame] = params
+ if frame not in self.cached_parameters:
+ params = super(Page, self).get_saved_parameters(session)
+ self.cached_parameters[frame] = params
+
+ return self.cached_parameters[frame]
- return self.cached_parameters[frame]
- else:
- return super(Page, self).get_saved_parameters(session)
-
class FrameParameter(Parameter):
def do_marshal(self, frame):
return frame.path()
@@ -297,33 +323,6 @@
def do_unmarshal(self, path):
return self.app.get_widget(path)
-class Frame(Widget):
- def __init__(self, app, name):
- super(Frame, self).__init__(app, name)
-
- self.object = None
-
- def set_object_attribute(self, attribute):
- self.object = attribute
-
- def get_object(self, session):
- if self.object:
- return self.object.get(session)
-
- def get_saved_parameters(self, session):
- frame = self.page().get_frame(session)
-
- if not frame or self is frame or self in frame.ancestors():
- return super(Frame, self).get_saved_parameters(session)
-
- def do_process(self, session, object):
- new_object = self.get_object(session)
- super(Frame, self).do_process(session, new_object)
-
- def do_render(self, session, object):
- new_object = self.get_object(session)
- return super(Frame, self).do_render(session, new_object)
-
class Application(object):
def __init__(self):
self.pages = dict()
@@ -488,8 +487,14 @@
self.saved_parameters.extend(params)
def marshal(self):
- url = self.marshal_page() + "?" + self.marshal_url_vars()
+ page = self.marshal_page()
+ vars = self.marshal_url_vars()
+ if vars:
+ url = page + "?" + vars
+ else:
+ url = page
+
if self.debug:
self.app.debug.urls.add(url)
@@ -500,21 +505,23 @@
def marshal_url_vars(self, separator=";"):
params = self.get_page().get_saved_parameters(self)
- vars = list()
- for param in params:
- key = param.path()
- value = self.get(key)
- default = param.get_default(self)
+ if params:
+ vars = list()
- if value not in (default, None):
- skey = quote_plus(key)
- svalue = quote_plus(param.marshal(value))
+ for param in params:
+ key = param.path()
+ value = self.get(key)
+ default = param.get_default(self)
- vars.append("%s=%s" % (skey, svalue))
+ if value not in (default, None):
+ skey = quote_plus(key)
+ svalue = quote_plus(param.marshal(value))
- return separator.join(vars)
+ vars.append("%s=%s" % (skey, svalue))
+ return separator.join(vars)
+
def unmarshal(self, string):
if string.startswith("/"):
raise Exception("Illegal session string '" + string + "'")
17 years, 2 months
rhmessaging commits: r1040 - mgmt/cumin/python/wooly.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 10:53:01 -0400 (Sat, 13 Oct 2007)
New Revision: 1040
Modified:
mgmt/cumin/python/wooly/__init__.py
Log:
Takes care of hotspot that showed up in profiling. Stores the result of calculating the parameters in scope for a frame instead of recalculating it on each session.marshal.
Modified: mgmt/cumin/python/wooly/__init__.py
===================================================================
--- mgmt/cumin/python/wooly/__init__.py 2007-10-13 14:17:34 UTC (rev 1039)
+++ mgmt/cumin/python/wooly/__init__.py 2007-10-13 14:53:01 UTC (rev 1040)
@@ -99,12 +99,17 @@
if str:
return str
- def save_parameters(self, session):
- session.save_parameters(self.parameters)
+ def get_saved_parameters(self, session):
+ params = list()
+ params.extend(self.parameters)
for child in self.children:
- child.save_parameters(session)
+ cparams = child.get_saved_parameters(session)
+ if cparams:
+ params.extend(cparams)
+ return params
+
def process(self, session, object):
if session.debug:
call = WidgetCall(session.debug.process_stack,
@@ -254,6 +259,8 @@
self.frame = self.FrameParameter(app, "frame")
self.add_parameter(self.frame)
+ self.cached_parameters = dict()
+
def get_last_modified(self, session):
return datetime.utcnow()
@@ -271,6 +278,18 @@
def get_frame(self, session):
return self.frame.get(session)
+ def get_saved_parameters(self, session):
+ frame = self.get_frame(session)
+
+ if frame:
+ if frame not in self.cached_parameters:
+ params = super(Page, self).get_saved_parameters(session)
+ self.cached_parameters[frame] = params
+
+ return self.cached_parameters[frame]
+ else:
+ return super(Page, self).get_saved_parameters(session)
+
class FrameParameter(Parameter):
def do_marshal(self, frame):
return frame.path()
@@ -291,11 +310,11 @@
if self.object:
return self.object.get(session)
- def save_parameters(self, session):
+ def get_saved_parameters(self, session):
frame = self.page().get_frame(session)
if not frame or self is frame or self in frame.ancestors():
- super(Frame, self).save_parameters(session)
+ return super(Frame, self).get_saved_parameters(session)
def do_process(self, session, object):
new_object = self.get_object(session)
@@ -466,7 +485,7 @@
self.redirect = redirect
def save_parameters(self, params):
- self.saved_parameters += params
+ self.saved_parameters.extend(params)
def marshal(self):
url = self.marshal_page() + "?" + self.marshal_url_vars()
@@ -480,11 +499,10 @@
return self.get_page().name
def marshal_url_vars(self, separator=";"):
- self.get_page().save_parameters(self)
-
+ params = self.get_page().get_saved_parameters(self)
vars = list()
- for param in self.saved_parameters:
+ for param in params:
key = param.path()
value = self.get(key)
default = param.get_default(self)
@@ -514,8 +532,6 @@
self.set_page(self.app.get_page(string))
def unmarshal_url_vars(self, string, separator=";"):
- self.get_page().save_parameters(self)
-
vars = string.split(separator)
for var in vars:
17 years, 2 months
rhmessaging commits: r1039 - in mgmt/cumin: python/wooly and 1 other directory.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2007-10-13 10:17:34 -0400 (Sat, 13 Oct 2007)
New Revision: 1039
Modified:
mgmt/cumin/bin/cumin-test
mgmt/cumin/python/wooly/devel.py
Log:
More profiling improvements. Adds a max param to the benchmark
harness. Fixes profile dumps.
Modified: mgmt/cumin/bin/cumin-test
===================================================================
--- mgmt/cumin/bin/cumin-test 2007-10-13 02:49:17 UTC (rev 1038)
+++ mgmt/cumin/bin/cumin-test 2007-10-13 14:17:34 UTC (rev 1039)
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import sys, profile, pstats
+import sys
from time import time
from wooly.devel import BenchmarkHarness
from wooly.server import WebServer
@@ -23,7 +23,7 @@
return args
-def do_main(port, debug=True, bench=False, demodata=True):
+def do_main(port, bench_hits, debug=True, demodata=True):
model = CuminModel()
app = Cumin(model)
@@ -36,9 +36,9 @@
if debug or bench:
app.enable_debug()
- if bench:
+ if bench_hits:
harness = BenchmarkHarness(app)
- harness.run()
+ harness.run(bench_hits)
else:
server = WebServer(app, port)
server.run()
@@ -49,27 +49,36 @@
in_port = int(args.get("port", 9090))
in_profile = "profile" in args
in_debug = "no-debug" not in args
- in_bench = "bench" in args
+ in_bench = "bench" in args and int(args.get("bench", None) or 200) or 0
in_demodata = "no-demo-data" not in args
- stats_file = "/tmp/cumin-test-stats-%i" % time()
+ if in_profile:
+ from profile import Profile
+ from pstats import Stats
- if in_profile:
- try:
- code = "do_main(%i, %r, %r, %r)" % \
- (in_port, in_debug, in_bench, in_demodata)
- profile.run(code, stats_file)
+ prof = Profile()
+
+ try:
+ statement = "do_main(%i, %i, %r, %r)" % \
+ (in_port, in_bench, in_debug, in_demodata)
+
+ prof.run(statement)
+
raise KeyboardInterrupt()
except KeyboardInterrupt:
- stats = pstats.Stats(stats_file)
+ file = "/tmp/cumin-test-stats-%i" % time()
- stats.sort_stats("cumulative").print_stats(40)
- stats.sort_stats("time").print_stats(40)
+ prof.dump_stats(file)
+ stats = Stats(file)
+
+ stats.sort_stats("cumulative").print_stats(15)
+ stats.sort_stats("time").print_stats(15)
+
stats.strip_dirs()
else:
try:
- do_main(in_port, in_debug, in_bench, in_demodata)
+ do_main(in_port, in_bench, in_debug, in_demodata)
except KeyboardInterrupt:
pass
Modified: mgmt/cumin/python/wooly/devel.py
===================================================================
--- mgmt/cumin/python/wooly/devel.py 2007-10-13 02:49:17 UTC (rev 1038)
+++ mgmt/cumin/python/wooly/devel.py 2007-10-13 14:17:34 UTC (rev 1039)
@@ -8,7 +8,7 @@
def __init__(self, app):
self.app = app
- def run(self):
+ def run(self, max=-1):
visited = set()
self.app.debug.urls.add("")
count = 0
@@ -31,10 +31,14 @@
bytes = len(html)
millis = (clock() - start) * 1000
- count += 1
print count, bytes, millis, url
+ if count == max:
+ break
+
+ count += 1
+
class DevelPage(Page):
html = """
<html>
17 years, 2 months