Kill monkeypatching of ProcessingState.
authorElrond <elrond+mediagoblin.org@samba-tng.org>
Sat, 26 Jan 2013 14:28:24 +0000 (15:28 +0100)
committerElrond <elrond+mediagoblin.org@samba-tng.org>
Fri, 8 Feb 2013 09:09:37 +0000 (10:09 +0100)
And change the process_foo() API to accept a
processingstate now.

image and video are tested, the others are UNTESTED.

mediagoblin/media_types/ascii/processing.py
mediagoblin/media_types/audio/processing.py
mediagoblin/media_types/image/processing.py
mediagoblin/media_types/stl/processing.py
mediagoblin/media_types/video/processing.py
mediagoblin/processing/__init__.py
mediagoblin/processing/task.py

index 254717ebf725ab627819e0ca1688a0e41f0515ee..382cd01500ace6f1b8703ebae38b4648d26adca7 100644 (file)
@@ -19,7 +19,6 @@ import Image
 import logging
 
 from mediagoblin import mg_globals as mgg
-from mediagoblin.decorators import get_workbench
 from mediagoblin.processing import create_pub_filepath
 from mediagoblin.media_types.ascii import asciitoimage
 
@@ -39,13 +38,14 @@ def sniff_handler(media_file, **kw):
     return False
 
 
-@get_workbench
-def process_ascii(entry, workbench=None):
+def process_ascii(proc_state):
     """Code to process a txt file. Will be run by celery.
 
     A Workbench() represents a local tempory dir. It is automatically
     cleaned up when this function exits. 
     """
+    entry = proc_state.entry
+    workbench = proc_state.workbench
     ascii_config = mgg.global_config['media_type:mediagoblin.media_types.ascii']
     # Conversions subdirectory to avoid collisions
     conversions_subdir = os.path.join(
index e12cefe659a48cae0d7e42e6505b08394eaf2463..5dffcaf98a53e359cc3b1f6785f04cf6323cba4f 100644 (file)
@@ -19,7 +19,6 @@ from tempfile import NamedTemporaryFile
 import os
 
 from mediagoblin import mg_globals as mgg
-from mediagoblin.decorators import get_workbench
 from mediagoblin.processing import (create_pub_filepath, BadMediaFail,
     FilenameBuilder, ProgressCallback)
 
@@ -43,13 +42,14 @@ def sniff_handler(media_file, **kw):
     return False
 
 
-@get_workbench
-def process_audio(entry, workbench=None):
+def process_audio(proc_state):
     """Code to process uploaded audio. Will be run by celery.
 
     A Workbench() represents a local tempory dir. It is automatically
     cleaned up when this function exits.
     """
+    entry = proc_state.entry
+    workbench = proc_state.workbench
     audio_config = mgg.global_config['media_type:mediagoblin.media_types.audio']
 
     queued_filepath = entry.queued_media_file
index 8afcf90b18313f95011153d87fa82c668afe5d18..ca88d3f4ef29262c9a71eddea2eeba9de25b46d7 100644 (file)
@@ -94,13 +94,13 @@ def sniff_handler(media_file, **kw):
     return False
 
 
-def process_image(entry):
+def process_image(proc_state):
     """Code to process an image. Will be run by celery.
 
     A Workbench() represents a local tempory dir. It is automatically
     cleaned up when this function exits.
     """
-    proc_state = entry.proc_state
+    entry = proc_state.entry
     workbench = proc_state.workbench
 
     # Conversions subdirectory to avoid collisions
index 3089f29512d917461a8dc19212a87001c76f9ba6..77744ac52b58ec889945c8e47ea5717dfce5b6f5 100644 (file)
@@ -21,7 +21,6 @@ import subprocess
 import pkg_resources
 
 from mediagoblin import mg_globals as mgg
-from mediagoblin.decorators import get_workbench
 from mediagoblin.processing import create_pub_filepath, \
     FilenameBuilder
 
@@ -76,13 +75,15 @@ def blender_render(config):
         env=env)
 
 
-@get_workbench
-def process_stl(entry, workbench=None):
+def process_stl(proc_state):
     """Code to process an stl or obj model. Will be run by celery.
 
     A Workbench() represents a local tempory dir. It is automatically
     cleaned up when this function exits.
     """
+    entry = proc_state.entry
+    workbench = proc_state.workbench
+
     queued_filepath = entry.queued_media_file
     queued_filename = workbench.localized_file(
         mgg.queue_store, queued_filepath, 'source')
index 9040b736b6b7fe82f8e578034f35e1066e2c540b..5b9be2425e7c72972b234dec69726afb2e86259a 100644 (file)
@@ -52,7 +52,7 @@ def sniff_handler(media_file, **kw):
     return False
 
 
-def process_video(entry):
+def process_video(proc_state):
     """
     Process a video entry, transcode the queued media files (originals) and
     create a thumbnail for the entry.
@@ -60,7 +60,7 @@ def process_video(entry):
     A Workbench() represents a local tempory dir. It is automatically
     cleaned up when this function exits.
     """
-    proc_state = entry.proc_state
+    entry = proc_state.entry
     workbench = proc_state.workbench
     video_config = mgg.global_config['media_type:mediagoblin.media_types.video']
 
index 282561078ae62a994936629eb14147b816eb7ee9..f9445e280fc8e75fd6984c049a59abea8a7a396b 100644 (file)
@@ -80,19 +80,6 @@ class ProcessingState(object):
         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
 
index 8614c673d63288ff1f6df9f88c7a1616be4e8222..aec50aabdb11cfcc9460cd11709fe291ebfb95a0 100644 (file)
@@ -89,7 +89,7 @@ class ProcessMedia(task.Task):
             with mgg.workbench_manager.create() as workbench:
                 proc_state.set_workbench(workbench)
                 # run the processing code
-                entry.media_manager['processor'](entry)
+                entry.media_manager['processor'](proc_state)
 
             # We set the state to processed and save the entry here so there's
             # no need to save at the end of the processing stage, probably ;)