[Checkins] SVN: GenericSetup/trunk/ Include the tool itself in the event so event handlers have some context to work with. This is necessary when you need to pass data from the BeforeProfileImportEvent to the ProfileImportedEvent handlers: this allows them to annotate the request which can be gotten through tool.REQUEST.

Wichert Akkerman wichert at wiggy.net
Sun Nov 4 13:56:59 EST 2007


Log message for revision 81478:
  Include the tool itself in the event so event handlers have some context to work with. This is necessary when you need to pass data from the BeforeProfileImportEvent to the ProfileImportedEvent handlers: this allows them to annotate the request which can be gotten through tool.REQUEST.

Changed:
  U   GenericSetup/trunk/events.py
  U   GenericSetup/trunk/interfaces.py
  U   GenericSetup/trunk/tests/test_events.py
  U   GenericSetup/trunk/tool.py

-=-
Modified: GenericSetup/trunk/events.py
===================================================================
--- GenericSetup/trunk/events.py	2007-11-04 18:49:49 UTC (rev 81477)
+++ GenericSetup/trunk/events.py	2007-11-04 18:56:59 UTC (rev 81478)
@@ -3,7 +3,8 @@
 from Products.GenericSetup.interfaces import IProfileImportedEvent
 
 class BaseProfileImportEvent(object):
-    def __init__(self, profile_id, steps, full_import):
+    def __init__(self, tool, profile_id, steps, full_import):
+        self.tool=tool
         self.profile_id=profile_id
         self.steps=steps
         self.full_import=full_import

Modified: GenericSetup/trunk/interfaces.py
===================================================================
--- GenericSetup/trunk/interfaces.py	2007-11-04 18:49:49 UTC (rev 81477)
+++ GenericSetup/trunk/interfaces.py	2007-11-04 18:56:59 UTC (rev 81478)
@@ -822,7 +822,9 @@
 
     full_import = Attribute("True if all steps will be imported")
 
+    tool = Attribute("The tool which is performing the import")
 
+
 class IProfileImportedEvent(Interface):
     """ An event which is fired when (part of) a profile is imported.
     """
@@ -832,3 +834,5 @@
 
     full_import = Attribute("True if all steps are imported")
 
+    tool = Attribute("The tool which is performing the import")
+

Modified: GenericSetup/trunk/tests/test_events.py
===================================================================
--- GenericSetup/trunk/tests/test_events.py	2007-11-04 18:49:49 UTC (rev 81477)
+++ GenericSetup/trunk/tests/test_events.py	2007-11-04 18:56:59 UTC (rev 81478)
@@ -7,17 +7,19 @@
 
 class BaseEventTests(unittest.TestCase):
     def testInterface(self):
-        event=self.klass("profile_id", "steps", "full_import")
+        event=self.klass("tool", "profile_id", "steps", "full_import")
         verifyObject(self.iface, event)
 
     def testNormalConstruction(self):
-        event=self.klass("profile_id", "steps", "full_import")
+        event=self.klass("tool", "profile_id", "steps", "full_import")
+        self.assertEqual(event.tool, "tool")
         self.assertEqual(event.profile_id, "profile_id")
         self.assertEqual(event.steps, "steps")
         self.assertEqual(event.full_import, "full_import")
 
     def testKeywordConstruction(self):
-        event=self.klass(profile_id="profile_id", steps="steps", full_import="full_import")
+        event=self.klass(tool="tool", profile_id="profile_id", steps="steps", full_import="full_import")
+        self.assertEqual(event.tool, "tool")
         self.assertEqual(event.profile_id, "profile_id")
         self.assertEqual(event.steps, "steps")
         self.assertEqual(event.full_import, "full_import")

Modified: GenericSetup/trunk/tool.py
===================================================================
--- GenericSetup/trunk/tool.py	2007-11-04 18:49:49 UTC (rev 81477)
+++ GenericSetup/trunk/tool.py	2007-11-04 18:56:59 UTC (rev 81478)
@@ -332,7 +332,7 @@
         steps.append (step_id)
 
         full_import=(set(steps)==set(self.getSortedImportSteps()))
-        event.notify(BeforeProfileImportEvent(profile_id, steps, full_import))
+        event.notify(BeforeProfileImportEvent(self, profile_id, steps, full_import))
 
         for step in steps:
             message = self._doRunImportStep(step, context)
@@ -344,7 +344,7 @@
 
         self._import_context_id = old_context
 
-        event.notify(ProfileImportedEvent(profile_id, steps, full_import))
+        event.notify(ProfileImportedEvent(self, profile_id, steps, full_import))
 
         return { 'steps' : steps, 'messages' : messages }
 
@@ -1075,7 +1075,7 @@
             steps = self.getSortedImportSteps()
         messages = {}
 
-        event.notify(BeforeProfileImportEvent(profile_id, steps, True))
+        event.notify(BeforeProfileImportEvent(self, profile_id, steps, True))
         for step in steps:
             message = self._doRunImportStep(step, context)
             message_list = filter(None, [message])
@@ -1084,7 +1084,7 @@
             messages[step] = '\n'.join(message_list)
             context.clearNotes()
 
-        event.notify(ProfileImportedEvent(profile_id, steps, True))
+        event.notify(ProfileImportedEvent(self, profile_id, steps, True))
 
         return { 'steps' : steps, 'messages' : messages }
 



More information about the Checkins mailing list