From: Elrond Date: Sat, 26 Jan 2013 14:28:24 +0000 (+0100) Subject: Kill monkeypatching of ProcessingState. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=fb46fa663dbd80a66a3a5995dfda730dd3fd52a4;p=mediagoblin.git Kill monkeypatching of ProcessingState. And change the process_foo() API to accept a processingstate now. image and video are tested, the others are UNTESTED. --- diff --git a/mediagoblin/media_types/ascii/processing.py b/mediagoblin/media_types/ascii/processing.py index 254717eb..382cd015 100644 --- a/mediagoblin/media_types/ascii/processing.py +++ b/mediagoblin/media_types/ascii/processing.py @@ -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( diff --git a/mediagoblin/media_types/audio/processing.py b/mediagoblin/media_types/audio/processing.py index e12cefe6..5dffcaf9 100644 --- a/mediagoblin/media_types/audio/processing.py +++ b/mediagoblin/media_types/audio/processing.py @@ -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 diff --git a/mediagoblin/media_types/image/processing.py b/mediagoblin/media_types/image/processing.py index 8afcf90b..ca88d3f4 100644 --- a/mediagoblin/media_types/image/processing.py +++ b/mediagoblin/media_types/image/processing.py @@ -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 diff --git a/mediagoblin/media_types/stl/processing.py b/mediagoblin/media_types/stl/processing.py index 3089f295..77744ac5 100644 --- a/mediagoblin/media_types/stl/processing.py +++ b/mediagoblin/media_types/stl/processing.py @@ -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') diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py index 9040b736..5b9be242 100644 --- a/mediagoblin/media_types/video/processing.py +++ b/mediagoblin/media_types/video/processing.py @@ -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'] diff --git a/mediagoblin/processing/__init__.py b/mediagoblin/processing/__init__.py index 28256107..f9445e28 100644 --- a/mediagoblin/processing/__init__.py +++ b/mediagoblin/processing/__init__.py @@ -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 diff --git a/mediagoblin/processing/task.py b/mediagoblin/processing/task.py index 8614c673..aec50aab 100644 --- a/mediagoblin/processing/task.py +++ b/mediagoblin/processing/task.py @@ -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 ;)