aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mediagoblin/storage.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/mediagoblin/storage.py b/mediagoblin/storage.py
index 4e0960c7..87435ff2 100644
--- a/mediagoblin/storage.py
+++ b/mediagoblin/storage.py
@@ -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
@@ -103,6 +104,14 @@ class StorageInterface(object):
# Subclasses should override this method.
self.__raise_not_implemented()
+ def url_for_file(self, filepath):
+ """
+ Get the URL for this file. This assumes our storage has been
+ mounted with some kind of URL which makes this possible.
+ """
+ # Subclasses should override this method.
+ self.__raise_not_implemented()
+
def get_unique_filename(self, filepath):
"""
If a filename at filepath already exists, generate a new name.
@@ -119,3 +128,38 @@ 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 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
+
+ def url_for_file(self, filepath):
+ pass