r6245 - in flumotion/trunk: . flumotion/component/consumers/httpstreamer flumotion/component/encoders/jpeg flumotion/component/encoders/speex flumotion/component/encoders/theora flumotion/component/encoders/vorbis flumotion/component/misc/cortado flumotion/test flumotion/wizard

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Mon Feb 18 14:10:06 CET 2008


Author: jdahlin
Date: Mon Feb 18 14:10:01 2008
New Revision: 6245

Log:
2008-02-18  Johan Dahlin  <jdahlin at async.com.br>

    * flumotion/test/test_wizard_models.py:
    * flumotion/wizard/models.py:
    Map underscore to dashes for attribute accesses.
    This simplifies the getProperties() implementations as a side effect.

    * flumotion/component/consumers/httpstreamer/http_wizard.py:
    * flumotion/component/encoders/jpeg/jpeg_wizard.py:
    * flumotion/component/encoders/speex/speex_wizard.py:
    * flumotion/component/encoders/theora/theora_wizard.py:
    * flumotion/component/encoders/vorbis/vorbis_wizard.py:
    * flumotion/component/misc/cortado/cortado_wizard.py:
    * flumotion/wizard/overlaystep.py:
    * flumotion/wizard/save.py:
    We can use attributes instead of the uglier dictionary interface now.



Modified:
   flumotion/trunk/ChangeLog
   flumotion/trunk/flumotion/component/consumers/httpstreamer/http_wizard.py
   flumotion/trunk/flumotion/component/encoders/jpeg/jpeg_wizard.py
   flumotion/trunk/flumotion/component/encoders/speex/speex_wizard.py
   flumotion/trunk/flumotion/component/encoders/theora/theora_wizard.py
   flumotion/trunk/flumotion/component/encoders/vorbis/vorbis_wizard.py
   flumotion/trunk/flumotion/component/misc/cortado/cortado_wizard.py
   flumotion/trunk/flumotion/test/test_wizard_models.py
   flumotion/trunk/flumotion/wizard/models.py
   flumotion/trunk/flumotion/wizard/overlaystep.py
   flumotion/trunk/flumotion/wizard/save.py

Modified: flumotion/trunk/ChangeLog
==============================================================================
--- flumotion/trunk/ChangeLog	(original)
+++ flumotion/trunk/ChangeLog	Mon Feb 18 14:10:01 2008
@@ -1,3 +1,20 @@
+2008-02-18  Johan Dahlin  <jdahlin at async.com.br>
+
+	* flumotion/test/test_wizard_models.py:
+	* flumotion/wizard/models.py:
+	Map underscore to dashes for attribute accesses.
+	This simplifies the getProperties() implementations as a side effect.
+
+	* flumotion/component/consumers/httpstreamer/http_wizard.py:
+	* flumotion/component/encoders/jpeg/jpeg_wizard.py:
+	* flumotion/component/encoders/speex/speex_wizard.py:
+	* flumotion/component/encoders/theora/theora_wizard.py:
+	* flumotion/component/encoders/vorbis/vorbis_wizard.py:
+	* flumotion/component/misc/cortado/cortado_wizard.py:
+	* flumotion/wizard/overlaystep.py:
+	* flumotion/wizard/save.py:
+	We can use attributes instead of the uglier dictionary interface now.
+
 2008-02-15  Johan Dahlin  <johan at gnome.org>
 
 	* configure.ac:

Modified: flumotion/trunk/flumotion/component/consumers/httpstreamer/http_wizard.py
==============================================================================
--- flumotion/trunk/flumotion/component/consumers/httpstreamer/http_wizard.py	(original)
+++ flumotion/trunk/flumotion/component/consumers/httpstreamer/http_wizard.py	Mon Feb 18 14:10:01 2008
@@ -79,7 +79,7 @@
     def getProperties(self):
         properties = super(HTTPPorter, self).getProperties()
         # FIXME: kiwi should do this.
-        properties['port'] = int(properties['port'])
+        properties.port = int(properties.port)
         return properties
 
 
@@ -118,20 +118,20 @@
     def getProperties(self):
         properties = super(HTTPStreamer, self).getProperties()
         if self.has_bandwidth_limit:
-            properties['bandwidth-limit'] = int(
-                properties['bandwidth-limit'] * 1e6)
+            properties.bandwidth_limit = int(
+                properties.bandwidth_limit * 1e6)
         else:
-            del properties['bandwidth-limit']
+            del properties.bandwidth_limit
 
         if not self.has_client_limit:
-            del properties['client-limit']
+            del properties.client_limit
 
         if self.has_plugins:
-            properties['porter-socket-path'] = self.socket_path
-            properties['porter-username'] = self.porter_username
-            properties['porter-password'] = self.porter_password
-            properties['type'] = 'slave'
-            del properties['port']
+            properties.porter_socket_path = self.socket_path
+            properties.porter_username = self.porter_username
+            properties.porter_password = self.porter_password
+            properties.type = 'slave'
+            del properties.port
 
         return properties
 

Modified: flumotion/trunk/flumotion/component/encoders/jpeg/jpeg_wizard.py
==============================================================================
--- flumotion/trunk/flumotion/component/encoders/jpeg/jpeg_wizard.py	(original)
+++ flumotion/trunk/flumotion/component/encoders/jpeg/jpeg_wizard.py	Mon Feb 18 14:10:01 2008
@@ -47,7 +47,7 @@
 
     def getProperties(self):
         properties = super(JPEGVideoEncoder, self).getProperties()
-        properties['framerate'] = _fraction_from_float(properties['framerate'], 2)
+        properties.framerate = _fraction_from_float(properties.framerate, 2)
         return properties
 
 

Modified: flumotion/trunk/flumotion/component/encoders/speex/speex_wizard.py
==============================================================================
--- flumotion/trunk/flumotion/component/encoders/speex/speex_wizard.py	(original)
+++ flumotion/trunk/flumotion/component/encoders/speex/speex_wizard.py	Mon Feb 18 14:10:01 2008
@@ -38,7 +38,7 @@
 
     def getProperties(self):
         properties = super(SpeexAudioEncoder, self).getProperties()
-        properties['bitrate'] *= 1000
+        properties.bitrate *= 1000
         return properties
 
 

Modified: flumotion/trunk/flumotion/component/encoders/theora/theora_wizard.py
==============================================================================
--- flumotion/trunk/flumotion/component/encoders/theora/theora_wizard.py	(original)
+++ flumotion/trunk/flumotion/component/encoders/theora/theora_wizard.py	Mon Feb 18 14:10:01 2008
@@ -45,15 +45,15 @@
     def getProperties(self):
         properties = super(TheoraVideoEncoder, self).getProperties()
         if self.has_bitrate:
-            del properties['quality']
-            properties['bitrate'] *= 1000
+            del properties.quality
+            properties.bitrate *= 1000
         elif self.has_quality:
-            del properties['bitrate']
+            del properties.bitrate
         else:
             raise AssertionError
 
-        properties['noise-sensitivity'] = max(
-            int(properties['noise-sensitivity'] * (32768 / 100.)),  1)
+        properties.noise_sensitivity = max(
+            int(properties.noise_sensitivity * (32768 / 100.)),  1)
 
         return properties
 

Modified: flumotion/trunk/flumotion/component/encoders/vorbis/vorbis_wizard.py
==============================================================================
--- flumotion/trunk/flumotion/component/encoders/vorbis/vorbis_wizard.py	(original)
+++ flumotion/trunk/flumotion/component/encoders/vorbis/vorbis_wizard.py	Mon Feb 18 14:10:01 2008
@@ -42,10 +42,10 @@
     def getProperties(self):
         properties = super(VorbisAudioEncoder, self).getProperties()
         if self.has_bitrate:
-            del properties['quality']
-            properties['bitrate'] *= 1000
+            del properties.quality
+            properties.bitrate *= 1000
         elif self.has_quality:
-            del properties['bitrate']
+            del properties.bitrate
         else:
             raise AssertionError
 

Modified: flumotion/trunk/flumotion/component/misc/cortado/cortado_wizard.py
==============================================================================
--- flumotion/trunk/flumotion/component/misc/cortado/cortado_wizard.py	(original)
+++ flumotion/trunk/flumotion/component/misc/cortado/cortado_wizard.py	Mon Feb 18 14:10:01 2008
@@ -39,10 +39,10 @@
     def getProperties(self):
         p = super(CortadoHTTPPlug, self).getProperties()
 
-        p['codebase'] = self.server.getCodebase()
-        p['stream-url'] = self.streamer.getURL()
-        p['has-video'] = self.video_producer is not None
-        p['has-audio'] = self.audio_producer is not None
+        p.codebase = self.server.getCodebase()
+        p.stream_url = self.streamer.getURL()
+        p.has_video = self.video_producer is not None
+        p.has_audio = self.audio_producer is not None
 
         if self.video_producer:
             width = self.video_producer.properties.width
@@ -53,10 +53,10 @@
             height = 240
             framerate = 1
 
-        p['width'] = width
-        p['height'] = height
-        p['framerate'] = framerate
-        p['buffer-size'] = 40
+        p.width = width
+        p.height = height
+        p.framerate = framerate
+        p.buffer_size = 40
 
         return p
 

Modified: flumotion/trunk/flumotion/test/test_wizard_models.py
==============================================================================
--- flumotion/trunk/flumotion/test/test_wizard_models.py	(original)
+++ flumotion/trunk/flumotion/test/test_wizard_models.py	Mon Feb 18 14:10:01 2008
@@ -88,7 +88,7 @@
     def setUp(self):
         self.props = Properties()
 
-    def testInsertItem(self):
+    def testSetItem(self):
         self.props['foo'] = 10
 
         self.failUnless(self.props)
@@ -99,7 +99,19 @@
         self.failUnless('foo' in self.props)
         self.assertEquals(self.props['foo'], 10)
 
-    def testInsertAttribute(self):
+    def testSetItemUnderscore(self):
+        self.props['foo-bar'] = 10
+
+        self.failUnless(self.props)
+
+        self.failUnless(hasattr(self.props, 'foo_bar'))
+        self.assertEquals(self.props.foo_bar, 10)
+
+        self.failUnless('foo-bar' in self.props)
+        self.failIf('foo_bar' in self.props)
+        self.assertEquals(self.props['foo-bar'], 10)
+
+    def testSetAttribute(self):
         self.props.foo = 10
 
         self.failUnless(self.props)
@@ -110,6 +122,18 @@
         self.failUnless('foo' in self.props)
         self.assertEquals(self.props['foo'], 10)
 
+    def testSetAttributeUnderscore(self):
+        self.props.foo_bar = 10
+
+        self.failUnless(self.props)
+
+        self.failUnless(hasattr(self.props, 'foo_bar'))
+        self.assertEquals(self.props.foo_bar, 10)
+
+        self.failUnless('foo-bar' in self.props)
+        self.failIf('foo_bar' in self.props)
+        self.assertEquals(self.props['foo-bar'], 10)
+
     def testDeleteItem(self):
         self.props.foo = 10
 
@@ -118,6 +142,14 @@
         self.failIf(hasattr(self.props, 'foo'))
         self.failIf('foo' in self.props)
 
+    def testDeleteItemUnderscore(self):
+        self.props.foo_bar = 10
+
+        del self.props['foo-bar']
+
+        self.failIf(hasattr(self.props, 'foo_bar'))
+        self.failIf('foo-bar' in self.props)
+
     def testDeleteAttribute(self):
         self.props.foo = 10
 
@@ -126,7 +158,14 @@
         self.failIf(hasattr(self.props, 'foo'))
         self.failIf('foo' in self.props)
 
-    def testInsertInvalid(self):
+    def testDeleteAttributeUnderscore(self):
+        self.props.foo_bar = 10
+        del self.props.foo_bar
+
+        self.failIf(hasattr(self.props, 'foo_bar'))
+        self.failIf('foo-bar' in self.props)
+
+    def testSetInvalid(self):
         self.assertRaises(AttributeError,
                           self.props.__setattr__, 'update', 10)
         self.failIf(self.props)

Modified: flumotion/trunk/flumotion/wizard/models.py
==============================================================================
--- flumotion/trunk/flumotion/wizard/models.py	(original)
+++ flumotion/trunk/flumotion/wizard/models.py	Mon Feb 18 14:10:01 2008
@@ -27,8 +27,7 @@
 
 
 class Properties(dict):
-    """
-    I am a special dictionary which you also can treat as an instance.
+    """I am a special dictionary which you also can treat as an instance.
     Setting and getting an attribute works.
     This is suitable for using in a kiwi proxy.
     >>> p = Properties()
@@ -38,14 +37,13 @@
 
     Note that you cannot insert the attributes which has the same name
     as dictionary methods, such as 'keys', 'values', 'items', 'update'.
-    """
-    def __setattr__(self, attr, value):
-        if attr in dict.__dict__:
-            raise AttributeError(
-                "Cannot set property %r, it's a dictionary attribute"
-                % (attr,))
-        self[attr] = value
 
+    Underscores are converted to dashes when setting attributes, eg:
+
+    >>> p.this_is_outrageous = True
+    >>> p
+    <Properties {'this-is-outrageous': True}>
+    """
     def __setitem__(self, attr, value):
         if attr in dict.__dict__:
             raise AttributeError(
@@ -53,7 +51,11 @@
                 % (attr,))
         dict.__setitem__(self, attr, value)
 
+    def __setattr__(self, attr, value):
+        self[attr.replace('_', '-')] = value
+
     def __getattr__(self, attr):
+        attr = attr.replace('_', '-')
         try:
             return self[attr]
         except KeyError:
@@ -62,7 +64,7 @@
                 self, attr))
 
     def __delattr__(self, attr):
-        del self[attr]
+        del self[attr.replace('_', '-')]
 
     def __repr__(self):
         return '<Properties %r>' % (dict.__repr__(self),)
@@ -172,10 +174,7 @@
         return self.worker
 
     def getProperties(self):
-        props = {}
-        for key, value in self.properties.iteritems():
-            props[key.replace('_', '-')] = value
-        return props
+        return self.properties
 
     def getPlugs(self):
         return self.plugs
@@ -200,10 +199,7 @@
         self.properties = Properties()
 
     def getProperties(self):
-        props = {}
-        for key, value in self.properties.iteritems():
-            props[key.replace('_', '-')] = value
-        return props
+        return self.properties
 
 
 class Producer(Component):

Modified: flumotion/trunk/flumotion/wizard/overlaystep.py
==============================================================================
--- flumotion/trunk/flumotion/wizard/overlaystep.py	(original)
+++ flumotion/trunk/flumotion/wizard/overlaystep.py	Mon Feb 18 14:10:01 2008
@@ -55,10 +55,10 @@
         p = super(Overlay, self).getProperties()
 
         if not self.show_text:
-            del p['text']
+            del p.text
 
-        p['width'] = self._video_producer.getWidth()
-        p['height'] = self._video_producer.getHeight()
+        p.width = self._video_producer.getWidth()
+        p.height = self._video_producer.getHeight()
 
         return p
 

Modified: flumotion/trunk/flumotion/wizard/save.py
==============================================================================
--- flumotion/trunk/flumotion/wizard/save.py	(original)
+++ flumotion/trunk/flumotion/wizard/save.py	Mon Feb 18 14:10:01 2008
@@ -238,15 +238,15 @@
 
         # At this point we already know that we should overlay something
         if overlay.show_logo:
-            properties['fluendo-logo'] = True
+            properties.fluendo_logo = True
             encoding_step = self.wizard.get_step('Encoding')
             if encoding_step.get_muxer_type() == 'ogg-muxer':
-                properties['xiph-logo'] = True
+                properties.xiph_logo = True
 
             license_options = self.wizard.get_step_options('Content License')
             if (license_options['set-license'] and
                 license_options['license'] == LicenseType.CC):
-                properties['cc-logo'] = True
+                properties.cc_logo = True
 
         return Component('overlay-video',
                          overlay.component_type,


More information about the flumotion-commit mailing list