[Checkins] SVN: grok/trunk/ Catalog components now live in grokcore.catalog. This is __unfinished__

Souheil Chelfouh cvs-admin at zope.org
Sat Apr 28 10:57:07 UTC 2012


Log message for revision 125358:
  Catalog components now live in grokcore.catalog. This is __unfinished__
  
  

Changed:
  U   grok/trunk/buildout.cfg
  U   grok/trunk/setup.py
  U   grok/trunk/src/grok/__init__.py
  U   grok/trunk/src/grok/components.py
  U   grok/trunk/src/grok/directive.py
  U   grok/trunk/src/grok/ftests/catalog/indexes_app_interface.py
  D   grok/trunk/src/grok/index.py
  U   grok/trunk/src/grok/interfaces.py
  U   grok/trunk/src/grok/meta.py
  U   grok/trunk/src/grok/meta.zcml
  U   grok/trunk/src/grok/testing.py

-=-
Modified: grok/trunk/buildout.cfg
===================================================================
--- grok/trunk/buildout.cfg	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/buildout.cfg	2012-04-28 10:57:01 UTC (rev 125358)
@@ -16,9 +16,12 @@
 
 [sources]
 zope.errorview = svn http://svn.zope.org/repos/main/zope.errorview/trunk
+grokcore.catalog = svn http://svn.zope.org/repos/main/grokcore.catalog/trunk
+grokcore.site = svn http://svn.zope.org/repos/main/grokcore.site/trunk
 
 [versions]
 grok =
+grokcore.catalog =
 
 [interpreter]
 recipe = z3c.recipe.scripts

Modified: grok/trunk/setup.py
===================================================================
--- grok/trunk/setup.py	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/setup.py	2012-04-28 10:57:01 UTC (rev 125358)
@@ -57,6 +57,7 @@
         'grokcore.viewlet >= 1.3',
         'grokcore.view [security_publication]',
         'grokcore.xmlrpc',
+        'grokcore.catalog',
         'martian >= 0.14',
         'pytz',
         'setuptools',

Modified: grok/trunk/src/grok/__init__.py
===================================================================
--- grok/trunk/src/grok/__init__.py	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/src/grok/__init__.py	2012-04-28 10:57:01 UTC (rev 125358)
@@ -32,6 +32,7 @@
 from grokcore.component.directive import provides, direct
 from grokcore.component.directive import global_utility, global_adapter
 
+from grokcore.catalog import index
 from grokcore.content import Model, Container, OrderedContainer
 
 from grokcore.security import Permission
@@ -101,18 +102,21 @@
 from grok.components import AddFormPage, EditFormPage, DisplayFormPage
 from grok.components import ExceptionView, NotFoundView, UnauthorizedView
 from grok.components import XMLRPC, REST, JSON
-from grok.components import Indexes
+
 from grok.components import Role
-
+from grokcore.catalog import Indexes
 from grokcore.traverser import Traverser
 
 from grok.interfaces import IRESTSkinType, IRESTLayer
 from grok.interfaces import IApplicationInitializedEvent
 
+from grokcore.site import site
+from grokcore.rest import restskin
 from grokcore.traverser import traversable
-from grok.directive import (
-    permissions, site, restskin)
 
+# this will be moved to ... something else soon
+from grok.directive import permissions  
+
 # BBB These two functions are meant for test fixtures and should be
 # imported from grok.testing, not from grok.
 from grok.testing import grok, grok_component

Modified: grok/trunk/src/grok/components.py
===================================================================
--- grok/trunk/src/grok/components.py	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/src/grok/components.py	2012-04-28 10:57:01 UTC (rev 125358)
@@ -282,79 +282,27 @@
 class Layout(ViewSupportMixin, grokcore.layout.Layout):
     pass
 
+
 class Page(ViewSupportMixin, grokcore.layout.Page):
     pass
 
+
 class FormPage(ViewSupportMixin, grokcore.layout.FormPage):
     pass
 
+
 class AddFormPage(ViewSupportMixin, grokcore.layout.AddFormPage):
     pass
 
+
 class EditFormPage(ViewSupportMixin, grokcore.layout.EditFormPage):
     pass
 
+
 class DisplayFormPage(ViewSupportMixin, grokcore.layout.DisplayFormPage):
     pass
 
 
-class IndexesClass(object):
-    """Base class for index collections in a Grok application.
-
-    A `grok.Indexes` utility provides one or more Zope Database
-    content indexes for use in a :class:`grok.Site` or
-    :class:`grok.Application`.  The site or application that the
-    indexes are intended for should be named with the :func:`grok.site()`
-    directive, and the kind of object to index should be named with a
-    :func:`grok.context()` directive.
-
-    Inside their class, the developer should specify one or more
-    :class:`grok.index.Field`, :class:`grok.index.Text`, or
-    :class:`grok.index.Set` instances naming object attributes that
-    should be indexed (and therefore searchable).::
-
-        class ArticleIndex(grok.Indexes):
-            grok.site(Newspaper)
-            grok.context(Article)
-            author = index.Field()
-            title = index.Field()
-            body = index.Text()
-
-    See the :mod:`grok.index` module for more information on field
-    types.
-
-    .. note:: Indexes are persistent: they are stored in the Zope
-              database alongside the site or application that they
-              index.  They are created when the site or application is
-              first created (and made persistent), and so an
-              already-created site will not change just because the
-              definition of one of its :data:`grok.Indexes` changes;
-              it will either have to be deleted and re-created, or
-              some other operation performed to bring its indexes up
-              to date.
-
-    """
-    def __init__(self, name, bases=(), attrs=None):
-        if attrs is None:
-            return
-        indexes = {}
-        for name, value in attrs.items():
-            # Ignore everything that's not an index definition object
-            # except for values set by directives
-            if '.' in name:
-                setattr(self, name, value)
-                continue
-            if not interfaces.IIndexDefinition.providedBy(value):
-                continue
-            indexes[name] = value
-        self.__grok_indexes__ = indexes
-        # __grok_module__ is needed to make defined_locally() return True for
-        # inline templates
-        self.__grok_module__ = martian.util.caller_module()
-
-Indexes = IndexesClass('Indexes')
-
-
 class Role(securitypolicy_Role):
     """Base class for roles in Grok applications.
 

Modified: grok/trunk/src/grok/directive.py
===================================================================
--- grok/trunk/src/grok/directive.py	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/src/grok/directive.py	2012-04-28 10:57:01 UTC (rev 125358)
@@ -12,43 +12,14 @@
 #
 ##############################################################################
 """Grok directives.
-
-This module defines Grok directives: the markers that users place
-inside of their classes (and sometimes in their modules, too) to
-direct how Grok registers their components.  For example, the first
-directive defined below is `site`, which people programming Grok
-applications normally use like this::
-
-    class MyIndex(grok.Indexes):
-        grok.site(MySite)
-        ...
-
-If the set of directives in this module looks rather small, remember
-that most of the directives available in Grok actually come from the
-`grokcore` modules on which Grok depends, where they have been placed so
-that other projects can use them without having to pull in all of Grok.
-
 """
 
 import grok
 import martian
 import martian.util
 from grokcore.view.directive import TaggedValueStoreOnce
-from grokcore.rest.directive import restskin
 
 
-class site(martian.Directive):
-    """The `grok.site()` directive.
-
-    This directive is used when creating a `grok.Indexes` subclass, to
-    indicate the Grok site object for which the indexes should be built.
-
-    """
-    scope = martian.CLASS
-    store = martian.ONCE
-    validate = martian.validateInterfaceOrClass
-
-
 class permissions(martian.Directive):
     """The `grok.permissions()` directive.
 

Modified: grok/trunk/src/grok/ftests/catalog/indexes_app_interface.py
===================================================================
--- grok/trunk/src/grok/ftests/catalog/indexes_app_interface.py	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/src/grok/ftests/catalog/indexes_app_interface.py	2012-04-28 10:57:01 UTC (rev 125358)
@@ -61,21 +61,26 @@
 import grok
 from grok import index
 
+
 class IHerd(Interface):
     pass
 
+
 class Herd(grok.Container, grok.Application):
     grok.implements(IHerd)
 
+
 class Herd2(grok.Container, grok.Application):
     grok.implements(IHerd)
 
+
 class IMammoth(Interface):
     name = schema.TextLine(title=u'Name')
     age = schema.Int(title=u'Age')
     def message():
         """Message the mammoth has for the world."""
 
+
 class MammothIndexes(grok.Indexes):
     grok.site(IHerd)
     grok.context(IMammoth)
@@ -84,6 +89,7 @@
     age = index.Field()
     message = index.Text()
 
+
 class Mammoth(grok.Model):
     grok.implements(IMammoth)
 

Deleted: grok/trunk/src/grok/index.py
===================================================================
--- grok/trunk/src/grok/index.py	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/src/grok/index.py	2012-04-28 10:57:01 UTC (rev 125358)
@@ -1,120 +0,0 @@
-#############################################################################
-#
-# Copyright (c) 2007-2008 Zope Foundation 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.
-#
-##############################################################################
-"""Grok index definitions
-"""
-import sys
-
-from zope.interface import implements
-from zope.interface.interfaces import IMethod, IInterface
-
-from zope.catalog.field import FieldIndex
-from zope.catalog.text import TextIndex
-from zc.catalog.catalogindex import SetIndex, ValueIndex
-
-from martian.error import GrokError, GrokImportError
-from martian.util import frame_is_class
-
-from grok.interfaces import IIndexDefinition
-
-
-class IndexDefinition(object):
-    """The definition of a particular index in a :data:`grok.Indexes`
-    class.
-
-    This base class defines the actual behavior of
-    :class:`grok.index.Field` and the other kinds of attribute index
-    that Grok supports.  Upon our instantiation, we save every
-    parameter that we were passed; later, if an index actually needs
-    to be created (which is typically at the moment when a new
-    :class:`grok.Application` object is added to the Zope Database),
-    then our :meth:`setup()` method gets called.
-
-    The only parameter that is actually significant to us is `attribute`
-    which (optionally) defines the attribute we should index.  All other
-    parameters are simply passed along to the Zope index we create,
-    which interprets them as configuration details of its own.
-
-    Note that, since index creation (and thus a call to our
-    :meth:`setup()` method) currently occurs only during the creation
-    of a new Grok `Application` object in the Zope Database, the
-    presence of this declaration in Grok application code is nearly
-    always a no-op.
-
-    """
-    implements(IIndexDefinition)
-
-    index_class = None
-
-    def __init__(self, *args, **kw):
-        frame = sys._getframe(1)
-        if not frame_is_class(frame):
-            raise GrokImportError(
-                "%r can only be instantiated on class level." % self.__class__)
-        # store any extra parameters to pass to index later
-        self._args = args
-        self._attribute = kw.pop('attribute', None)
-        self._kw = kw
-
-    def setup(self, catalog, name, context, module_info):
-        # If the user supplied attribute= when instantiating us, we
-        # allow that value to override the attribute name under which we
-        # are actually stored inside of the `grok.Indexes` instance.
-        if self._attribute is not None:
-            field_name = self._attribute
-        else:
-            field_name = name
-
-        if IInterface.providedBy(context):
-            try:
-                method = context[field_name]
-            except KeyError:
-                raise GrokError("grok.Indexes in %r refers to an attribute or "
-                                "method %r on interface %r, but this does not "
-                                "exist." % (module_info.getModule(),
-                                            field_name, context), None)
-            call = IMethod.providedBy(method)
-        else:
-            call = callable(getattr(context, field_name, None))
-            context = None  # no interface lookup
-        catalog[name] = self.index_class(field_name=field_name,
-                                         interface=context,
-                                         field_callable=call,
-                                         *self._args, **self._kw)
-
-
-class Field(IndexDefinition):
-    """A :class:`grok.Indexes` index that matches against an entire field."""
-    index_class = FieldIndex
-
-
-class Text(IndexDefinition):
-    """A :class:`grok.Indexes` index supporting full-text searches of a
-    field."""
-    index_class = TextIndex
-
-
-class Set(IndexDefinition):
-    """A :class:`grok.Indexes` index supporting keyword searches of a field."""
-    index_class = SetIndex
-
-
-class Value(IndexDefinition):
-    """A :class:`grok.Indexes` index similar to, but more flexible than
-    :class:`grok.Field` index.
-
-    The index allows searches for documents that contain any of a set of
-    values; between a set of values; any (non-None) values; and any empty
-    values.
-    """
-    index_class = ValueIndex

Modified: grok/trunk/src/grok/interfaces.py
===================================================================
--- grok/trunk/src/grok/interfaces.py	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/src/grok/interfaces.py	2012-04-28 10:57:01 UTC (rev 125358)
@@ -58,7 +58,6 @@
     NotFoundView = interface.Attribute("Base class notfound exception views.")
     UnauthorizedView = interface.Attribute(
         "Base class unauthorized exception views.")
-    Indexes = interface.Attribute("Base class for catalog index definitions.")
     Role = interface.Attribute("Base class for roles.")
 
 
@@ -71,13 +70,7 @@
         """Specify the permissions that comprise a role.
         """
 
-    def site(class_or_interface):
-        """Specifies the site that an indexes definition is for.
 
-        It can only be used inside grok.Indexes subclasses.
-        """
-
-
 class IGrokEvents(interface.Interface):
 
     IObjectCreatedEvent = interface.Attribute("")

Modified: grok/trunk/src/grok/meta.py
===================================================================
--- grok/trunk/src/grok/meta.py	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/src/grok/meta.py	2012-04-28 10:57:01 UTC (rev 125358)
@@ -116,102 +116,3 @@
             args=(factory, provides, name),
             )
         return True
-
-
-class IndexesGrokker(martian.InstanceGrokker):
-    """Grokker for Grok index bundles."""
-    martian.component(components.IndexesClass)
-
-    def grok(self, name, factory, module_info, config, **kw):
-        site = grok.site.bind().get(factory)
-        context = grok.context.bind().get(factory, module_info.getModule())
-        catalog_name = grok.name.bind().get(factory)
-
-        if site is None:
-            raise GrokError("No site specified for grok.Indexes "
-                            "subclass in module %r. "
-                            "Use grok.site() to specify."
-                            % module_info.getModule(),
-                            factory)
-        indexes = getattr(factory, '__grok_indexes__', None)
-        if indexes is None:
-            return False
-
-        subscriber = IndexesSetupSubscriber(catalog_name, indexes,
-                                            context, module_info)
-        subscribed = (site, grok.IObjectAddedEvent)
-        config.action(
-            discriminator=None,
-            callable=component.provideHandler,
-            args=(subscriber, subscribed),
-            )
-        return True
-
-
-class IndexesSetupSubscriber(object):
-    """Helper that sets up indexes when their Grok site is created.
-
-    Each `grok.Indexes` class serves as an assertion that, whenever an
-    instance of its `grok.site()` is created, the given list of indexes
-    should be generated as well.  But a long period of time could elapse
-    between when the application starts (and its indexes are grokked),
-    and the moment, maybe days or weeks later, when a new instance of
-    that `grok.Site` is created.  Hence this `IndexesSetupSubscriber`:
-    it can be instantiated at grokking time with the index information,
-    and then registered with the Component Architecture as an event that
-    should be fired later, whenever the right kind of `grok.Site` is
-    instantiated.  At that point its `__call__` method is kicked off and
-    it makes sure the index catalogs get created properly.
-
-    """
-    def __init__(self, catalog_name, indexes, context, module_info):
-        self.catalog_name = catalog_name
-        self.indexes = indexes
-        self.context = context
-        self.module_info = module_info
-
-    def __call__(self, site, event):
-        # make sure we have an intids
-        self._createIntIds(site)
-        # get the catalog
-        catalog = self._createCatalog(site)
-        # now install indexes
-        for name, index in self.indexes.items():
-            try:
-                index.setup(catalog, name, self.context, self.module_info)
-            except DuplicationError:
-                raise GrokError(
-                    "grok.Indexes in module %r causes "
-                    "creation of catalog index %r in catalog %r, "
-                    "but an index with that name is already present." %
-                    (self.module_info.getModule(), name, self.catalog_name),
-                    None)
-
-    def _createCatalog(self, site):
-        """Create the catalog if needed and return it.
-
-        If the catalog already exists, return that.
-
-        """
-        catalog = zope.component.queryUtility(
-            ICatalog, name=self.catalog_name, context=site, default=None)
-        if catalog is not None:
-            return catalog
-        catalog = Catalog()
-        setupUtility = component.getUtility(
-            grokcore.site.interfaces.IUtilityInstaller)
-        setupUtility(site, catalog, ICatalog, name=self.catalog_name)
-        return catalog
-
-    def _createIntIds(self, site):
-        """Create intids if needed, and return it.
-        """
-        intids = zope.component.queryUtility(
-            IIntIds, context=site, default=None)
-        if intids is not None:
-            return intids
-        intids = IntIds()
-        setupUtility = component.getUtility(
-            grokcore.site.interfaces.IUtilityInstaller)
-        setupUtility(site, intids, IIntIds)
-        return intids

Modified: grok/trunk/src/grok/meta.zcml
===================================================================
--- grok/trunk/src/grok/meta.zcml	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/src/grok/meta.zcml	2012-04-28 10:57:01 UTC (rev 125358)
@@ -13,6 +13,7 @@
   <include package="grokcore.viewlet" file="meta.zcml" />
   <include package="grokcore.annotation" file="meta.zcml" />
   <include package="grokcore.site" file="meta.zcml" />
+  <include package="grokcore.catalog" file="meta.zcml" />
   <grok:grok package=".meta" />
 
 </configure>

Modified: grok/trunk/src/grok/testing.py
===================================================================
--- grok/trunk/src/grok/testing.py	2012-04-28 09:24:56 UTC (rev 125357)
+++ grok/trunk/src/grok/testing.py	2012-04-28 10:57:01 UTC (rev 125358)
@@ -39,6 +39,7 @@
     zcml.do_grok('grokcore.formlib.meta', config)
     zcml.do_grok('grokcore.annotation.meta', config)
     zcml.do_grok('grokcore.site.meta', config)
+    zcml.do_grok('grokcore.catalog.meta', config)
     zcml.do_grok('grokcore.traverser.meta', config)
     zcml.do_grok('grokcore.rest.meta', config)
     zcml.do_grok('grokcore.xmlrpc.meta', config)



More information about the checkins mailing list