[Zope-Checkins]
SVN: Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/
first working implementation
Andreas Jung
andreas at andreas-jung.com
Wed Jul 14 12:04:45 EDT 2004
Log message for revision 26528:
first working implementation
Changed:
U Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ProgressHandler.py
U Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ZCatalog.py
-=-
Modified: Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ProgressHandler.py
===================================================================
--- Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ProgressHandler.py 2004-07-14 15:49:08 UTC (rev 26527)
+++ Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ProgressHandler.py 2004-07-14 16:04:45 UTC (rev 26528)
@@ -15,7 +15,34 @@
$Id: ZCatalog.py 25050 2004-05-27 15:06:40Z chrisw $
"""
-class ProgressHandler:
+import time, sys
+
+class DefaultProgressHandler:
+ """ A simple progress handler """
+
+ def __init__(self, steps=100):
+ self._steps = steps
+
+ def init(self, ident, max):
+ self._ident = ident
+ self._max = max
+ self._start = time.time()
+ self.fp = sys.stdout
+ self.output('started')
+
+ def finish(self):
+ self.output('terminated. Duration: %0.2f seconds' % \
+ (time.time() -self._start))
+
+ def report(self, current, *args, **kw):
+ if current % self._steps == 0:
+ self.output('%d/%d (%.2f%%)' % (current, self._max, (100.0 * current / self._max)))
+
+ def output(self, text):
+ print >>self.fp, '%s: %s' % (self._ident, text)
+
+
+class ProgressMixin:
""" A simple machinery to provide progres informations for long running
ZCatalog operations like reindexing.
"""
@@ -23,11 +50,10 @@
def pg_register(self, handler=None):
self._v_pg_handler = handler
-
- def pg_init(self, max):
+ def pg_init(self, ident, max):
handler = getattr(self, '_v_pg_handler', None)
if not handler: return
- handler.init(max)
+ handler.init(ident, max)
def pg_finish(self):
handler = getattr(self, '_v_pg_handler', None)
Modified: Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ZCatalog.py
===================================================================
--- Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ZCatalog.py 2004-07-14 15:49:08 UTC (rev 26527)
+++ Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ZCatalog.py 2004-07-14 16:04:45 UTC (rev 26528)
@@ -38,6 +38,7 @@
import urllib, time, sys
import string,logging
from IZCatalog import IZCatalog
+from ProgressHandler import ProgressMixin, DefaultProgressHandler
LOG = logging.getLogger('Zope.ZCatalog')
@@ -56,7 +57,7 @@
return self.manage_main(self, REQUEST,update_menu=1)
-class ZCatalog(Folder, Persistent, Implicit):
+class ZCatalog(Folder, Persistent, Implicit, ProgressMixin):
"""ZCatalog object
A ZCatalog contains arbirary index like references to Zope
@@ -463,13 +464,23 @@
def reindexIndex(self, name, REQUEST):
if isinstance(name, str):
name = (name,)
- for p in self._catalog.uids.keys():
+
+ paths = self._catalog.uids.keys()
+ num_paths = len(paths) # inefficient
+
+ i = 0
+ self.pg_register(DefaultProgressHandler(steps=10))
+ self.pg_init('reindexing %s' % name, num_paths)
+
+ for p in paths:
+ i+=1
+ self.pg_report(i)
obj = self.resolve_path(p)
if not obj:
obj = self.resolve_url(p, REQUEST)
if obj is None:
LOG.error('reindexIndex could not resolve '
- 'an object from the uid %r.' % (uid))
+ 'an object from the uid %r.' % p)
else:
# don't update metadata when only reindexing a single
# index via the UI
@@ -487,6 +498,8 @@
DeprecationWarning)
self.catalog_object(obj, p, idxs=name)
+ self.pg_finish()
+
def manage_reindexIndex(self, ids=None, REQUEST=None, RESPONSE=None,
URL1=None):
"""Reindex indexe(s) from a ZCatalog"""
More information about the Zope-Checkins
mailing list