aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/storage
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/storage')
-rw-r--r--mediagoblin/storage/__init__.py16
-rw-r--r--mediagoblin/storage/cloudfiles.py1
-rw-r--r--mediagoblin/storage/filestorage.py14
-rw-r--r--mediagoblin/storage/mountstorage.py2
4 files changed, 30 insertions, 3 deletions
diff --git a/mediagoblin/storage/__init__.py b/mediagoblin/storage/__init__.py
index 8665d9e5..0840614b 100644
--- a/mediagoblin/storage/__init__.py
+++ b/mediagoblin/storage/__init__.py
@@ -21,7 +21,7 @@ import uuid
from werkzeug.utils import secure_filename
-from mediagoblin import util
+from mediagoblin.tools import common
########
# Errors
@@ -169,6 +169,18 @@ class StorageInterface(object):
with file(dest_path, 'wb') as dest_file:
dest_file.write(source_file.read())
+ def copy_local_to_storage(self, filename, filepath):
+ """
+ Copy this file from locally to the storage system.
+
+ This is kind of the opposite of copy_locally. It's likely you
+ could override this method with something more appropriate to
+ your storage system.
+ """
+ with self.get_file(filepath, 'wb') as dest_file:
+ with file(filename, 'rb') as source_file:
+ dest_file.write(source_file.read())
+
###########
# Utilities
@@ -236,5 +248,5 @@ def storage_system_from_config(config_section):
else:
storage_class = 'mediagoblin.storage.filestorage:BasicFileStorage'
- storage_class = util.import_component(storage_class)
+ storage_class = common.import_component(storage_class)
return storage_class(**config_params)
diff --git a/mediagoblin/storage/cloudfiles.py b/mediagoblin/storage/cloudfiles.py
index 85d52242..51b73579 100644
--- a/mediagoblin/storage/cloudfiles.py
+++ b/mediagoblin/storage/cloudfiles.py
@@ -27,6 +27,7 @@ from mediagoblin.storage import StorageInterface, clean_listy_filepath
import cloudfiles
import mimetypes
+
class CloudFilesStorage(StorageInterface):
'''
OpenStack/Rackspace Cloud's Swift/CloudFiles support
diff --git a/mediagoblin/storage/filestorage.py b/mediagoblin/storage/filestorage.py
index 22d6eb5a..a904865f 100644
--- a/mediagoblin/storage/filestorage.py
+++ b/mediagoblin/storage/filestorage.py
@@ -20,6 +20,7 @@ from mediagoblin.storage import (
NoWebServing)
import os
+import shutil
import urlparse
@@ -76,3 +77,16 @@ class BasicFileStorage(StorageInterface):
def get_local_path(self, filepath):
return self._resolve_filepath(filepath)
+
+ def copy_local_to_storage(self, filename, filepath):
+ """
+ Copy this file from locally to the storage system.
+ """
+ # Make directories if necessary
+ if len(filepath) > 1:
+ directory = self._resolve_filepath(filepath[:-1])
+ if not os.path.exists(directory):
+ os.makedirs(directory)
+
+ shutil.copy(
+ filename, self.get_local_path(filepath))
diff --git a/mediagoblin/storage/mountstorage.py b/mediagoblin/storage/mountstorage.py
index 6adb7a0d..7239931f 100644
--- a/mediagoblin/storage/mountstorage.py
+++ b/mediagoblin/storage/mountstorage.py
@@ -14,7 +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/>.
-from medigoblin.storage import StorageInterface, clean_listy_filepath
+from mediagoblin.storage import StorageInterface, clean_listy_filepath
class MountStorage(StorageInterface):