diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-06-11 11:18:03 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-06-11 11:18:03 -0500 |
commit | 3a89c23e7fd330ea662dd57ff74a9d424d476b84 (patch) | |
tree | 8852cdfedcbc05628e8f7046b3aa1dde88774607 /mediagoblin/storage.py | |
parent | d07713d0b0696528927e720e957ac4d049e3f46f (diff) | |
download | mediagoblin-3a89c23e7fd330ea662dd57ff74a9d424d476b84.tar.lz mediagoblin-3a89c23e7fd330ea662dd57ff74a9d424d476b84.tar.xz mediagoblin-3a89c23e7fd330ea662dd57ff74a9d424d476b84.zip |
Allow storage systems to be local and allow for a get_local_path
method if applicable.
Diffstat (limited to 'mediagoblin/storage.py')
-rw-r--r-- | mediagoblin/storage.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/mediagoblin/storage.py b/mediagoblin/storage.py index 5d7e70d6..685039b2 100644 --- a/mediagoblin/storage.py +++ b/mediagoblin/storage.py @@ -60,6 +60,9 @@ class StorageInterface(object): StorageInterface. """ + # Whether this file store is on the local filesystem. + local_storage = False + def __raise_not_implemented(self): """ Raise a warning about some component not implemented by a @@ -127,12 +130,25 @@ class StorageInterface(object): else: return filepath + def get_local_path(self, filepath): + """ + If this is a local_storage implementation, give us a link to + the local filesystem reference to this file. + + >>> storage_handler.get_local_path(['foo', 'bar', 'baz.jpg']) + u'/path/to/mounting/foo/bar/baz.jpg' + """ + # Subclasses should override this method, if applicable. + self.__raise_not_implemented() + class BasicFileStorage(StorageInterface): """ Basic local filesystem implementation of storage API """ + local_storage = True + def __init__(self, base_dir, base_url=None, **kwargs): """ Keyword arguments: @@ -177,6 +193,9 @@ class BasicFileStorage(StorageInterface): self.base_url, '/'.join(clean_listy_filepath(filepath))) + def get_local_path(self, filepath): + return self._resolve_filepath(filepath) + ########### # Utilities @@ -187,7 +206,7 @@ def clean_listy_filepath(listy_filepath): Take a listy filepath (like ['dir1', 'dir2', 'filename.jpg']) and clean out any nastiness from it. - For example: + >>> clean_listy_filepath([u'/dir1/', u'foo/../nasty', u'linooks.jpg']) [u'dir1', u'foo_.._nasty', u'linooks.jpg'] |