[pitivi] formatters: Fix validateSourceURI and use it in the formatters.
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi] formatters: Fix validateSourceURI and use it in the formatters.
- Date: Tue, 21 Apr 2009 12:11:22 -0400 (EDT)
commit d35d3dee75344e3f3c50fdd3d6ee0ed61242e208
Author: Edward Hervey <bilboed bilboed com>
Date: Tue Apr 21 18:04:14 2009 +0200
formatters: Fix validateSourceURI and use it in the formatters.
FIXME : Add support for it in the ui, by listening to 'missing-uri'
---
pitivi/formatters/base.py | 14 ++++++++++----
pitivi/formatters/etree.py | 11 ++++++++---
pitivi/formatters/playlist.py | 5 ++++-
pitivi/utils.py | 2 ++
4 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/pitivi/formatters/base.py b/pitivi/formatters/base.py
index 61b4419..278b97e 100644
--- a/pitivi/formatters/base.py
+++ b/pitivi/formatters/base.py
@@ -280,23 +280,29 @@ class Formatter(object, Signallable, Loggable):
returned.
@rtype: C{URI} or C{None}
"""
+ self.debug("uri:%s", uri)
if not uri_is_valid(uri):
+ self.warning("invalid URI")
return None
# skip non local uri
if not uri.split('://', 1)[0] in ["file"]:
+ self.warning("We can only handle file:// URI")
return uri
# first check the good old way
- if not uri_is_valid(uri) or not uri_is_reachable(uri):
- return None
+ if uri_is_valid(uri) and uri_is_reachable(uri):
+ self.debug("URI is reachable")
+ return uri
+
+ self.debug("URI might have moved...")
localpath = uri.split('://', 1)[1]
# else let's figure out if we have a compatible mapping
for k, v in self.directorymapping.iteritems():
if localpath.startswith(k):
- return localpath.replace(k, v, 1)
+ return uri.replace(k, v, 1)
# else, let's fire the signal...
self.emit('missing-uri', uri)
@@ -304,7 +310,7 @@ class Formatter(object, Signallable, Loggable):
# and check again
for k, v in self.directorymapping.iteritems():
if localpath.startswith(k):
- return localpath.replace(k, v, 1)
+ return uri.replace(k, v, 1)
# Houston, we have lost contact with mission://fail
return None
diff --git a/pitivi/formatters/etree.py b/pitivi/formatters/etree.py
index 2d437ad..142b6bb 100644
--- a/pitivi/formatters/etree.py
+++ b/pitivi/formatters/etree.py
@@ -159,10 +159,13 @@ class ElementTreeFormatter(Formatter):
def _loadObjectFactory(self, klass, element):
self.debug("klass:%r, element:%r", klass, element)
# FIXME
+ filename = self.validateSourceURI(element.attrib.get("filename", None))
+ if not filename:
+ return None
if issubclass(klass, FileSourceFactory):
- factory = FileSourceFactory(element.attrib["filename"])
+ factory = FileSourceFactory(filename)
else:
- factory = klass()
+ factory = klass(filename)
factory.duration = long(element.attrib["duration"])
factory.default_duration = long(element.attrib["default_duration"])
@@ -207,7 +210,9 @@ class ElementTreeFormatter(Formatter):
def _loadFactories(self, factories, klass):
res = []
for fact in factories:
- res.append(self._loadObjectFactory(klass, fact))
+ obj = self._loadObjectFactory(klass, fact)
+ if obj:
+ res.append(obj)
return res
def _loadSources(self):
diff --git a/pitivi/formatters/playlist.py b/pitivi/formatters/playlist.py
index 9d9667c..5711420 100644
--- a/pitivi/formatters/playlist.py
+++ b/pitivi/formatters/playlist.py
@@ -48,7 +48,10 @@ class PlaylistFormatter(LoadOnlyFormatter):
# simple list of location/uri
f = file(path)
for ln in f.readlines():
- res.append(self._parseLine(ln))
+ val = self.validateSourceURI(self._parseLine(ln))
+ # FIXME : if the loading failed, we should insert a blank source
+ if val:
+ res.append(val)
self._uris = res
def _getSources(self):
diff --git a/pitivi/utils.py b/pitivi/utils.py
index e521b89..9338529 100644
--- a/pitivi/utils.py
+++ b/pitivi/utils.py
@@ -199,6 +199,8 @@ def filter_(caps):
def uri_is_valid(uri):
"""Checks if the given uri is a valid uri (of type file://)
+ Will also check if the size is valid (> 0).
+
@param uri: The location to check
@type uri: C{URI}
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]