wingo - in flumotion/trunk: . doc/random flumotion/component flumotion/component/consumers/httpstreamer

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Mon Jun 25 15:31:41 CEST 2007


Author: wingo
Date: Mon Jun 25 15:31:37 2007
New Revision: 5238

Modified:
   flumotion/trunk/ChangeLog
   flumotion/trunk/doc/random/component-initialization-protocol
   flumotion/trunk/flumotion/component/component.py
   flumotion/trunk/flumotion/component/consumers/httpstreamer/http.py
Log:
2007-06-25  Andy Wingo  <wingo at pobox.com>

	* flumotion/component/consumers/httpstreamer/http.py
	(MultifdSinkStreamer.check_properties): Change to implement
	check_properties instead of do_check.

	* flumotion/component/component.py (BaseComponent.do_check): By
	default, call the check_properties vmethod.
	(BaseComponent.check_properties): New vmethod.
	(BaseComponent.setup): Rearrange some code; no semantic change.

	* doc/random/component-initialization-protocol (check_properties):
	New vmethod. Fixes #605.



Modified: flumotion/trunk/ChangeLog
==============================================================================
--- flumotion/trunk/ChangeLog	(original)
+++ flumotion/trunk/ChangeLog	Mon Jun 25 15:31:37 2007
@@ -1,3 +1,17 @@
+2007-06-25  Andy Wingo  <wingo at pobox.com>
+
+	* flumotion/component/consumers/httpstreamer/http.py
+	(MultifdSinkStreamer.check_properties): Change to implement
+	check_properties instead of do_check.
+
+	* flumotion/component/component.py (BaseComponent.do_check): By
+	default, call the check_properties vmethod.
+	(BaseComponent.check_properties): New vmethod.
+	(BaseComponent.setup): Rearrange some code; no semantic change.
+
+	* doc/random/component-initialization-protocol (check_properties):
+	New vmethod. Fixes #605.
+
 2007-06-25  Arek Korbik  <arkadini at gmail.com>
 
 	* flumotion/component/consumers/disker/disker.py

Modified: flumotion/trunk/doc/random/component-initialization-protocol
==============================================================================
--- flumotion/trunk/doc/random/component-initialization-protocol	(original)
+++ flumotion/trunk/doc/random/component-initialization-protocol	Mon Jun 25 15:31:37 2007
@@ -84,6 +84,17 @@
 All .init methods of every class in the hierarchy get called.
 This method is optional for subclasses.
 
+BaseComponent.check_properties(self, properties, addMessage)
+------------------------------------------------------------
+A helper vmethod called by the default implementation of do_check() that
+includes the properties in the arguments. The addMessage argument is a
+function that will call self.addMessage, additionally raising an
+exception if the message is of level ERROR.
+
+This procedure is called with twisted.internet.defer.maybeDeferred, so
+all exceptions thrown by this procedure will be caught, and it is
+acceptable (although not required) to return a deferred.
+
 BaseComponent.do_check(self)
 ----------------------------
 This method has no requirements. It is implementation-specific.

Modified: flumotion/trunk/flumotion/component/component.py
==============================================================================
--- flumotion/trunk/flumotion/component/component.py	(original)
+++ flumotion/trunk/flumotion/component/component.py	Mon Jun 25 15:31:37 2007
@@ -358,7 +358,33 @@
 
         @Returns: L{twisted.internet.defer.Deferred}
         """
-        return defer.succeed(None)
+        def addMessage(message):
+            self.addMessage(message)
+            if message.level == messages.ERROR:
+                raise errors.ComponentSetupHandledError(message.debug)
+
+        return defer.maybeDeferred(self.check_properties,
+                                   self.config['properties'],
+                                   addMessage)
+
+    def check_properties(self, properties, addMessage):
+        """
+        BaseComponent convenience vmethod for running checks.
+
+        A component implementation can override this method to run any
+        checks that it needs to. Typically, a check_properties
+        implementation will call the provided addMessage() callback to
+        note warnings or errors. For errors, addMessage() will abort the
+        check process, setting the mood to sad.
+
+        @param properties: The component's properties
+        @type properties: dict of string => object
+        @param addMessage: Thunk to add a message to the component
+                           state. Will raise an exception if the
+                           message is of level ERROR.
+        @type addMessage: L{flumotion.common.messages.Message} -> None
+        """
+        pass
 
     def do_setup(self):
         """
@@ -460,16 +486,6 @@
                 self.warning('Running checks made the component sad.')
                 raise errors.ComponentSetupHandledError()
 
-        self.debug("setup() called with config %r", config)
-        self.setMood(moods.waking)
-        self._setConfig(config)
-        # now we have a name, set it on the medium too
-        if self.medium:
-            self.medium.logName = self.getName()
-        d = setup_plugs()
-        d.addCallback(lambda r: self.do_check())
-        d.addCallback(checkErrorCallback)
-        d.addCallback(lambda r: self.do_setup())
         def setupErrback(failure):
             # pass through handled errors
             if failure.check(errors.ComponentSetupHandledError):
@@ -485,6 +501,16 @@
             raise errors.ComponentSetupHandledError(
                 'Could not set up component')
 
+        self.debug("setup() called with config %r", config)
+        self.setMood(moods.waking)
+        self._setConfig(config)
+        # now we have a name, set it on the medium too
+        if self.medium:
+            self.medium.logName = self.getName()
+        d = setup_plugs()
+        d.addCallback(lambda r: self.do_check())
+        d.addCallback(checkErrorCallback)
+        d.addCallback(lambda r: self.do_setup())
         d.addErrback(setupErrback)
         return d
 

Modified: flumotion/trunk/flumotion/component/consumers/httpstreamer/http.py
==============================================================================
--- flumotion/trunk/flumotion/component/consumers/httpstreamer/http.py	(original)
+++ flumotion/trunk/flumotion/component/consumers/httpstreamer/http.py	Mon Jun 25 15:31:37 2007
@@ -302,8 +302,7 @@
     def get_pipeline_string(self, properties):
         return self.pipe_template
 
-    def do_check(self):
-        props = self.config['properties']
+    def check_properties(self, props, addMessage):
 
         # F0.6: remove backwards-compatible properties
         self.fixRenamedProperties(props, [
@@ -321,12 +320,12 @@
         if props.get('type', 'master') == 'slave':
             for k in 'socket-path', 'username', 'password':
                 if not 'porter-' + k in props:
-                    msg = "slave mode, missing required property 'porter-%s'" % k
-                    return defer.fail(errors.ConfigError(msg))
+                    raise errors.ConfigError("slave mode, missing required"
+                                             " property 'porter-%s'" % k)
 
         if 'burst-size' in props and 'burst-time' in props:
-            msg = 'both burst-size and burst-time set, cannot satisfy'
-            return defer.fail(errors.ConfigError(msg))
+            raise errors.ConfigError('both burst-size and burst-time '
+                                     'set, cannot satisfy')
 
         # tcp is where multifdsink is
         version = gstreamer.get_plugin_version('tcp') 
@@ -336,12 +335,7 @@
                     ".".join(map(str, version)), 'multifdsink'))
             m.add(T_(N_("Please upgrade '%s' to version %s."),
                 'gst-plugins-base', '0.10.10'))
-            self.addMessage(m)
-            self.setMood(moods.sad)
-
-            return defer.fail(
-                errors.ComponentSetupHandledError(
-                    "multifdsink version not newer than 0.10.9.1"))
+            addMessage(m)
 
     def time_bursting_supported(self, sink):
         try:


More information about the flumotion-commit mailing list