MountStorage: Better error reporting
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 3 Aug 2011 21:13:58 +0000 (23:13 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 3 Aug 2011 21:13:58 +0000 (23:13 +0200)
Created a new resolver frontend function, that raises and
error, when no backend is found. Useful for all the
wrappers.

mediagoblin/storage.py

index abbe16c9c8864edeec33cb4c6086331525a4d7fd..f9d2c3eab9c4c6ff1027e456766bf38f8537bd33 100644 (file)
@@ -227,7 +227,7 @@ class MountStorage(StorageInterface):
         new_ent = clean_listy_filepath(dirpath)
 
         print "Mounting:", repr(new_ent)
-        already, rem_1, table, rem_2 = self.resolve_to_backend(new_ent, True)
+        already, rem_1, table, rem_2 = self._resolve_to_backend(new_ent, True)
         print "===", repr(already), repr(rem_1), repr(rem_2)
 
         assert (already is None) or (len(rem_2) > 0), "Already mounted"
@@ -237,7 +237,7 @@ class MountStorage(StorageInterface):
         assert not table.has_key(None), "Huh? Already mounted?!"
         table[None] = backend
 
-    def resolve_to_backend(self, filepath, extra_info = False):
+    def _resolve_to_backend(self, filepath, extra_info = False):
         """
         extra_info = True is for internal use!
 
@@ -270,6 +270,12 @@ class MountStorage(StorageInterface):
         else:
             return (res_be, res_fp)
 
+    def resolve_to_backend(self, filepath):
+        backend, filepath = self._resolve_to_backend(filepath)
+        if backend is None:
+            raise Error("Path not mounted")
+        return backend, filepath
+
     def __repr__(self, table = None, indent = []):
         res = []
         if table is None: