Kill monkeypatching of ProcessingState.

And change the process_foo() API to accept a
processingstate now.

image and video are tested, the others are UNTESTED.
This commit is contained in:
Elrond 2013-01-26 15:28:24 +01:00
parent 715ea49546
commit fb46fa663d
7 changed files with 15 additions and 27 deletions

View 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(

View 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

View 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

View 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')

View 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']

View 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

View 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 ;)