diff options
author | Joar Wandborg <git@wandborg.com> | 2011-09-05 22:06:47 +0200 |
---|---|---|
committer | Joar Wandborg <git@wandborg.com> | 2011-09-05 22:06:47 +0200 |
commit | c2b862d1349b5ecc6d787000edb209525b719751 (patch) | |
tree | 17b6f96271ae598ef5b6b6d5f6e9c3aa3653f025 /mediagoblin/process_media | |
parent | 05d5d45bf9db4ffe6f7987a8c66e9f547fb1ce15 (diff) | |
download | mediagoblin-c2b862d1349b5ecc6d787000edb209525b719751.tar.lz mediagoblin-c2b862d1349b5ecc6d787000edb209525b719751.tar.xz mediagoblin-c2b862d1349b5ecc6d787000edb209525b719751.zip |
Feature #571 - Closing storage objects - Removed closing(), renamed
StorageObjectWrapper, added with-support to CloudFilesStorageWrapper
* Removed custom `closing()` method
* Removed usage of `closing()` in process_media/__init__.py
* Renamed StorageObjectWrapper -> CloudFilesStorageObject wrapper
In my first version of the StorageOjbectWrapper it was located
inside the CloudFilesStorage object, things have changed since
then but there has been no renaming, thank you Elrond for the
good point.
* CloudFilesStorageObjectWrapper now supports context manager
methods such as `__enter__()` and `__exit__()` (and `close()`)
Diffstat (limited to 'mediagoblin/process_media')
-rw-r--r-- | mediagoblin/process_media/__init__.py | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index db913f5f..2b9eed6e 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -16,7 +16,6 @@ import Image -from contextlib import contextmanager from celery.task import Task from celery import registry @@ -36,14 +35,6 @@ def create_pub_filepath(entry, filename): filename]) -@contextmanager -def closing(callback): - try: - yield callback - finally: - pass - - ################################ # Media processing initial steps ################################ @@ -66,7 +57,7 @@ class ProcessMedia(Task): except BaseProcessingFail, exc: mark_entry_failed(entry[u'_id'], exc) return - + entry['state'] = u'processed' entry.save() @@ -144,7 +135,7 @@ def process_image(entry): thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg') thumb_file = mgg.public_store.get_file(thumb_filepath, 'w') - with closing(thumb_file): + with thumb_file: thumb.save(thumb_file, "JPEG", quality=90) # If the size of the original file exceeds the specified size of a `medium` @@ -162,7 +153,7 @@ def process_image(entry): medium_filepath = create_pub_filepath(entry, 'medium.jpg') medium_file = mgg.public_store.get_file(medium_filepath, 'w') - with closing(medium_file): + with medium_file: medium.save(medium_file, "JPEG", quality=90) medium_processed = True @@ -172,8 +163,8 @@ def process_image(entry): with queued_file: original_filepath = create_pub_filepath(entry, queued_filepath[-1]) - - with closing(mgg.public_store.get_file(original_filepath, 'wb')) as original_file: + + with mgg.public_store.get_file(original_filepath, 'wb') as original_file: original_file.write(queued_file.read()) mgg.queue_store.delete_file(queued_filepath) |