From b228d89715558281d9573543dd0d6c74836d42ca Mon Sep 17 00:00:00 2001 From: Elrond Date: Wed, 26 Dec 2012 23:40:42 +0100 Subject: [PATCH] prepare_queue_task: Take app not request. First rename prepare_entry to prepare_queue_task, because this is really more like what this thing does. Thanks to Velmont for noting that we do not need a request in here, but an "app" is good enough. Which means, that this stuff can be called from tool scripts too. --- mediagoblin/plugins/api/views.py | 4 ++-- mediagoblin/submit/lib.py | 9 ++++++--- mediagoblin/submit/views.py | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/mediagoblin/plugins/api/views.py b/mediagoblin/plugins/api/views.py index e8f64574..0991297d 100644 --- a/mediagoblin/plugins/api/views.py +++ b/mediagoblin/plugins/api/views.py @@ -27,7 +27,7 @@ from mediagoblin.meddleware.csrf import csrf_exempt from mediagoblin.media_types import sniff_media from mediagoblin.plugins.api.tools import api_auth, get_entry_serializable, \ json_response -from mediagoblin.submit.lib import prepare_entry, run_process_media +from mediagoblin.submit.lib import prepare_queue_task, run_process_media _log = logging.getLogger(__name__) @@ -68,7 +68,7 @@ def post_entry(request): entry.generate_slug() # queue appropriately - queue_file = prepare_entry(request, entry, media_file.filename) + queue_file = prepare_queue_task(request.app, entry, media_file.filename) with queue_file: queue_file.write(request.files['file'].stream.read()) diff --git a/mediagoblin/submit/lib.py b/mediagoblin/submit/lib.py index 6660eb53..db5dfe53 100644 --- a/mediagoblin/submit/lib.py +++ b/mediagoblin/submit/lib.py @@ -29,7 +29,10 @@ from mediagoblin.processing.task import ProcessMedia _log = logging.getLogger(__name__) -def prepare_entry(request, entry, filename): +def prepare_queue_task(app, entry, filename): + """ + Prepare a MediaEntry for the processing queue and get a queue file + """ # We generate this ourselves so we know what the taks id is for # retrieval later. @@ -40,13 +43,13 @@ def prepare_entry(request, entry, filename): entry.queued_task_id = task_id # Now store generate the queueing related filename - queue_filepath = request.app.queue_store.get_unique_filepath( + queue_filepath = app.queue_store.get_unique_filepath( ['media_entries', task_id, secure_filename(filename)]) # queue appropriately - queue_file = request.app.queue_store.get_file( + queue_file = app.queue_store.get_file( queue_filepath, 'wb') # Add queued filename to the entry diff --git a/mediagoblin/submit/views.py b/mediagoblin/submit/views.py index d36f5f5d..2d609b31 100644 --- a/mediagoblin/submit/views.py +++ b/mediagoblin/submit/views.py @@ -33,7 +33,7 @@ from mediagoblin.messages import add_message, SUCCESS from mediagoblin.media_types import sniff_media, \ InvalidFileType, FileTypeNotSupported from mediagoblin.submit.lib import handle_push_urls, run_process_media, \ - prepare_entry + prepare_queue_task @require_active_login @@ -78,7 +78,7 @@ def submit_start(request): # Generate a slug from the title entry.generate_slug() - queue_file = prepare_entry(request, entry, filename) + queue_file = prepare_queue_task(request.app, entry, filename) with queue_file: queue_file.write(request.files['file'].stream.read()) -- 2.25.1