Put down structure of BasicFileStorage, and the ._resolve_filepath() method
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 10 Apr 2011 18:38:01 +0000 (13:38 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sun, 10 Apr 2011 18:38:01 +0000 (13:38 -0500)
mediagoblin/storage.py

index 4e0960c7d7ca42eb766359978751437690ada831..84ceb641d950982e65e86092085b1d2ba8442b16 100644 (file)
@@ -14,6 +14,7 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+import os
 
 from werkzeug.utils import secure_filename
 
@@ -119,3 +120,41 @@ class StorageInterface(object):
             return filepath[:-1] + ["%s-%s" % (uuid.uuid4(), filepath[-1])]
         else:
             return filepath
+
+
+class BasicFileStorage(StorageInterface):
+    """
+    Basic local filesystem implementation of storage API
+    """
+
+    def __init__(self, base_dir, serve_url=None):
+        """
+        Keyword arguments:
+        - base_dir: Base directory things will be served out of.  MUST
+          be an absolute path.
+        - serve_url: URL files will be served from
+        """
+        self.base_dir = base_dir
+        self.serve_url = serve_url
+
+    def _resolve_filepath(self, filepath):
+        """
+        Transform the given filepath into a local filesystem filepath.
+        """
+        return os.path.join(
+            self.base_dir, *clean_listy_filepath(filepath))
+        
+    def _create_dirs_for_filepath(self, filepath):
+        """
+        Create any necessary directories for filepath
+        """
+        pass
+
+    def file_exists(self, filepath):
+        return os.path.exists(self._resolve_filepath(filepath))
+
+    def get_file(self, filepath, mode):
+        pass
+
+    def delete_file(self, filepath):
+        pass