[Zope-Checkins]
SVN: Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ProgressHandler.py
added interface
Andreas Jung
andreas at andreas-jung.com
Thu Jul 15 11:50:51 EDT 2004
Log message for revision 26556:
added interface
Changed:
U Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ProgressHandler.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-15 15:28:02 UTC (rev 26555)
+++ Zope/branches/ajung-zcatalog-progress/lib/python/Products/ZCatalog/ProgressHandler.py 2004-07-15 15:50:51 UTC (rev 26556)
@@ -18,9 +18,39 @@
import time, sys
from zLOG import LOG, INFO
+from Interface import Interface
+
+class IProgressHandler(Interface):
+ """ A handler to log progress informations for long running
+ operations.
+ """
+
+ def init(ident, max):
+ """ Called add the start of the long running process.
+
+ 'ident' -- a string identifying the operation
+ 'max' -- maximum number of objects to be processed
+ """
+
+ def finish():
+ """ Called up terminiation """
+
+ def report(current, *args, **kw):
+ """ Called for every iteration.
+
+ 'current' -- an integer representing the number of objects
+ processed so far.
+ """
+
+ def output(text):
+ """ Log 'text' to some output channel """
+
+
class StdoutHandler:
""" A simple progress handler """
+ __implements__ = IProgressHandler
+
def __init__(self, steps=100):
self._steps = steps
@@ -29,10 +59,10 @@
self._max = max
self._start = time.time()
self.fp = sys.stdout
- self.output('started')
+ self.output('Process started')
def finish(self):
- self.output('terminated. Duration: %0.2f seconds' % \
+ self.output('Process terminated. Duration: %0.2f seconds' % \
(time.time() -self._start))
def report(self, current, *args, **kw):
@@ -46,6 +76,8 @@
class ZLogHandler(StdoutHandler):
""" Use zLOG """
+ __implements__ = IProgressHandler
+
def output(self, text):
LOG(self._ident, INFO, text)
More information about the Zope-Checkins
mailing list