aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoar Wandborg <git@wandborg.com>2011-09-01 03:22:59 +0200
committerJoar Wandborg <git@wandborg.com>2011-09-01 03:22:59 +0200
commitb5e7b967bbe95f9d6efaa9f0b6a105f2f13d662e (patch)
treea4718b16f99ef44b665d28531e0a0be7fcd62fcc
parent13b9f054f9a548d418c95adca1b4fddcb7e3cf1e (diff)
downloadmediagoblin-b5e7b967bbe95f9d6efaa9f0b6a105f2f13d662e.tar.lz
mediagoblin-b5e7b967bbe95f9d6efaa9f0b6a105f2f13d662e.tar.xz
mediagoblin-b5e7b967bbe95f9d6efaa9f0b6a105f2f13d662e.zip
Made a wrapper for cloudfiles.storage_object.Object
- `medium.jpg` issue should no longer exist.
-rw-r--r--mediagoblin/process_media/__init__.py4
-rw-r--r--mediagoblin/storage.py29
2 files changed, 29 insertions, 4 deletions
diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py
index e1289a4c..85a23450 100644
--- a/mediagoblin/process_media/__init__.py
+++ b/mediagoblin/process_media/__init__.py
@@ -142,8 +142,8 @@ def process_image(entry):
thumb = thumb.convert("RGB")
thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg')
-
thumb_file = mgg.public_store.get_file(thumb_filepath, 'w')
+
with closing(thumb_file):
thumb.save(thumb_file, "JPEG", quality=90)
@@ -160,8 +160,8 @@ def process_image(entry):
medium = medium.convert("RGB")
medium_filepath = create_pub_filepath(entry, 'medium.jpg')
-
medium_file = mgg.public_store.get_file(medium_filepath, 'w')
+
with closing(medium_file):
medium.save(medium_file, "JPEG", quality=90)
medium_processed = True
diff --git a/mediagoblin/storage.py b/mediagoblin/storage.py
index aaddce2f..7765b668 100644
--- a/mediagoblin/storage.py
+++ b/mediagoblin/storage.py
@@ -20,6 +20,7 @@ import urlparse
import uuid
import cloudfiles
import mimetypes
+import tempfile
from werkzeug.utils import secure_filename
@@ -228,6 +229,27 @@ class BasicFileStorage(StorageInterface):
class CloudFilesStorage(StorageInterface):
+ class StorageObjectWrapper():
+ """
+ Wrapper for python-cloudfiles's cloudfiles.storage_object.Object
+ used to circumvent the mystic `medium.jpg` corruption issue.
+
+ This wrapper currently meets mediagoblin's needs for a public_store
+ file-like object.
+ """
+ def __init__(self, storage_object):
+ self.storage_object = storage_object
+
+ def read(self, *args, **kwargs):
+ return self.storage_object.read(*args, **kwargs)
+
+ def write(self, data, *args, **kwargs):
+ if self.storage_object.size and type(data) == str:
+ data = self.read() + data
+
+ self.storage_object.write(data, *args, **kwargs)
+
+
def __init__(self, **kwargs):
self.param_container = kwargs.get('cloudfiles_container')
self.param_user = kwargs.get('cloudfiles_user')
@@ -269,7 +291,10 @@ class CloudFilesStorage(StorageInterface):
except cloudfiles.errors.NoSuchObject:
return False
- def get_file(self, filepath, mode='r'):
+ def get_file(self, filepath, *args):
+ """
+ - Doesn't care about the "mode" argument
+ """
try:
obj = self.container.get_object(
self._resolve_filepath(filepath))
@@ -283,7 +308,7 @@ class CloudFilesStorage(StorageInterface):
if mimetype:
obj.content_type = mimetype[0]
- return obj
+ return self.StorageObjectWrapper(obj)
def delete_file(self, filepath):
# TODO: Also delete unused directories if empty (safely, with