Padding on the header-dropdown area
[mediagoblin.git] / mediagoblin / processing / __init__.py
index 282561078ae62a994936629eb14147b816eb7ee9..f3a85940ca74f454e49932f99f0bb95330c4f7a5 100644 (file)
@@ -75,24 +75,19 @@ class FilenameBuilder(object):
 
 
 class ProcessingState(object):
+    """
+    The first and only argument to the "processor" of a media type
+
+    This could be thought of as a "request" to the processor
+    function. It has the main info for the request (media entry)
+    and a bunch of tools for the request on it.
+    It can get more fancy without impacting old media types.
+    """
     def __init__(self, entry):
         self.entry = entry
         self.workbench = None
         self.queued_filename = None
 
-        # Monkey patch us onto the entry
-        # This is needed to keep the current calling convention
-        # for processors:
-        #   def process_FOO(entry):
-        #     proc_state = entry.proc_state
-        #     workbench = proc_state.workbench
-        # When all processors use the new stuff, they should be
-        # rewritten:
-        #   def process_FOO(proc_state):
-        #     entry = proc_state.entry
-        #     workbench = proc_state.workbench
-        entry.proc_state = self
-
     def set_workbench(self, wb):
         self.workbench = wb
 
@@ -110,14 +105,27 @@ 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):
+        # Remove queued media file from storage and database.
+        # queued_filepath is in the task_id directory which should
+        # be removed too, but fail if the directory is not empty to be on
+        # the super-safe side.
         queued_filepath = self.entry.queued_media_file
-        mgg.queue_store.delete_file(queued_filepath)
+        mgg.queue_store.delete_file(queued_filepath)      # rm file
+        mgg.queue_store.delete_dir(queued_filepath[:-1])  # rm dir
         self.entry.queued_media_file = []