Issue #362 - Updated `mediagoblin.user_pages.views` to handle new "Simple comments...
[mediagoblin.git] / mediagoblin / storage.py
index 685039b2745210ce433bd943a60dc0c27f35d03d..5d6faa4cd7a78da5144865b78e466291462b36d7 100644 (file)
@@ -16,6 +16,7 @@
 
 import os
 import re
+import shutil
 import urlparse
 import uuid
 
@@ -141,6 +142,24 @@ class StorageInterface(object):
         # Subclasses should override this method, if applicable.
         self.__raise_not_implemented()
 
+    def copy_locally(self, filepath, dest_path):
+        """
+        Copy this file locally.
+
+        A basic working method for this is provided that should
+        function both for local_storage systems and remote storge
+        systems, but if more efficient systems for copying locally
+        apply to your system, override this method with something more
+        appropriate.
+        """
+        if self.local_storage:
+            shutil.copy(
+                self.get_local_path(filepath), dest_path)
+        else:
+            with self.get_file(filepath, 'rb') as source_file:
+                with file(dest_path, 'wb') as dest_file:
+                    dest_file.write(source_file.read())
+
 
 class BasicFileStorage(StorageInterface):
     """
@@ -228,7 +247,7 @@ def clean_listy_filepath(listy_filepath):
     return cleaned_filepath
 
 
-def storage_system_from_paste_config(paste_config, storage_prefix):
+def storage_system_from_config(paste_config, storage_prefix):
     """
     Utility for setting up a storage system from the paste app config.
 
@@ -247,7 +266,7 @@ def storage_system_from_paste_config(paste_config, storage_prefix):
       An instantiated storage system.
 
     Example:
-      storage_system_from_paste_config(
+      storage_system_from_config(
         {'publicstore_base_url': '/media/',
          'publicstore_base_dir': '/var/whatever/media/'},
         'publicstore')
@@ -272,3 +291,5 @@ def storage_system_from_paste_config(paste_config, storage_prefix):
 
     storage_class = util.import_component(storage_class)
     return storage_class(**config_params)
+
+