[pitivi: 39/65] Clarify when an argument needs to be passed when an ObjectFactory is instantiated in ElementTreeForm
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi: 39/65] Clarify when an argument needs to be passed when an ObjectFactory is instantiated in ElementTreeForm
- Date: Mon, 4 Jul 2011 01:22:30 +0000 (UTC)
commit 934b1704ad70f685d9e716af4daaac98bd5b35ed
Author: Alex BÄluÈ <alexandru balut gmail com>
Date: Fri Jun 10 23:21:52 2011 +0200
Clarify when an argument needs to be passed when an ObjectFactory is instantiated in ElementTreeFormatter._loadObjectFactory
This change was suggested by the FIXME I removed.
pitivi/formatters/etree.py | 33 ++++++++++++++++++++-------------
1 files changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/pitivi/formatters/etree.py b/pitivi/formatters/etree.py
index 1e41d2c..7183f20 100644
--- a/pitivi/formatters/etree.py
+++ b/pitivi/formatters/etree.py
@@ -156,8 +156,10 @@ class ElementTreeFormatter(Formatter):
def _loadFactory(self, element):
klass = namedAny(element.attrib["type"])
-
- return self._loadObjectFactory(klass, element)
+ assert issubclass(klass, SourceFactory)
+ factory = self._loadObjectFactory(klass, element)
+ self._context.factories[element.attrib["id"]] = factory
+ return factory
def _saveObjectFactory(self, factory):
element = Element("source")
@@ -183,18 +185,23 @@ class ElementTreeFormatter(Formatter):
return element
def _loadObjectFactory(self, klass, element):
+ """Instantiate the specified class and set its attributes.
+
+ @param klass: An ObjectFactory subclass.
+ @param element: The Element representing the object to be created.
+ @return: An instance of the specified klass.
+ """
self.debug("klass:%r, element:%r", klass, element)
- # FIXME : we should check if the given ObjectFactory
- # requires a filename !
- filename = element.attrib.get("filename", None)
- if filename is not None:
+ # Instantiate the class.
+ args = []
+ if issubclass(klass, FileSourceFactory):
+ filename = element.attrib.get("filename")
if isinstance(filename, unicode):
filename = filename.encode("utf-8")
+ args.append(filename)
+ factory = klass(*args)
- factory = klass(filename)
- else:
- factory = klass()
-
+ # Set the attributes of the instance.
factory.duration = long(element.attrib["duration"])
factory.default_duration = long(element.attrib["default_duration"])
@@ -210,13 +217,13 @@ class ElementTreeFormatter(Formatter):
stream = self._loadStream(stream_element)
factory.addOutputStream(stream)
- if filename is not None:
+ if issubclass(klass, FileSourceFactory):
filename1 = self.validateSourceURI(filename, factory)
if filename != filename1:
# the file was moved
- factory.uri = factory.filename = filename1
+ factory.uri = filename1
+ factory.filename = filename1
- self._context.factories[element.attrib["id"]] = factory
return factory
def _saveFileSourceFactory(self, element, source):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]