Index: /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/catalogupdater.py
===================================================================
--- /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/catalogupdater.py (revision 3141)
+++ /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/catalogupdater.py (revision 3142)
@@ -37,5 +37,5 @@
self._logger.info('Updating %s columns for %s Catalog.' % (
- updatecols, '/'.join(catalog.getPhysicalPath())) )
+ updatecols, '/'.join(catalog.getPhysicalPath())))
cu = queryUtility(ICatalogUpdater, name='catalog_updater')
Index: /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/tests/test_catalogupdate.py
===================================================================
--- /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/tests/test_catalogupdate.py (revision 3141)
+++ /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/exportimport/tests/test_catalogupdate.py (revision 3142)
@@ -39,5 +39,4 @@
""" % (PLONEFOUR and '' or \
'')
-
@@ -47,5 +46,5 @@
def updateMetadata4All(self, catalog, columns):
self._logger.info("%s:%s" % (catalog.id, columns))
-
+
class CatalogUpdaterZCMLLayer(test_exportimport.ZCatalogXMLAdapterTests.layer):
@@ -65,5 +64,6 @@
def _getTargetClass(self):
- from quintagroup.catalogupdater.exportimport.catalogupdater import CatalogUpdaterXMLAdapter
+ from quintagroup.catalogupdater.exportimport.catalogupdater \
+ import CatalogUpdaterXMLAdapter
return CatalogUpdaterXMLAdapter
@@ -78,5 +78,5 @@
def getLastMessage(self):
messages = getattr(self.logger, '_messages', [])
- return messages[-1] or [None,]*3
+ return messages[-1] or [None, ] * 3
def test_body_set_update(self):
@@ -90,6 +90,7 @@
message = self.getLastMessage()
- self.assertEqual( message[-1], "foo_catalog:['eggs', 'spam']",
- "Not updated columns in catalog" )
+ self.assertEqual(message[-1], "foo_catalog:['eggs', 'spam']",
+ "Not updated columns in catalog")
+
def test_suite():
Index: /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/interfaces.py
===================================================================
--- /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/interfaces.py (revision 3141)
+++ /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/interfaces.py (revision 3142)
@@ -1,3 +1,4 @@
from zope.interface import Interface
+
class IUpdatableCatalog(Interface):
@@ -5,4 +6,5 @@
exportimport handler
"""
+
class ICatalogUpdater(Interface):
@@ -17,3 +19,2 @@
metadata, which must be updated.
"""
-
Index: /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/tests.py
===================================================================
--- /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/tests.py (revision 3141)
+++ /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/tests.py (revision 3142)
@@ -5,6 +5,4 @@
from zope.component import queryUtility
from zope.component import provideAdapter
-
-from Testing import ZopeTestCase as ztc
from Products.Five import zcml
@@ -37,9 +35,11 @@
ptc.setupPloneSite()
+
class TestUtility(TestCase):
def afterSetUp(self):
self.loginAsPortalOwner()
- self.my_doc = makeContent(self.portal, portal_type='Document', id='my_doc')
+ self.my_doc = makeContent(self.portal, portal_type='Document',
+ id='my_doc')
self.catalog = getToolByName(self.portal, 'portal_catalog')
self.logout()
@@ -51,5 +51,4 @@
self.catalog.addColumn('test_column')
-
def addIndexerNew(self):
@indexer(Interface)
@@ -58,10 +57,8 @@
provideAdapter(test_column, name='test_column')
-
def addIndexerOld(self):
def test_column(obj, portal, **kwargs):
return obj.id
registerIndexableAttribute("test_column", test_column)
-
def testSingleColumnUpdate(self):
@@ -93,5 +90,5 @@
self.assertTrue(mydoc.Title == "My document", mydoc.Title)
- self.my_doc.setTitle('New my document') # catalog not updated
+ self.my_doc.setTitle('New my document') # catalog not updated
cu = queryUtility(ICatalogUpdater, name="catalog_updater")
cu.updateMetadata4All(self.catalog, 'test_column')
@@ -100,5 +97,4 @@
self.assertTrue(mydoc.Title == 'My document',
"Other metadata updated: Title='%s'" % mydoc.Title)
-
def testAllRecordsUpdate(self):
@@ -110,9 +106,8 @@
num_recs = len(self.catalog._catalog.data)
allcat = self.catalog.unrestrictedSearchResults(path='/')
- num_updated = sum([1 for b in allcat if b.test_column==b.id])
+ num_updated = sum([1 for b in allcat if b.test_column == b.id])
self.assertTrue(num_updated == num_recs, "Only %d records updated, " \
"must be - %d" % (num_updated, num_recs))
-
def testTransaction(self):
@@ -121,6 +116,7 @@
# savepoint patch
global sp_commits
- sp_commits = 1 # Starts from 1 to count last commit
+ sp_commits = 1 # Starts from 1 to count last commit
orig_trsp = transaction.savepoint
+
def dummy_savepoint(*args, **kwargs):
global sp_commits
@@ -132,15 +128,14 @@
num_recs = len(self.catalog.unrestrictedSearchResults(path='/'))
num_subcommits = 3
- self.catalog.threshold = num_recs/num_subcommits
+ self.catalog.threshold = num_recs / num_subcommits
cu = queryUtility(ICatalogUpdater, name="catalog_updater")
cu.updateMetadata4All(self.catalog, 'test_column')
- self.assertTrue(sp_commits == num_subcommits,
- "Wrong number of transaction subcommits: actual:%d, must be: %d" % (
- sp_commits, num_subcommits))
+ self.assertTrue(sp_commits == num_subcommits, "Wrong number of " \
+ "transaction subcommits: actual:%d, must be: %d" % (sp_commits,
+ num_subcommits))
transaction.savepoint = orig_trsp
-
Index: /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/utility.py
===================================================================
--- /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/utility.py (revision 3141)
+++ /quintagroup.catalogupdater/trunk/quintagroup/catalogupdater/utility.py (revision 3142)
@@ -1,3 +1,4 @@
-import logging, types
+import logging
+import types
import transaction
from zope.interface import implements
@@ -6,5 +7,4 @@
from Missing import MV
-from Acquisition import aq_inner
from Acquisition import aq_parent
@@ -18,5 +18,5 @@
as _old_IIndexableObjectWrapper
IS_NEW = False
-else:
+else:
IS_NEW = True
@@ -33,5 +33,6 @@
def validate(self, cat, cols):
# Validate catalog and column name
- AVAIL_COLTYPES = list(types.StringTypes) + [types.ListType, types.TupleType]
+ AVAIL_COLTYPES = list(types.StringTypes) + [types.ListType,
+ types.TupleType]
_cat = getattr(cat, '_catalog', None)
@@ -40,16 +41,16 @@
if not type(cols) in AVAIL_COLTYPES:
- raise TypeError("'columns' parameter must be one of the following " \
- "types: %s" % AVAIL_COLTYPES)
+ raise TypeError("'columns' parameter must be one of the " \
+ "following types: %s" % AVAIL_COLTYPES)
# Normalize columns
if type(cols) in types.StringTypes:
- cols = [cols,]
+ cols = [cols, ]
# Check is every column present in the catalog
for col in cols:
- if not _cat.schema.has_key(col):
- raise AttributeError("'%s' - not presented column in %s catalog " % (col, cat))
+ if not col in _cat.schema:
+ raise AttributeError("'%s' - not presented column in " \
+ "%s catalog " % (col, cat))
return _cat, cols
-
def getWrappedObjectNew(self, obj, portal, catalog):
@@ -57,6 +58,7 @@
wrapper = None
if not IIndexableObject.providedBy(obj):
- # This is the CMF 2.2 compatible approach, which should be used going forward
- wrapper = queryMultiAdapter((obj, catalog), IIndexableObject)
+ # This is the CMF 2.2 compatible approach,
+ # which should be used going forward
+ wrapper = queryMultiAdapter((obj, catalog), IIndexableObject)
return wrapper and wrapper or obj
@@ -72,10 +74,9 @@
else:
vars = {}
-
+
w = getMultiAdapter((obj, portal), _old_IIndexableObjectWrapper)
w.update(vars)
return w
-
def updateMetadata4All(self, catalog, columns):
@@ -87,9 +88,10 @@
portal = getToolByName(catalog, 'portal_url').getPortalObject()
root = aq_parent(portal)
-
+
data = _catalog.data
schema = _catalog.schema
paths = _catalog.paths
- getWrappedObject = IS_NEW and self.getWrappedObjectNew or self.getWrappedObjectOld
+ getWrappedObject = (IS_NEW and self.getWrappedObjectNew
+ or self.getWrappedObjectOld)
# For subtransaction support
threshold = getattr(catalog, 'threshold', 10000)
@@ -112,6 +114,7 @@
for column in columns:
# calculate the column value
- attr=getattr(obj, column, MV)
- if(attr is not MV and safe_callable(attr)): attr=attr()
+ attr = getattr(obj, column, MV)
+ if (attr is not MV and safe_callable(attr)):
+ attr = attr()
# Update metadata value
indx = schema[column]
@@ -134,3 +137,2 @@
_v_total = 0
LOG.info('commiting subtransaction')
-
Index: /quintagroup.catalogupdater/trunk/setup.py
===================================================================
--- /quintagroup.catalogupdater/trunk/setup.py (revision 3141)
+++ /quintagroup.catalogupdater/trunk/setup.py (revision 3142)
@@ -9,5 +9,4 @@
long_description=open("README.txt").read() + "\n" +
open(os.path.join("docs", "HISTORY.txt")).read(),
- # Get more strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
"Framework :: Plone",