# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
-import re
import shutil
import urlparse
import uuid
self.container = self.connection.get_container(
self.param_container)
+ self.container_uri = self.container.public_uri()
+
def _resolve_filepath(self, filepath):
return '/'.join(
clean_listy_filepath(filepath))
self.container.delete_object(filepath)
def file_url(self, filepath):
- return self.get_file(filepath).public_uri()
+ return '/'.join([
+ self.container_uri,
+ self._resolve_filepath(filepath)])
class MountStorage(StorageInterface):
"""
Experimental "Mount" virtual Storage Interface
- This isn't an interface to some real storage, instead
- it's a redirecting interface, that redirects requests
- to other "StorageInterface"s.
- For example, requests for ["store1", "a"] to first
- storage with the path ["a"], etc.
+ This isn't an interface to some real storage, instead it's a
+ redirecting interface, that redirects requests to other
+ "StorageInterface"s.
+
+ For example, say you have the paths:
+
+ 1. ['user_data', 'cwebber', 'avatar.jpg']
+ 2. ['user_data', 'elrond', 'avatar.jpg']
+ 3. ['media_entries', '34352f304c3f4d0ad8ad0f043522b6f2', 'thumb.jpg']
+
+ You could mount media_entries under CloudFileStorage and user_data
+ under BasicFileStorage. Then 1 would be passed to
+ BasicFileStorage under the path ['cwebber', 'avatar.jpg'] and 3
+ would be passed to CloudFileStorage under
+ ['34352f304c3f4d0ad8ad0f043522b6f2', 'thumb.jpg'].
+
+ In other words, this is kind of like mounting /home/ and /etc/
+ under different filesystems on your operating system... but with
+ mediagoblin filestorages :)
- To set this up, you currently need to call the mount()
- method with the target path and a backend, that shall
- be available under that target path.
- You have to mount things in a sensible order,
+ To set this up, you currently need to call the mount() method with
+ the target path and a backend, that shall be available under that
+ target path. You have to mount things in a sensible order,
especially you can't mount ["a", "b"] before ["a"].
"""
def __init__(self, **kwargs):
return cleaned_filepath
-def storage_system_from_config(config):
+def storage_system_from_config(config_section):
"""
- Utility for setting up a storage system from the paste app config.
+ Utility for setting up a storage system from a config section.
- Note that a special argument may be passed in to the paste_config
- which is "${storage_prefix}_storage_class" which will provide an
+ Note that a special argument may be passed in to
+ the config_section which is "storage_class" which will provide an
import path to a storage system. This defaults to
"mediagoblin.storage:BasicFileStorage" if otherwise undefined.
Arguments:
- - paste_config: dictionary of config parameters
- - storage_prefix: the storage system we're setting up / will be
- getting keys/arguments from. For example 'publicstore' will
- grab all arguments that are like 'publicstore_FOO'.
+ - config_section: dictionary of config parameters
Returns:
An instantiated storage system.
Example:
storage_system_from_config(
- {'publicstore_base_url': '/media/',
- 'publicstore_base_dir': '/var/whatever/media/'},
- 'publicstore')
+ {'base_url': '/media/',
+ 'base_dir': '/var/whatever/media/'})
Will return:
BasicFileStorage(
"""
# This construct is needed, because dict(config) does
# not replace the variables in the config items.
- config_params = dict(config.iteritems())
+ config_params = dict(config_section.iteritems())
if 'storage_class' in config_params:
storage_class = config_params['storage_class']