Implement FTP backend and other code cleanups.
[cumulus.git] / python / cumulus / store / file.py
index 6034835..f343500 100644 (file)
@@ -5,9 +5,11 @@ import cumulus.store
 type_patterns = cumulus.store.type_patterns
 
 class FileStore(cumulus.store.Store):
-    def __init__(self, prefix):
-        while prefix.endswith("/") and prefix != "/": prefix = prefix[:-1]
-        self.prefix = prefix
+    def __init__(self, url, **kw):
+        # if constructor isn't called via factory interpret url as filename
+        if not hasattr (self, 'path'):
+            self.path = url
+        self.prefix = self.path.rstrip("/")
 
     def _get_path(self, type, name):
         return "%s/%s" % (self.prefix, name)
@@ -33,5 +35,10 @@ class FileStore(cumulus.store.Store):
         os.unlink(k)
 
     def stat(self, type, name):
-        stat = os.stat(self._get_path(type, name))
-        return {'size': stat.st_size}
+        try:
+            stat = os.stat(self._get_path(type, name))
+            return {'size': stat.st_size}
+        except OSError:
+            raise cumulus.store.NotFoundError, (type, name)
+
+Store = FileStore