[pitivi] Make registering formatters a bit more dynamic.
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi] Make registering formatters a bit more dynamic.
- Date: Fri, 5 Jun 2009 11:38:30 -0400 (EDT)
commit 4bd620b367be4aa8a9f403ff3c3b234651f04fd2
Author: Alessandro Decina <alessandro d gmail com>
Date: Thu Jun 4 15:45:12 2009 +0200
Make registering formatters a bit more dynamic.
Add pitivi.format.register_formatter so i can register dummy formatters in unit
tests.
---
pitivi/formatters/format.py | 46 ++++++++++++++-----------------------------
pitivi/project.py | 4 ++-
2 files changed, 18 insertions(+), 32 deletions(-)
diff --git a/pitivi/formatters/format.py b/pitivi/formatters/format.py
index 1a2d48c..3be2233 100644
--- a/pitivi/formatters/format.py
+++ b/pitivi/formatters/format.py
@@ -27,29 +27,7 @@ from gettext import gettext as _
# FIXME : We need a registry of all available formatters
-def load_project(uri, formatter=None, missinguricallback=None):
- """
- Load the project from the given location.
-
- If specified, use the given formatter.
-
- @type uri: L{str}
- @param uri: The location of the project. Needs to be an
- absolute URI.
- @type formatter: L{Formatter}
- @param formatter: If specified, try loading the project with that
- L{Formatter}. If not specified, will try all available L{Formatter}s.
- @raise FormatterLoadError: If the location couldn't be properly loaded.
- @param missinguricallback: A callback that will be used if some
- files to load can't be found anymore. The callback shall call the
- formatter's addMapping() method with the moved location.
- @type missinguricallback: C{callable}
- @return: The project. The caller needs to ensure the loading is
- finished before using it. See the 'loaded' property and signal of
- L{Project}.
- @rtype: L{Project}.
- """
- raise NotImplementedError
+_formatters = []
def save_project(project, uri, formatter=None, overwrite=False):
"""
@@ -90,7 +68,7 @@ def can_handle_location(uri):
@rtype: L{bool}
"""
- for klass, name, exts in list_formats():
+ for klass, name, exts in _formatters:
if klass.canHandle(uri):
return True
@@ -102,12 +80,7 @@ def list_formats():
file formats, where name is a user-readable name, and extensions is a
sequence of extensions for this format ('.' omitted).
"""
- from pitivi.formatters.etree import ElementTreeFormatter
- from pitivi.formatters.playlist import PlaylistFormatter
- return [
- (ElementTreeFormatter, _("PiTiVi Native (XML)"), ('xptv',)),
- (PlaylistFormatter, _("Playlist format"), ('pls', ))
- ]
+ return _formatters
def get_formatter_for_uri(uri):
"""
@@ -117,6 +90,17 @@ def get_formatter_for_uri(uri):
@param uri: The location of the project file
@return: an instance of a Formatter, or None
"""
- for klass, name, exts in list_formats():
+ for klass, name, exts in _formatters:
if klass.canHandle(uri):
return klass()
+
+def register_formatter(klass, name, extensions):
+ _formatters.append((klass, name, extensions))
+
+# register known formatters
+
+from pitivi.formatters.etree import ElementTreeFormatter
+from pitivi.formatters.playlist import PlaylistFormatter
+
+register_formatter(ElementTreeFormatter, _("PiTiVi Native (XML)"), ('xptv',))
+register_formatter(PlaylistFormatter, _("Playlist format"), ('pls', ))
diff --git a/pitivi/project.py b/pitivi/project.py
index c3a1b76..a7ad77c 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -39,7 +39,6 @@ from pitivi.settings import ExportSettings
from pitivi.configure import APPNAME
from pitivi.signalinterface import Signallable
from pitivi.action import ViewAction
-from pitivi.formatters.format import save_project
class ProjectError(Exception):
"""Project error"""
@@ -194,6 +193,9 @@ class Project(Signallable, Loggable):
@raises ProjectSaveLoadError: If no uri was provided and none was set
previously.
"""
+ # import here to break circular import
+ from pitivi.formatters.format import save_project
+
self.log("saving...")
location = location or self.uri
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]