[Checkins] SVN: Sandbox/cklinger/megrok.reload/trunk/megrok/reload/ very basic zcml reloading
Christian Klinger
cklinger at novareto.de
Fri Feb 19 06:40:47 EST 2010
Log message for revision 109151:
very basic zcml reloading
Changed:
U Sandbox/cklinger/megrok.reload/trunk/megrok/reload/browser.py
D Sandbox/cklinger/megrok.reload/trunk/megrok/reload/fivezcml.py
U Sandbox/cklinger/megrok.reload/trunk/megrok/reload/interfaces.py
A Sandbox/cklinger/megrok.reload/trunk/megrok/reload/widgets.py
U Sandbox/cklinger/megrok.reload/trunk/megrok/reload/zcml.py
-=-
Modified: Sandbox/cklinger/megrok.reload/trunk/megrok/reload/browser.py
===================================================================
--- Sandbox/cklinger/megrok.reload/trunk/megrok/reload/browser.py 2010-02-19 11:30:17 UTC (rev 109150)
+++ Sandbox/cklinger/megrok.reload/trunk/megrok/reload/browser.py 2010-02-19 11:40:47 UTC (rev 109151)
@@ -1,27 +1,69 @@
import grok
from zope.interface import Interface
+from grok.interfaces import IApplication
from megrok.reload.code import reload_code
+from megrok.reload.zcml import reload_zcml
from megrok.reload.interfaces import IReload
-from megrok.reload.zcml import reload_zcml
+from zope.schema.interfaces import IVocabularyFactory
+from zope.component import getAllUtilitiesRegisteredFor
+from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+from grokcore.component.testing import grok as grok_module
-grok.templatedir('templates')
+from widgets import MultiCheckBoxWidget
-class Reload(grok.View):
+def null_validator(*args, **kwargs):
+ """A validator that doesn't validate anything.
+
+ This is somewhat lame, but if you have a "Cancel" type button that
+ won't want to validate the form, you need something like this.
+
+ @form.action(_(u"label_cancel", default=u"Cancel"),
+ validator=null_validator,
+ name=u'cancel')
+ """
+ return ()
+
+
+class ApplicationVocabulary(grok.GlobalUtility):
+ grok.implements(IVocabularyFactory)
+ grok.name(u'megrok.reload.applications')
+
+ def __call__(self, context):
+ rc = []
+ apps = getAllUtilitiesRegisteredFor(IApplication)
+ for app in apps:
+ rc.append(SimpleTerm(app.__module__, app.__name__, app.__name__))
+ return SimpleVocabulary(rc)
+
+class MultiCheckBoxVocabularyWidget(MultiCheckBoxWidget):
+ """ """
+
+ def __init__(self, field, request):
+ """Initialize the widget."""
+ super(MultiCheckBoxVocabularyWidget, self).__init__(field,
+ field.value_type.vocabulary, request)
+
+
+class Reload(grok.Form):
"""Reload view.
"""
grok.context(Interface)
grok.implements(IReload)
message = None
- def update(self):
- action = self.request.form.get('action')
- if action is not None:
- if action == 'code':
- self.message = self.code_reload()
- elif action == 'zcml':
- self.message = self.zcml_reload()
+ form_fields = grok.Fields(IReload)
+ form_fields['applications'].custom_widget = MultiCheckBoxVocabularyWidget
+
+ @grok.action(u'Reload Code', validator=null_validator)
+ def handle_relaod(self, **kw):
+ self.code_reload()
+
+ @grok.action(u'Reload Code and ZCML')
+ def handle_relaod(self, **kw):
+ self.zcml_reload(kw.get('applications', []))
+
def status(self):
return self.message
@@ -36,16 +78,11 @@
result = 'No code reloaded!'
return result
- def zcml_reload(self):
-
- # We always do an implicit code reload so we can register all newly
- # added classes.
+ def zcml_reload(self, applications):
reloaded = reload_code()
- reload_zcml()
+ for application in applications:
+ grok_module(application.split('.')[0]) ### BBB: THIS IS VERY BUGGY...
- # TODO Minimize all caches, we only really want to invalidate the
- # local site manager from all caches
- # aq_base(self.context)._p_jar.db().cacheMinimize() BBB
result = ''
if reloaded:
result += 'Code reloaded:\n\n'
Deleted: Sandbox/cklinger/megrok.reload/trunk/megrok/reload/fivezcml.py
===================================================================
--- Sandbox/cklinger/megrok.reload/trunk/megrok/reload/fivezcml.py 2010-02-19 11:30:17 UTC (rev 109150)
+++ Sandbox/cklinger/megrok.reload/trunk/megrok/reload/fivezcml.py 2010-02-19 11:40:47 UTC (rev 109151)
@@ -1,78 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004, 2005 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""ZCML machinery
-
-$Id: zcml.py 96815 2009-02-20 13:25:03Z hannosch $
-"""
-import os
-import os.path
-from zope.configuration import xmlconfig
-
-_initialized = False
-_context = None
-
-
-def load_site():
- """Load a Five/Zope site by finding and loading the appropriate site
- configuration file."""
- global _initialized
- if _initialized:
- return
- _initialized = True
-
- import Globals
- Globals.INSTANCE_HOME
-
- # load instance site configuration file
- site_zcml = os.path.join(Globals.INSTANCE_HOME, "etc", "site.zcml")
-
- import Zope2.utilities
- zope_utilities = os.path.dirname(Zope2.utilities.__file__)
- skel_site_zcml = os.path.join(zope_utilities, "skel", "etc", "site.zcml")
-
- if os.path.exists(site_zcml):
- file = site_zcml
- else:
- # check for zope installation home skel during running unit tests
- file = skel_site_zcml
-
- global _context
- _context = xmlconfig.file(file)
-
-
-def load_config(file, package=None, execute=True):
- """Load an additional ZCML file into the context.
-
- Use with extreme care.
- """
- global _context
- _context = xmlconfig.file(file, package, _context, execute=execute)
-
-def load_string(s):
- """Load a snipped of ZCML into the context.
-
- Use with extreme care.
- """
- global _context
- _context = xmlconfig.string(s, _context)
-
-# clean up code
-
-def cleanUp():
- global _context
- _context = None
-
-from zope.testing.cleanup import addCleanUp
-addCleanUp(cleanUp)
-del addCleanUp
Modified: Sandbox/cklinger/megrok.reload/trunk/megrok/reload/interfaces.py
===================================================================
--- Sandbox/cklinger/megrok.reload/trunk/megrok/reload/interfaces.py 2010-02-19 11:30:17 UTC (rev 109150)
+++ Sandbox/cklinger/megrok.reload/trunk/megrok/reload/interfaces.py 2010-02-19 11:40:47 UTC (rev 109151)
@@ -1,10 +1,18 @@
from zope.interface import Interface
+from zope.schema import Choice, List
class IReload(Interface):
"""Interface for the ZCML reload view.
"""
+ applications = List(
+ title = u"Application",
+ description=u"Pleas select a Application which should be reloaded",
+ value_type=Choice(vocabulary="megrok.reload.applications")
+ )
+
+
def status():
"""Return a status text."""
Added: Sandbox/cklinger/megrok.reload/trunk/megrok/reload/widgets.py
===================================================================
--- Sandbox/cklinger/megrok.reload/trunk/megrok/reload/widgets.py (rev 0)
+++ Sandbox/cklinger/megrok.reload/trunk/megrok/reload/widgets.py 2010-02-19 11:40:47 UTC (rev 109151)
@@ -0,0 +1,43 @@
+from zope.app.form.browser.widget import renderElement
+from zope.app.form.browser import MultiCheckBoxWidget as BaseWidget
+
+
+class MultiCheckBoxWidget(BaseWidget):
+ """Provide a list of checkboxes that provide the choice for the list,
+ with a <label> for accessibility"""
+
+ orientation = "vertical"
+
+ _joinButtonToMessageTemplate = u"%s %s"
+
+ def renderItem(self, index, text, value, name, cssClass):
+ id = '%s.%s' % (name, index)
+ elem = renderElement('input',
+ type="checkbox",
+ cssClass=cssClass,
+ name=name,
+ id=id,
+ value=value)
+
+ label = renderElement('label',
+ extra= u"for=%s" % id,
+ contents=text)
+
+ return self._joinButtonToMessageTemplate %(elem, label)
+
+ def renderSelectedItem(self, index, text, value, name, cssClass):
+ id = '%s.%s' % (name, index)
+ elem = renderElement('input',
+ type="checkbox",
+ cssClass=cssClass,
+ name=name,
+ id=id,
+ value=value,
+ checked="checked")
+
+ label = renderElement('label',
+ extra= u"for=%s" % id,
+ contents=text)
+
+ return self._joinButtonToMessageTemplate %(elem, label)
+
Modified: Sandbox/cklinger/megrok.reload/trunk/megrok/reload/zcml.py
===================================================================
--- Sandbox/cklinger/megrok.reload/trunk/megrok/reload/zcml.py 2010-02-19 11:30:17 UTC (rev 109150)
+++ Sandbox/cklinger/megrok.reload/trunk/megrok/reload/zcml.py 2010-02-19 11:40:47 UTC (rev 109151)
@@ -29,35 +29,25 @@
functions.append(r)
return functions
-import martian
def reload_zcml():
- #from grokcore.component.zcml import
+ from grokcore.component.testing import grok
+ grok('greload')
- def resetBootstrap():
- # we need to make sure that the grokker registry is clean again
- the_module_grokker.clear()
- from zope.testing.cleanup import addCleanUp
- addCleanUp(resetBootstrap)
-
- the_multi_grokker = martian.MetaMultiGrokker()
- the_module_grokker = martian.ModuleGrokker(the_multi_grokker)
-
- return
- gsm = getGlobalSiteManager()
- old_gsm_dict = gsm.__dict__.copy()
- try:
- setSite(None)
- gsm.__init__(gsm.__name__)
- # Clean up
- for clean in cleanups():
- clean()
- # Reload all ZCML
- import pdb;pdb.set_trace()
- fivezcml._initialized = False
- fivezcml._context._seen_files.clear()
- fivezcml.load_site()
- except Exception, e:
- gsm.__init__(gsm.__name__)
- gsm.__dict__.clear()
- gsm.__dict__.update(old_gsm_dict)
- raise e
+ #gsm = getGlobalSiteManager()
+ #old_gsm_dict = gsm.__dict__.copy()
+ #try:
+ # setSite(None)
+ # gsm.__init__(gsm.__name__)
+ # # Clean up
+ # for clean in cleanups():
+ # clean()
+ # # Reload all ZCML
+ # import pdb;pdb.set_trace()
+ # fivezcml._initialized = False
+ # fivezcml._context._seen_files.clear()
+ # fivezcml.load_site()
+ #except Exception, e:
+ # gsm.__init__(gsm.__name__)
+ # gsm.__dict__.clear()
+ # gsm.__dict__.update(old_gsm_dict)
+ # raise e
More information about the checkins
mailing list