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* :)
This commit is contained in:
Christopher Allan Webber 2011-06-12 17:28:54 -05:00
parent 6e7ce8d1af
commit 300c34e8ce

View File

@ -18,7 +18,7 @@ import Image
from mediagoblin.db.util import ObjectId from mediagoblin.db.util import ObjectId
from celery.task import task from celery.task import task
from mediagoblin import mg_globals from mediagoblin import mg_globals as mgg
THUMB_SIZE = 200, 200 THUMB_SIZE = 200, 200
@ -26,14 +26,14 @@ THUMB_SIZE = 200, 200
@task @task
def process_media_initial(media_id): 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)}) {'_id': ObjectId(media_id)})
queued_filepath = entry['queued_media_file'] queued_filepath = entry['queued_media_file']
queued_filename = mg_globals.workbench_manager.localized_file( queued_filename = mgg.workbench_manager.localized_file(
workbench, mg_globals.queue_store, queued_filepath, workbench, mgg.queue_store, queued_filepath,
'source') 'source')
queued_file = file(queued_filename, 'r') queued_file = file(queued_filename, 'r')
@ -42,12 +42,12 @@ def process_media_initial(media_id):
thumb = Image.open(queued_file) thumb = Image.open(queued_file)
thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS) 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', ['media_entries',
unicode(entry['_id']), unicode(entry['_id']),
'thumbnail.jpg']) '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: with thumb_file:
thumb.save(thumb_file, "JPEG") thumb.save(thumb_file, "JPEG")
@ -56,15 +56,15 @@ def process_media_initial(media_id):
queued_file = file(queued_filename, 'rb') queued_file = file(queued_filename, 'rb')
with queued_file: with queued_file:
main_filepath = mg_globals.public_store.get_unique_filepath( main_filepath = mgg.public_store.get_unique_filepath(
['media_entries', ['media_entries',
unicode(entry['_id']), unicode(entry['_id']),
queued_filepath[-1]]) 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()) 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 = entry.setdefault('media_files', {})
media_files_dict['thumb'] = thumb_filepath media_files_dict['thumb'] = thumb_filepath
media_files_dict['main'] = main_filepath media_files_dict['main'] = main_filepath
@ -72,4 +72,4 @@ def process_media_initial(media_id):
entry.save() entry.save()
# clean up workbench # clean up workbench
mg_globals.workbench_manager.destroy_workbench(workbench) mgg.workbench_manager.destroy_workbench(workbench)