[pitivi: 24/65] Improve error message for non-existing and non-readable files



commit 74520f3e1a43b4b6b231013eed48e66385ea64b1
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Fri Jun 24 22:43:48 2011 -0400

    Improve error message for non-existing and non-readable files

 pitivi/discoverer.py     |   15 ++++++++++++++-
 tests/test_discoverer.py |    3 +--
 2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/pitivi/discoverer.py b/pitivi/discoverer.py
index 17445d7..8f37c14 100644
--- a/pitivi/discoverer.py
+++ b/pitivi/discoverer.py
@@ -25,7 +25,8 @@ Discover file multimedia information.
 """
 
 from gettext import gettext as _
-import os.path
+import os
+from urlparse import urlparse
 import gobject
 gobject.threads_init()
 import gst
@@ -402,6 +403,18 @@ class Discoverer(Signallable, Loggable):
         self.current_uri = self.queue[0]
         self.info("Analyzing %s", self.current_uri)
 
+        # check if file exists and is readable
+        if gst.uri_get_protocol(self.current_uri) == "file":
+            if not os.access(self.current_uri, os.F_OK):
+                self.error = _("File does not exist")
+            elif not os.access(self.current_uri, os.R_OK):
+                self.error = _("File not readable by current user")
+            
+            if self.error:
+                self.info("Error: %s", self.error)
+                self._finishAnalysis("File does not exist or is not readable by the current user")
+                return False
+
         # setup graph and start analyzing
         self.pipeline = gst.Pipeline("Discoverer-%s" % self.current_uri)
 
diff --git a/tests/test_discoverer.py b/tests/test_discoverer.py
index f639fd4..5910598 100644
--- a/tests/test_discoverer.py
+++ b/tests/test_discoverer.py
@@ -158,8 +158,7 @@ class TestAnalysis(TestCase):
             'really/have/a/file/named/like/this/you/deserve/a/faillure')
         self.discoverer.connect('discovery-error', no_media_file_cb)
         self.discoverer._analyze()
-        self.failUnlessEqual(bag['error'], 'Pipeline didn\'t want '
-                'to go to PAUSED.')
+        self.failUnlessEqual(bag['error'], 'File does not exist')
 
     def testSetTimeout(self):
         """



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]