Create ProcessingState.store_public.
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 3 Apr 2013 16:52:17 +0000 (18:52 +0200)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Wed, 3 Apr 2013 16:52:17 +0000 (18:52 +0200)
The ideas is by Alon Levy.

Use it in ProcessingState.copy_original for now.

mediagoblin/processing/__init__.py

index f9445e280fc8e75fd6984c049a59abea8a7a396b..02462567d5464b2bd91f5fb35ae4a2f063143647 100644 (file)
@@ -97,9 +97,17 @@ class ProcessingState(object):
         return queued_filename
 
     def copy_original(self, target_name, keyname=u"original"):
+        self.store_public(keyname, self.get_queued_filename(), target_name)
+
+    def store_public(self, keyname, local_file, target_name=None):
+        if target_name is None:
+            target_name = os.path.basename(local_file)
         target_filepath = create_pub_filepath(self.entry, target_name)
-        mgg.public_store.copy_local_to_storage(self.get_queued_filename(),
-            target_filepath)
+        if keyname in self.entry.media_files:
+            _log.warn("store_public: keyname %r already used for file %r, "
+                      "replacing with %r", keyname,
+                      self.entry.media_files[keyname], target_filepath)
+        mgg.public_store.copy_local_to_storage(local_file, target_filepath)
         self.entry.media_files[keyname] = target_filepath
 
     def delete_queue_file(self):