prepare_queue_task: Take app not request.
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 26 Dec 2012 22:40:42 +0000 (23:40 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 26 Dec 2012 22:42:26 +0000 (23:42 +0100)
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
mediagoblin/submit/lib.py
mediagoblin/submit/views.py

index e8f64574cf260a560da5cdcefc3304d71ba6f3b9..0991297d743dd101d379f2ea76963caaffa09615 100644 (file)
@@ -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())
index 6660eb536387d4b9ee9f253b3022e2c76b57b6b2..db5dfe534024422ee78b94a3ff3b7cf031b4c100 100644 (file)
@@ -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
index d36f5f5dd596c3e50f5212f8bc6a48dd79edf32a..2d609b31e2528a729c33a6823b23105c3dd7d603 100644 (file)
@@ -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())