Skip to content

Commit

Permalink
- Recataloging a ZCatalog instance is now more safe and predictable.
Browse files Browse the repository at this point in the history
       Indexing errors are catched and logged. In addition the progress of the
       recataloging operation is logged. So one can see how much documents are
       already processed and how much documents are remaining.
  • Loading branch information
zopyx committed May 13, 2004
1 parent 993ec3a commit b82fb5a
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions ZCatalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
##############################################################################
""" ZCatalog product
$Id: ZCatalog.py,v 1.130 2004/03/19 13:25:34 andreasjung Exp $
$Id: ZCatalog.py,v 1.126.2.4 2004/05/13 18:11:16 andreasjung Exp $
"""

from Globals import DTMLFile, MessageDialog
Expand All @@ -31,12 +31,14 @@
from AccessControl.Permissions import \
manage_zcatalog_entries, manage_zcatalog_indexes, search_zcatalog
from ZCatalogIndexes import ZCatalogIndexes
from ZODB.POSException import ConflictError
from Products.PluginIndexes.common.PluggableIndex \
import PluggableIndexInterface
from Products.PluginIndexes.TextIndex import Splitter
import urllib, time, types
import string
import urllib, time, sys
import string, logging
from IZCatalog import IZCatalog
from zLOG import LOG, INFO, BLATHER


manage_addZCatalogForm=DTMLFile('dtml/addZCatalog',globals())
Expand All @@ -55,6 +57,8 @@ def manage_addZCatalog(self, id, title,


class ZCatalog(Folder, Persistent, Implicit):
__implements__ = IZCatalog

"""ZCatalog object
A ZCatalog contains arbirary index like references to Zope
Expand All @@ -73,8 +77,6 @@ class is that it is not Zope specific. You can use it in any
Python program to catalog objects.
"""

__implements__ = IZCatalog

meta_type = "ZCatalog"
icon='misc_/ZCatalog/ZCatalog.gif'
Expand Down Expand Up @@ -213,7 +215,7 @@ def manage_subbingToggle(self, REQUEST, RESPONSE, URL1):
def manage_catalogObject(self, REQUEST, RESPONSE, URL1, urls=None):
""" index Zope object(s) that 'urls' point to """
if urls:
if isinstance(urls, types.StringType):
if isinstance(urls, str):
urls=(urls,)

for url in urls:
Expand All @@ -232,7 +234,7 @@ def manage_uncatalogObject(self, REQUEST, RESPONSE, URL1, urls=None):
""" removes Zope object(s) 'urls' from catalog """

if urls:
if isinstance(urls, types.StringType):
if isinstance(urls, str):
urls=(urls,)

for url in urls:
Expand Down Expand Up @@ -271,12 +273,26 @@ def refreshCatalog(self, clear=0):
paths = tuple(paths)
cat.clear()

for p in paths:
LOG('ZCatalog', BLATHER, 'Starting recataloging of ZCatalog at %s' %
self.absolute_url(1))
num_objects = len(paths)
for i in xrange(num_objects):
p = paths[i]
obj = self.resolve_path(p)
if not obj:
obj = self.resolve_url(p, self.REQUEST)
if obj is not None:
self.catalog_object(obj, p)
try:
LOG('ZCatalog', BLATHER, 'Recataloging object %s (%d/%d)' %
(p, i, num_objects))
self.catalog_object(obj, p)
except ConflictError:
raise
except:
LOG('ZCatalog', ERROR, 'Recataloging object at %s failed' % p,
error=sys.exc_info())

LOG('ZCatalog', BLATHER, 'Recataloging of ZCatalog at %s terminated' % self.absolute_url(1))

def manage_catalogClear(self, REQUEST=None, RESPONSE=None, URL1=None):
""" clears the whole enchilada """
Expand Down Expand Up @@ -363,7 +379,7 @@ def manage_delColumns(self, names, REQUEST=None, RESPONSE=None, URL1=None):

def manage_delColumn(self, names, REQUEST=None, RESPONSE=None, URL1=None):
""" delete a column or some columns """
if isinstance(names, types.StringType):
if isinstance(names, str):
names = (names,)

for name in names:
Expand Down Expand Up @@ -413,7 +429,7 @@ def manage_delIndex(self, ids=None, REQUEST=None, RESPONSE=None,
message='No items were specified!',
action = "./manage_catalogIndexes",)

if isinstance(ids, types.StringType):
if isinstance(ids, str):
ids = (ids,)

for name in ids:
Expand All @@ -433,7 +449,7 @@ def manage_clearIndex(self, ids=None, REQUEST=None, RESPONSE=None,
message='No items were specified!',
action = "./manage_catalogIndexes",)

if isinstance(ids, types.StringType):
if isinstance(ids, str):
ids = (ids,)

for name in ids:
Expand Down Expand Up @@ -477,7 +493,7 @@ def manage_reindexIndex(self, ids=None, REQUEST=None, RESPONSE=None,
message='No items were specified!',
action = "./manage_catalogIndexes",)

if isinstance(ids, types.StringType):
if isinstance(ids, str):
ids = (ids,)

for name in ids:
Expand Down Expand Up @@ -506,7 +522,7 @@ def catalog_object(self, obj, uid=None, idxs=None, update_metadata=1):
"method if no unique id is provided when cataloging"
)
else: uid='/'.join(uid())
elif not isinstance(uid,types.StringType):
elif not isinstance(uid,str):
raise CatalogError('The object unique id must be a string.')

self._catalog.catalogObject(obj, uid, None, idxs,
Expand Down

0 comments on commit b82fb5a

Please sign in to comment.