[Checkins]
SVN: grok/branches/gotcha-configuration-actions/src/grok/
Get rid of the bootstrap madness. Nohting that's in there has
to do with grokking,
Philipp von Weitershausen
philikon at philikon.de
Sat Oct 27 12:05:05 EDT 2007
Log message for revision 81133:
Get rid of the bootstrap madness. Nohting that's in there has to do with grokking,
it's just some simple component setup that Grok applications need. So we can just
as well put it in grok's configure.zcml.
There, the grokking procedure is now completely independent of grok-the-web-framework.
Changed:
U grok/branches/gotcha-configuration-actions/src/grok/components.py
U grok/branches/gotcha-configuration-actions/src/grok/configure.zcml
U grok/branches/gotcha-configuration-actions/src/grok/meta.zcml
U grok/branches/gotcha-configuration-actions/src/grok/testing.py
U grok/branches/gotcha-configuration-actions/src/grok/zcml.py
-=-
Modified: grok/branches/gotcha-configuration-actions/src/grok/components.py
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/components.py 2007-10-27 16:00:28 UTC (rev 81132)
+++ grok/branches/gotcha-configuration-actions/src/grok/components.py 2007-10-27 16:05:04 UTC (rev 81133)
@@ -42,8 +42,9 @@
PageTemplateResourceFactory
from zope.app.container.btree import BTreeContainer
from zope.app.container.contained import Contained
-from zope.app.container.interfaces import IReadContainer
+from zope.app.container.interfaces import IReadContainer, IObjectAddedEvent
from zope.app.component.site import SiteManagerContainer
+from zope.app.component.site import LocalSiteManager
import z3c.flashmessage.interfaces
@@ -65,7 +66,16 @@
class Site(SiteManagerContainer):
pass
+ at component.adapter(Site, IObjectAddedEvent)
+def addSiteHandler(site, event):
+ sitemanager = LocalSiteManager(site)
+ # LocalSiteManager creates the 'default' folder in its __init__.
+ # It's not needed anymore in new versions of Zope 3, therefore we
+ # remove it
+ del sitemanager['default']
+ site.setSiteManager(sitemanager)
+
class Application(Site):
"""A top-level application object."""
interface.implements(interfaces.IApplication)
Modified: grok/branches/gotcha-configuration-actions/src/grok/configure.zcml
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/configure.zcml 2007-10-27 16:00:28 UTC (rev 81132)
+++ grok/branches/gotcha-configuration-actions/src/grok/configure.zcml 2007-10-27 16:05:04 UTC (rev 81133)
@@ -1,5 +1,6 @@
<configure
xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser"
xmlns:grok="http://namespaces.zope.org/grok">
<include package="zope.security" file="meta.zcml" />
@@ -28,6 +29,20 @@
<securityPolicy
component="zope.app.securitypolicy.zopepolicy.ZopeSecurityPolicy" />
+ <adapter factory=".components.ModelTraverser" />
+ <adapter factory=".components.ContainerTraverser" />
+
+ <browser:defaultView
+ for=".components.Model"
+ name="index"
+ />
+ <browser:defaultView
+ for=".components.Container"
+ name="index"
+ />
+
+ <subscriber handler=".components.addSiteHandler" />
+
<!-- this overrides Zope 3's publication factories because they have
the same name; we also need to change the priority because of
the ZCML discriminator -->
Modified: grok/branches/gotcha-configuration-actions/src/grok/meta.zcml
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/meta.zcml 2007-10-27 16:00:28 UTC (rev 81132)
+++ grok/branches/gotcha-configuration-actions/src/grok/meta.zcml 2007-10-27 16:05:04 UTC (rev 81133)
@@ -1,6 +1,7 @@
<configure
xmlns="http://namespaces.zope.org/zope"
- xmlns:meta="http://namespaces.zope.org/meta">
+ xmlns:meta="http://namespaces.zope.org/meta"
+ xmlns:grok="http://namespaces.zope.org/grok">
<meta:directives namespace="http://namespaces.zope.org/grok">
<meta:directive
@@ -9,5 +10,8 @@
handler=".zcml.grokDirective"
/>
</meta:directives>
+
+ <!-- Load the grokkers -->
+ <grok:grok package=".meta" />
+
</configure>
-
\ No newline at end of file
Modified: grok/branches/gotcha-configuration-actions/src/grok/testing.py
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/testing.py 2007-10-27 16:00:28 UTC (rev 81132)
+++ grok/branches/gotcha-configuration-actions/src/grok/testing.py 2007-10-27 16:05:04 UTC (rev 81133)
@@ -19,6 +19,7 @@
def grok(module_name):
config = ConfigurationMachine()
+ zcml.do_grok('grok.meta', config)
zcml.do_grok(module_name, config)
config.execute_actions()
Modified: grok/branches/gotcha-configuration-actions/src/grok/zcml.py
===================================================================
--- grok/branches/gotcha-configuration-actions/src/grok/zcml.py 2007-10-27 16:00:28 UTC (rev 81132)
+++ grok/branches/gotcha-configuration-actions/src/grok/zcml.py 2007-10-27 16:05:04 UTC (rev 81133)
@@ -13,71 +13,28 @@
##############################################################################
"""Grok ZCML directives."""
-from zope import interface
-import zope.configuration.fields
-
-import os
-
-from zope import component
-from zope import interface
-
-from zope.component.interfaces import IDefaultViewName
-from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.interface import Interface
+from zope.configuration.fields import GlobalObject
from zope.configuration.config import ConfigurationMachine
-from zope.app.component.site import LocalSiteManager
import martian
from martian import scan
from martian.error import GrokError
-import grok
-from grok import components, meta
-
-
-class IGrokDirective(interface.Interface):
+class IGrokDirective(Interface):
"""Grok a package or module."""
- package = zope.configuration.fields.GlobalObject(
+ package = GlobalObject(
title=u"Package",
description=u"The package or module to be analyzed by grok.",
required=False,
)
-_bootstrapped = False
-def bootstrap():
- component.provideAdapter(components.ModelTraverser)
- component.provideAdapter(components.ContainerTraverser)
-
- # register the name 'index' as the default view name
- component.provideAdapter('index',
- adapts=(grok.Model, IBrowserRequest),
- provides=IDefaultViewName)
- component.provideAdapter('index',
- adapts=(grok.Container, IBrowserRequest),
- provides=IDefaultViewName)
- # register a subscriber for when grok.Sites are added to make them
- # into Zope 3 sites
- component.provideHandler(
- addSiteHandler, adapts=(grok.Site, grok.IObjectAddedEvent))
-
- # now grok the grokkers
- martian.grok_module(scan.module_info_from_module(meta), the_module_grokker)
-
-def addSiteHandler(site, event):
- sitemanager = LocalSiteManager(site)
- # LocalSiteManager creates the 'default' folder in its __init__.
- # It's not needed anymore in new versions of Zope 3, therefore we
- # remove it
- del sitemanager['default']
- site.setSiteManager(sitemanager)
-
# add a cleanup hook so that grok will bootstrap itself again whenever
# the Component Architecture is torn down.
def resetBootstrap():
- global _bootstrapped
# we need to make sure that the grokker registry is clean again
the_module_grokker.clear()
- _bootstrapped = False
from zope.testing.cleanup import addCleanUp
addCleanUp(resetBootstrap)
@@ -91,10 +48,6 @@
do_grok(package.__name__, _context)
def do_grok(dotted_name, config):
- global _bootstrapped
- if not _bootstrapped:
- bootstrap()
- _bootstrapped = True
martian.grok_dotted_name(
dotted_name, the_module_grokker, exclude_filter=skip_tests,
config=config
More information about the Checkins
mailing list