Also refactor "copy original into public storage".
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sat, 26 Jan 2013 14:08:12 +0000 (15:08 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Fri, 8 Feb 2013 09:09:37 +0000 (10:09 +0100)
This makes the processing code easier to read/write and
alos will help the reprocessing once we get to it.

Thanks to Joar Wandborg for testing!

mediagoblin/media_types/image/processing.py
mediagoblin/media_types/video/processing.py
mediagoblin/processing/__init__.py

index 541e5109813dce05cb12a087aea7c64c2cea9a20..8afcf90b18313f95011153d87fa82c668afe5d18 100644 (file)
@@ -141,9 +141,7 @@ def process_image(entry):
         medium_filepath = None
 
     # Copy our queued local workbench to its final destination
-    original_filepath = create_pub_filepath(
-            entry, name_builder.fill('{basename}{ext}'))
-    mgg.public_store.copy_local_to_storage(queued_filename, original_filepath)
+    proc_state.copy_original(name_builder.fill('{basename}{ext}'))
 
     # Remove queued media file from storage and database
     proc_state.delete_queue_file()
@@ -151,7 +149,6 @@ def process_image(entry):
     # Insert media file information into database
     media_files_dict = entry.setdefault('media_files', {})
     media_files_dict[u'thumb'] = thumb_filepath
-    media_files_dict[u'original'] = original_filepath
     if medium_filepath:
         media_files_dict[u'medium'] = medium_filepath
 
index 8b966636027864ce331816cdef7ff06e20d40b28..9040b736b6b7fe82f8e578034f35e1066e2c540b 100644 (file)
@@ -116,9 +116,7 @@ def process_video(entry):
     if video_config['keep_original']:
         # Push original file to public storage
         _log.debug('Saving original...')
-        original_filepath = create_pub_filepath(entry, queued_filepath[-1])
-        mgg.public_store.copy_local_to_storage(queued_filename, original_filepath)
-        entry.media_files['original'] = original_filepath
+        proc_state.copy_original(queued_filepath[-1])
 
     # Remove queued media file from storage and database
     proc_state.delete_queue_file()
index 1760d0b93bc83581eefe29150bf4c0cd7053449f..282561078ae62a994936629eb14147b816eb7ee9 100644 (file)
@@ -109,6 +109,12 @@ class ProcessingState(object):
         self.queued_filename = queued_filename
         return queued_filename
 
+    def copy_original(self, target_name, keyname=u"original"):
+        target_filepath = create_pub_filepath(self.entry, target_name)
+        mgg.public_store.copy_local_to_storage(self.get_queued_filename(),
+            target_filepath)
+        self.entry.media_files[keyname] = target_filepath
+
     def delete_queue_file(self):
         queued_filepath = self.entry.queued_media_file
         mgg.queue_store.delete_file(queued_filepath)