[Checkins] SVN: zope.app.catalog/trunk/ version bump,
added new feature to prevent auto indexing - see
CHANGES.txt, fixed buildout to run ftests too,
added ftest dependencies, not svn tags in setup anymore
Bernd Dorn
bernd.dorn at lovelysystems.com
Fri Jun 22 05:36:59 EDT 2007
Log message for revision 76936:
version bump, added new feature to prevent auto indexing - see CHANGES.txt, fixed buildout to run ftests too, added ftest dependencies, not svn tags in setup anymore
Changed:
A zope.app.catalog/trunk/CHANGES.txt
U zope.app.catalog/trunk/buildout.cfg
D zope.app.catalog/trunk/setup.cfg
U zope.app.catalog/trunk/setup.py
U zope.app.catalog/trunk/src/zope/app/catalog/README.txt
U zope.app.catalog/trunk/src/zope/app/catalog/catalog.py
A zope.app.catalog/trunk/src/zope/app/catalog/event.txt
U zope.app.catalog/trunk/src/zope/app/catalog/interfaces.py
U zope.app.catalog/trunk/src/zope/app/catalog/tests.py
-=-
Added: zope.app.catalog/trunk/CHANGES.txt
===================================================================
--- zope.app.catalog/trunk/CHANGES.txt (rev 0)
+++ zope.app.catalog/trunk/CHANGES.txt 2007-06-22 09:36:58 UTC (rev 76936)
@@ -0,0 +1,10 @@
+============================
+Changes for zope.app.catalog
+============================
+
+After 3.4.0a2
+=============
+
+- Added marker interfaces to prevent automatic indexing (see:
+ event.txt)
+
Property changes on: zope.app.catalog/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: zope.app.catalog/trunk/buildout.cfg
===================================================================
--- zope.app.catalog/trunk/buildout.cfg 2007-06-22 08:52:12 UTC (rev 76935)
+++ zope.app.catalog/trunk/buildout.cfg 2007-06-22 09:36:58 UTC (rev 76936)
@@ -5,4 +5,5 @@
[test]
recipe = zc.recipe.testrunner
-eggs = zope.app.catalog
+defaults = ['--tests-pattern', '^f?tests$']
+eggs = zope.app.catalog [test]
Deleted: zope.app.catalog/trunk/setup.cfg
===================================================================
--- zope.app.catalog/trunk/setup.cfg 2007-06-22 08:52:12 UTC (rev 76935)
+++ zope.app.catalog/trunk/setup.cfg 2007-06-22 09:36:58 UTC (rev 76936)
@@ -1,2 +0,0 @@
-[egg_info]
-tag_svn_revision = 1
\ No newline at end of file
Modified: zope.app.catalog/trunk/setup.py
===================================================================
--- zope.app.catalog/trunk/setup.py 2007-06-22 08:52:12 UTC (rev 76935)
+++ zope.app.catalog/trunk/setup.py 2007-06-22 09:36:58 UTC (rev 76936)
@@ -21,7 +21,7 @@
from setuptools import setup, find_packages
setup(name = 'zope.app.catalog',
- version = '3.4.0a2',
+ version = '3.5.0a1',
url = 'http://svn.zope.org/zope.app.catalog',
license = 'ZPL 2.1',
description = 'Zope app.catalog',
@@ -50,6 +50,12 @@
'zope.traversing',
],
include_package_data = True,
-
+ extras_require = dict(test=['zope.testing',
+ 'zope.app.testing',
+ 'zope.app.securitypolicy',
+ 'zope.app.zcmlfiles',
+ 'zope.app.zptpage',
+ ]
+ ),
zip_safe = False,
)
Modified: zope.app.catalog/trunk/src/zope/app/catalog/README.txt
===================================================================
--- zope.app.catalog/trunk/src/zope/app/catalog/README.txt 2007-06-22 08:52:12 UTC (rev 76935)
+++ zope.app.catalog/trunk/src/zope/app/catalog/README.txt 2007-06-22 09:36:58 UTC (rev 76936)
@@ -302,3 +302,4 @@
The score increased because we used an additional index. If an index
doesn't provide scores, scores of 1.0 are assumed.
+
Modified: zope.app.catalog/trunk/src/zope/app/catalog/catalog.py
===================================================================
--- zope.app.catalog/trunk/src/zope/app/catalog/catalog.py 2007-06-22 08:52:12 UTC (rev 76935)
+++ zope.app.catalog/trunk/src/zope/app/catalog/catalog.py 2007-06-22 09:36:58 UTC (rev 76936)
@@ -26,7 +26,7 @@
from zope.app.container.interfaces import IContainer
from zope.app.container.btree import BTreeContainer
-from zope.app.catalog.interfaces import ICatalog
+from zope.app.catalog.interfaces import ICatalog, INoAutoIndex, INoAutoReindex
from zope.app.intid.interfaces import IIntIds
from zope.traversing.interfaces import IPhysicallyLocatable
from zope.location import location
@@ -163,16 +163,20 @@
def indexDocSubscriber(event):
"""A subscriber to IntIdAddedEvent"""
+ ob = event.object
+ if INoAutoIndex.providedBy(ob):
+ return
for cat in component.getAllUtilitiesRegisteredFor(ICatalog):
- ob = event.object
id = component.getUtility(IIntIds, context=cat).getId(ob)
cat.index_doc(id, ob)
def reindexDocSubscriber(event):
"""A subscriber to ObjectModifiedEvent"""
+ ob = event.object
+ if INoAutoReindex.providedBy(ob):
+ return
for cat in component.getAllUtilitiesRegisteredFor(ICatalog):
- ob = event.object
id = component.getUtility(IIntIds, context=cat).queryId(ob)
if id is not None:
cat.index_doc(id, ob)
Added: zope.app.catalog/trunk/src/zope/app/catalog/event.txt
===================================================================
--- zope.app.catalog/trunk/src/zope/app/catalog/event.txt (rev 0)
+++ zope.app.catalog/trunk/src/zope/app/catalog/event.txt 2007-06-22 09:36:58 UTC (rev 76936)
@@ -0,0 +1,86 @@
+==============================
+Automatic indexing with events
+==============================
+
+In order to automatically keep the catalog up-to-date any objects that
+are added to a intid utility are indexed automatically. Also when an
+object gets modified it is reindexed by listening to IObjectModified
+events.
+
+Let us create a fake catalog to demonstrate this behaviour. We only
+need to implement the index_doc method for this test.
+
+ >>> from zope.app.catalog.interfaces import ICatalog
+ >>> from zope import interface, component
+ >>> class FakeCatalog(object):
+ ... indexed = []
+ ... interface.implements(ICatalog)
+ ... def index_doc(self, docid, obj):
+ ... self.indexed.append((docid, obj))
+ >>> cat = FakeCatalog()
+ >>> component.provideUtility(cat)
+
+We also need an intid util and a keyreference adapter.
+
+ >>> from zope.app.intid import IntIds
+ >>> from zope.app.intid.interfaces import IIntIds
+ >>> intids = IntIds()
+ >>> component.provideUtility(intids, IIntIds)
+ >>> from zope.app.keyreference.testing import SimpleKeyReference
+ >>> component.provideAdapter(SimpleKeyReference)
+
+ >>> from zope.app.container.contained import Contained
+ >>> class Dummy(Contained):
+ ... def __init__(self, name):
+ ... self.__name__ = name
+ ... def __repr__(self):
+ ... return '<Dummy %r>' % self.__name__
+
+We have a subscriber to IIntidAddedEvent.
+
+ >>> from zope.app.catalog import catalog
+ >>> from zope.app.intid.interfaces import IntIdAddedEvent
+ >>> d1 = Dummy(u'one')
+ >>> id1 = intids.register(d1)
+ >>> catalog.indexDocSubscriber(IntIdAddedEvent(d1, None))
+
+Now we have indexed the object.
+
+ >>> cat.indexed.pop()
+ (..., <Dummy u'one'>)
+
+When an object is modified an objectmodified event should be fired by
+the application. Here is the handler for such an event.
+
+ >>> from zope.lifecycleevent import ObjectModifiedEvent
+ >>> catalog.reindexDocSubscriber(ObjectModifiedEvent(d1))
+ >>> len(cat.indexed)
+ 1
+ >>> cat.indexed.pop()
+ (..., <Dummy u'one'>)
+
+Preventing automatic indexing
+=============================
+
+Sometimes it is not accurate to automatically index an object. For
+example when a lot of indexes are in the catalog and only
+specific indexes needs to be updated. There are marker interfaces to
+achieve this.
+
+ >>> from zope.app.catalog.interfaces import INoAutoIndex
+
+If an object provides this interface it is not automatically indexed.
+
+ >>> interface.alsoProvides(d1, INoAutoIndex)
+ >>> catalog.indexDocSubscriber(IntIdAddedEvent(d1, None))
+ >>> len(cat.indexed)
+ 0
+
+ >>> from zope.app.catalog.interfaces import INoAutoReindex
+
+If an object provides this interface it is not automatically reindexed.
+
+ >>> interface.alsoProvides(d1, INoAutoReindex)
+ >>> catalog.reindexDocSubscriber(ObjectModifiedEvent(d1))
+ >>> len(cat.indexed)
+ 0
Property changes on: zope.app.catalog/trunk/src/zope/app/catalog/event.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: zope.app.catalog/trunk/src/zope/app/catalog/interfaces.py
===================================================================
--- zope.app.catalog/trunk/src/zope/app/catalog/interfaces.py 2007-06-22 08:52:12 UTC (rev 76935)
+++ zope.app.catalog/trunk/src/zope/app/catalog/interfaces.py 2007-06-22 09:36:58 UTC (rev 76936)
@@ -77,4 +77,12 @@
description=_(u"If true, then the field should be called to get the "
u"value to be indexed"),
)
-
+
+
+class INoAutoIndex(zope.interface.Interface):
+
+ """Marker for objects that should not be automatically indexed"""
+
+class INoAutoReindex(zope.interface.Interface):
+
+ """Marker for objects that should not be automatically reindexed"""
Modified: zope.app.catalog/trunk/src/zope/app/catalog/tests.py
===================================================================
--- zope.app.catalog/trunk/src/zope/app/catalog/tests.py 2007-06-22 08:52:12 UTC (rev 76935)
+++ zope.app.catalog/trunk/src/zope/app/catalog/tests.py 2007-06-22 09:36:58 UTC (rev 76936)
@@ -460,6 +460,10 @@
pass
+def setUp(test):
+ root = setup.placefulSetUp(True)
+ test.globs['root'] = root
+
def test_suite():
from zope.testing import doctest
suite = unittest.TestSuite()
@@ -474,6 +478,13 @@
setUp=placelesssetup.setUp,
tearDown=placelesssetup.tearDown,
))
+ suite.addTest(doctest.DocFileSuite(
+ 'event.txt',
+ setUp=setUp,
+ tearDown=lambda x: setup.placefulTearDown(),
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ ))
+
return suite
More information about the Checkins
mailing list