diff options
author | Christopher Allan Webber <cwebber@dustycloud.org> | 2015-03-05 16:49:06 -0600 |
---|---|---|
committer | Christopher Allan Webber <cwebber@dustycloud.org> | 2015-03-05 16:49:06 -0600 |
commit | 50f12414df260de9605489ec0ca5427cff0813bf (patch) | |
tree | d4d21fbd8b5de4e91599b1b23d1d7dfd549d7f09 /mediagoblin/storage | |
parent | 2d0511c49991118aedaffbaae19954ab03469cca (diff) | |
parent | 2b4c339de6a5762c59054182034793e3b6002ee4 (diff) | |
download | mediagoblin-50f12414df260de9605489ec0ca5427cff0813bf.tar.lz mediagoblin-50f12414df260de9605489ec0ca5427cff0813bf.tar.xz mediagoblin-50f12414df260de9605489ec0ca5427cff0813bf.zip |
Merge remote-tracking branch 'refs/remotes/breton/bug/647'
Diffstat (limited to 'mediagoblin/storage')
-rw-r--r-- | mediagoblin/storage/cloudfiles.py | 21 | ||||
-rw-r--r-- | mediagoblin/storage/filestorage.py | 12 |
2 files changed, 11 insertions, 22 deletions
diff --git a/mediagoblin/storage/cloudfiles.py b/mediagoblin/storage/cloudfiles.py index 532e5bac..61665ea0 100644 --- a/mediagoblin/storage/cloudfiles.py +++ b/mediagoblin/storage/cloudfiles.py @@ -193,27 +193,6 @@ class CloudFilesStorageObjectWrapper(): return self.storage_object.read(*args, **kwargs) def write(self, data, *args, **kwargs): - """ - write data to the cloudfiles storage object - - The original motivation for this wrapper is to ensure - that buffered writing to a cloudfiles storage object does not overwrite - any preexisting data. - - Currently this method does not support any write modes except "append". - However if we should need it it would be easy implement. - """ - _log.warn( - '{0}.write() has bad performance! Use .send instead for now'\ - .format(self.__class__.__name__)) - - if self.storage_object.size and type(data) == str: - _log.debug('{0} is > 0 in size, appending data'.format( - self.storage_object.name)) - data = self.read() + data - - _log.debug('Writing {0}'.format( - self.storage_object.name)) self.storage_object.write(data, *args, **kwargs) def send(self, *args, **kw): diff --git a/mediagoblin/storage/filestorage.py b/mediagoblin/storage/filestorage.py index f989539c..89f43276 100644 --- a/mediagoblin/storage/filestorage.py +++ b/mediagoblin/storage/filestorage.py @@ -14,6 +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/>. +import io import os import shutil @@ -24,6 +25,15 @@ from mediagoblin.storage import ( clean_listy_filepath, NoWebServing) +class FileObjectAwareFile(io.FileIO): + def write(self, data): + if hasattr(data, 'read'): + # We can call data.read(). It means that the data is a file-like + # object, which should be saved RAM-friendly way + shutil.copyfileobj(data, self) + else: + super(FileObjectAwareFile, self).write(data) + class BasicFileStorage(StorageInterface): """ @@ -60,7 +70,7 @@ class BasicFileStorage(StorageInterface): os.makedirs(directory) # Grab and return the file in the mode specified - return open(self._resolve_filepath(filepath), mode) + return FileObjectAwareFile(self._resolve_filepath(filepath), mode) def delete_file(self, filepath): """Delete file at filepath |