From 180bdbde93ad4b62395c78e99e97587b44ad31c7 Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 8 Jun 2011 23:22:11 +0200 Subject: Refactor filename generation in the public store Just a small refactoring of the filename setup in the public store. Very simple. --- mediagoblin/process_media/__init__.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'mediagoblin/process_media') diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index 4f06a686..097b4375 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -24,6 +24,13 @@ from mediagoblin.globals import database, queue_store, public_store THUMB_SIZE = 200, 200 +def create_pub_filepath(entry, filename): + return public_store.get_unique_filepath( + ['media_entries', + unicode(entry['_id']), + filename]) + + @task def process_media_initial(media_id): entry = database.MediaEntry.one( @@ -36,10 +43,7 @@ def process_media_initial(media_id): thumb = Image.open(queued_file) thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS) - thumb_filepath = public_store.get_unique_filepath( - ['media_entries', - unicode(entry['_id']), - 'thumbnail.jpg']) + thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg') with public_store.get_file(thumb_filepath, 'w') as thumb_file: thumb.save(thumb_file, "JPEG") @@ -49,15 +53,13 @@ def process_media_initial(media_id): queued_file = queue_store.get_file(queued_filepath, 'rb') with queued_file: - main_filepath = public_store.get_unique_filepath( - ['media_entries', - unicode(entry['_id']), - queued_filepath[-1]]) + main_filepath = create_pub_filepath(entry, queued_filepath[-1]) with public_store.get_file(main_filepath, 'wb') as main_file: main_file.write(queued_file.read()) queue_store.delete_file(queued_filepath) + entry['queued_media_file'] = [] media_files_dict = entry.setdefault('media_files', {}) media_files_dict['thumb'] = thumb_filepath media_files_dict['main'] = main_filepath -- cgit v1.2.3 From 6e7ce8d1af8c6fcf7d00992b1c8ef0e8c1602479 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 12 Jun 2011 17:27:37 -0500 Subject: mediagoblin.globals->mediagoblin.mg_globals --- mediagoblin/process_media/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/process_media') diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index 531eb16d..71a0a277 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -18,7 +18,7 @@ import Image from mediagoblin.db.util import ObjectId from celery.task import task -from mediagoblin import globals as mg_globals +from mediagoblin import mg_globals THUMB_SIZE = 200, 200 -- cgit v1.2.3 From 300c34e8ce52f20ba789c22c26bdc78b9ecb2954 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 12 Jun 2011 17:28:54 -0500 Subject: First import of mg_globals as mgg, partly because I just wanted it to be clear that it's okay to do by doing it *somewhere* :) --- mediagoblin/process_media/__init__.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'mediagoblin/process_media') diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index 71a0a277..c71c5dda 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -18,7 +18,7 @@ import Image from mediagoblin.db.util import ObjectId from celery.task import task -from mediagoblin import mg_globals +from mediagoblin import mg_globals as mgg THUMB_SIZE = 200, 200 @@ -26,14 +26,14 @@ THUMB_SIZE = 200, 200 @task def process_media_initial(media_id): - workbench = mg_globals.workbench_manager.create_workbench() + workbench = mgg.workbench_manager.create_workbench() - entry = mg_globals.database.MediaEntry.one( + entry = mgg.database.MediaEntry.one( {'_id': ObjectId(media_id)}) queued_filepath = entry['queued_media_file'] - queued_filename = mg_globals.workbench_manager.localized_file( - workbench, mg_globals.queue_store, queued_filepath, + queued_filename = mgg.workbench_manager.localized_file( + workbench, mgg.queue_store, queued_filepath, 'source') queued_file = file(queued_filename, 'r') @@ -42,12 +42,12 @@ def process_media_initial(media_id): thumb = Image.open(queued_file) thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS) - thumb_filepath = mg_globals.public_store.get_unique_filepath( + thumb_filepath = mgg.public_store.get_unique_filepath( ['media_entries', unicode(entry['_id']), 'thumbnail.jpg']) - thumb_file = mg_globals.public_store.get_file(thumb_filepath, 'w') + thumb_file = mgg.public_store.get_file(thumb_filepath, 'w') with thumb_file: thumb.save(thumb_file, "JPEG") @@ -56,15 +56,15 @@ def process_media_initial(media_id): queued_file = file(queued_filename, 'rb') with queued_file: - main_filepath = mg_globals.public_store.get_unique_filepath( + main_filepath = mgg.public_store.get_unique_filepath( ['media_entries', unicode(entry['_id']), queued_filepath[-1]]) - with mg_globals.public_store.get_file(main_filepath, 'wb') as main_file: + with mgg.public_store.get_file(main_filepath, 'wb') as main_file: main_file.write(queued_file.read()) - mg_globals.queue_store.delete_file(queued_filepath) + mgg.queue_store.delete_file(queued_filepath) media_files_dict = entry.setdefault('media_files', {}) media_files_dict['thumb'] = thumb_filepath media_files_dict['main'] = main_filepath @@ -72,4 +72,4 @@ def process_media_initial(media_id): entry.save() # clean up workbench - mg_globals.workbench_manager.destroy_workbench(workbench) + mgg.workbench_manager.destroy_workbench(workbench) -- cgit v1.2.3 From 34d35a23930815438a4e1d8b28ec17016fb938c0 Mon Sep 17 00:00:00 2001 From: cfdv Date: Sun, 12 Jun 2011 17:35:07 -0500 Subject: ensure color mode compatibility when making image thumbnails --- mediagoblin/process_media/__init__.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mediagoblin/process_media') diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index c71c5dda..f0a6e511 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -41,6 +41,9 @@ def process_media_initial(media_id): with queued_file: thumb = Image.open(queued_file) thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS) + # ensure color mode is compatible with jpg + if thumb.mode != "RGB": + thumb = thumb.convert("RGB") thumb_filepath = mgg.public_store.get_unique_filepath( ['media_entries', -- cgit v1.2.3 From 52426ae01f0439af2833656a74eda70a240d66ae Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 13 Jun 2011 00:36:56 +0200 Subject: Create a Workbench class and use it everywhere. Some references to Workbench.dir look ugly, I'm happy to hear suggestions there. --- mediagoblin/process_media/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/process_media') diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index f0a6e511..bd067e39 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -32,8 +32,8 @@ def process_media_initial(media_id): {'_id': ObjectId(media_id)}) queued_filepath = entry['queued_media_file'] - queued_filename = mgg.workbench_manager.localized_file( - workbench, mgg.queue_store, queued_filepath, + queued_filename = workbench.localized_file( + mgg.queue_store, queued_filepath, 'source') queued_file = file(queued_filename, 'r') -- cgit v1.2.3 From b67a983a02363bd17a4e6a96e650e65aa2d4eb7a Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 14 Jun 2011 20:39:14 +0200 Subject: Move destroy_workbench to Workbench class And add a lot of warnings, as the checks for "being part of the main Manager" are all gone. --- mediagoblin/process_media/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mediagoblin/process_media') diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py index bd067e39..f37bf080 100644 --- a/mediagoblin/process_media/__init__.py +++ b/mediagoblin/process_media/__init__.py @@ -75,4 +75,4 @@ def process_media_initial(media_id): entry.save() # clean up workbench - mgg.workbench_manager.destroy_workbench(workbench) + workbench.destroy_self() -- cgit v1.2.3