[Checkins] SVN: GenericSetup/branches/wichert-events/ Add the event firing logic

Wichert Akkerman wichert at wiggy.net
Sun Nov 4 11:21:08 EST 2007


Log message for revision 81474:
  Add the event firing logic

Changed:
  U   GenericSetup/branches/wichert-events/CHANGES.txt
  A   GenericSetup/branches/wichert-events/events.py
  U   GenericSetup/branches/wichert-events/interfaces.py
  U   GenericSetup/branches/wichert-events/tool.py

-=-
Modified: GenericSetup/branches/wichert-events/CHANGES.txt
===================================================================
--- GenericSetup/branches/wichert-events/CHANGES.txt	2007-11-04 14:51:55 UTC (rev 81473)
+++ GenericSetup/branches/wichert-events/CHANGES.txt	2007-11-04 16:21:08 UTC (rev 81474)
@@ -2,6 +2,8 @@
 
   GenericSetup 1.4 (unreleased)
   
+    - Fire events before and after importing.
+
     - Use zcml to register import and export steps.
 
     - tool: Fixed toolset import handler not to initialize tools again, when

Added: GenericSetup/branches/wichert-events/events.py
===================================================================
--- GenericSetup/branches/wichert-events/events.py	                        (rev 0)
+++ GenericSetup/branches/wichert-events/events.py	2007-11-04 16:21:08 UTC (rev 81474)
@@ -0,0 +1,17 @@
+from zope.interface import implements
+from Products.GenericSetup.interfaces import IBeforeProfileImportEvent
+from Products.GenericSetup.interfaces import IProfileImportedEvent
+
+class BaseProfileImportEvent(object):
+    def __init__(self, profile_id, steps, full_import):
+        self.profile_id=profile_id
+        self.steps=steps
+        self.full_import=full_import
+
+
+class BeforeProfileImportEvent(BaseProfileImportEvent):
+    implements(IBeforeProfileImportEvent)
+
+
+class ProfileImportedEvent(BaseProfileImportEvent):
+    implements(IProfileImportedEvent)


Property changes on: GenericSetup/branches/wichert-events/events.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GenericSetup/branches/wichert-events/interfaces.py
===================================================================
--- GenericSetup/branches/wichert-events/interfaces.py	2007-11-04 14:51:55 UTC (rev 81473)
+++ GenericSetup/branches/wichert-events/interfaces.py	2007-11-04 16:21:08 UTC (rev 81474)
@@ -15,6 +15,7 @@
 $Id$
 """
 
+from zope.interface import Attribute
 from zope.interface import Interface
 from zope.schema import Text
 from zope.schema import TextLine
@@ -811,3 +812,23 @@
           method, whose headers (e.g., "Content-Type") may affect the
           processing of the body.
         """
+
+class IBeforeProfileImportEvent(Interface):
+    """ An event which is fired before (part of) a profile is imported.
+    """
+    profile_id = Attribute("id of the profile to be imported or None for non-profile imports.")
+
+    steps = Attribute("list of steps that will be imported")
+
+    full_import = Attribute("True if all steps will be imported")
+
+
+class IProfileImportedEvent(Interface):
+    """ An event which is fired when (part of) a profile is imported.
+    """
+    profile_id = Attribute("id of the imported profile")
+
+    steps = Attribute("list of steps have been imported")
+
+    full_import = Attribute("True if all steps are imported")
+

Modified: GenericSetup/branches/wichert-events/tool.py
===================================================================
--- GenericSetup/branches/wichert-events/tool.py	2007-11-04 14:51:55 UTC (rev 81473)
+++ GenericSetup/branches/wichert-events/tool.py	2007-11-04 16:21:08 UTC (rev 81474)
@@ -30,12 +30,15 @@
 from ZODB.POSException import ConflictError
 from zope.interface import implements
 from zope.interface import implementedBy
+from zope import event 
 
 from interfaces import BASE
 from interfaces import EXTENSION
 from interfaces import ISetupTool
 from interfaces import SKIPPED_FILES
 from permissions import ManagePortal
+from events import BeforeProfileImportEvent
+from events import ProfileImportedEvent
 from context import DirectoryImportContext
 from context import SnapshotImportContext
 from context import TarballExportContext
@@ -321,22 +324,28 @@
 
         messages = {}
         steps = []
+
         if run_dependencies:
             for dependency in dependencies:
-
                 if dependency not in steps:
-                    message = self._doRunImportStep(dependency, context)
-                    messages[dependency] = message or ''
                     steps.append(dependency)
+        steps.append (step_id)
 
-        message = self._doRunImportStep(step_id, context)
+        full_import=(set(steps)==set(self.getSortedImportSteps()))
+        event.notify(BeforeProfileImportEvent(profile_id, steps, full_import))
+
+        for step in steps:
+            message = self._doRunImportStep(step, context)
+            messages[step] = message or ''
+
         message_list = filter(None, [message])
         message_list.extend( ['%s: %s' % x[1:] for x in context.listNotes()] )
         messages[step_id] = '\n'.join(message_list)
-        steps.append(step_id)
 
         self._import_context_id = old_context
 
+        event.notify(ProfileImportedEvent(profile_id, steps, full_import))
+
         return { 'steps' : steps, 'messages' : messages }
 
     security.declareProtected(ManagePortal, 'runImportStep')
@@ -363,7 +372,7 @@
         old_context = self._import_context_id
         context = self._getImportContext(profile_id, purge_old)
 
-        result = self._runImportStepsFromContext(context, purge_old=purge_old)
+        result = self._runImportStepsFromContext(context, purge_old=purge_old, profile_id=profile_id)
         prefix = 'import-all-%s' % profile_id.replace(':', '_')
         name = self._mangleTimestampName(prefix, 'log')
         self._createReport(name, result['steps'], result['messages'])
@@ -1059,13 +1068,14 @@
                }
 
     security.declarePrivate('_runImportStepsFromContext')
-    def _runImportStepsFromContext(self, context, steps=None, purge_old=None):
+    def _runImportStepsFromContext(self, context, steps=None, purge_old=None, profile_id=None):
         self.applyContext(context)
 
         if steps is None:
             steps = self.getSortedImportSteps()
         messages = {}
 
+        event.notify(BeforeProfileImportEvent(profile_id, steps, True))
         for step in steps:
             message = self._doRunImportStep(step, context)
             message_list = filter(None, [message])
@@ -1074,6 +1084,8 @@
             messages[step] = '\n'.join(message_list)
             context.clearNotes()
 
+        event.notify(ProfileImportedEvent(profile_id, steps, True))
+
         return { 'steps' : steps, 'messages' : messages }
 
     security.declarePrivate('_mangleTimestampName')



More information about the Checkins mailing list