diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-04-10 17:03:23 -0500 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2011-04-10 17:03:23 -0500 |
commit | cee7a1c163c0400610234f0f62455ba6d7e3160b (patch) | |
tree | 061ef4951d522b893aae978e7d4277a886da4c55 /mediagoblin/storage.py | |
parent | 20e3ee115d5db738b071e99172d2ea97c6c0443e (diff) | |
download | mediagoblin-cee7a1c163c0400610234f0f62455ba6d7e3160b.tar.lz mediagoblin-cee7a1c163c0400610234f0f62455ba6d7e3160b.tar.xz mediagoblin-cee7a1c163c0400610234f0f62455ba6d7e3160b.zip |
get_file() implementation for BasicFileStorage
Diffstat (limited to 'mediagoblin/storage.py')
-rw-r--r-- | mediagoblin/storage.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/mediagoblin/storage.py b/mediagoblin/storage.py index 89b86315..e6e3a59d 100644 --- a/mediagoblin/storage.py +++ b/mediagoblin/storage.py @@ -86,7 +86,7 @@ class StorageInterface(object): # Subclasses should override this method. self.__raise_not_implemented() - def get_file(self, filepath, mode): + def get_file(self, filepath, mode='r'): """ Return a file-like object for reading/writing from this filepath. @@ -156,8 +156,16 @@ class BasicFileStorage(StorageInterface): def file_exists(self, filepath): return os.path.exists(self._resolve_filepath(filepath)) - def get_file(self, filepath, mode): - pass + def get_file(self, filepath, mode='r'): + # Make directories if necessary + if len(filepath) > 1: + directory = self._resolve_filepath(filepath[:-1]) + if not os.path.exists('directory'): + os.makedirs(directory) + + # Grab and return the file in the mode specified + return open(self._resolve_filepath(filepath), mode) + def delete_file(self, filepath): pass |