From 55cfa3406390732173195bb920bf3f86bd1ce9f4 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sun, 11 Aug 2013 15:22:43 -0500 Subject: [PATCH] Renaming the processing manager stuff to be less ambiguous. BONUS COMMIT to Ben Finney and the Free Software Melbourne crew. :) IRONY: Initially I committed this as "media manager". --- mediagoblin/gmg_commands/reprocess.py | 8 ++++---- mediagoblin/processing/__init__.py | 13 ++++++++++--- mediagoblin/processing/task.py | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/mediagoblin/gmg_commands/reprocess.py b/mediagoblin/gmg_commands/reprocess.py index 9a9196bb..10ab50ab 100644 --- a/mediagoblin/gmg_commands/reprocess.py +++ b/mediagoblin/gmg_commands/reprocess.py @@ -24,7 +24,7 @@ from mediagoblin.tools.translate import lazy_pass_to_ugettext as _ from mediagoblin.tools.pluginapi import hook_handle from mediagoblin.processing import ( ProcessorDoesNotExist, ProcessorNotEligible, - get_entry_and_manager, get_manager_for_type) + get_entry_and_processing_manager, get_processing_manager_for_type) def reprocess_parser_setup(subparser): @@ -211,12 +211,12 @@ def _set_media_state(args): def available(args): # Get the media type, either by looking up media id, or by specific type try: - media_entry, manager = get_entry_and_manager(args.id_or_type) + media_entry, manager = get_entry_and_processing_manager(args.id_or_type) media_type = media_entry.type except ValueError: media_type = args.id_or_type media_entry = None - manager = get_manager_for_type(media_type) + manager = get_processing_manager_for_type(media_type) if media_entry is None: processors = manager.list_all_processors() @@ -245,7 +245,7 @@ def available(args): def run(args): - media_entry, manager = get_entry_and_manager(args.media_id) + media_entry, manager = get_entry_and_processing_manager(args.media_id) # TODO: (maybe?) This could probably be handled entirely by the # processor class... diff --git a/mediagoblin/processing/__init__.py b/mediagoblin/processing/__init__.py index b668baa7..02dba2f9 100644 --- a/mediagoblin/processing/__init__.py +++ b/mediagoblin/processing/__init__.py @@ -120,6 +120,13 @@ class MediaProcessor(object): # Should be initialized at time of processing, at least self.workbench = None + def __enter__(self): + self.workbench = mgg.workbench_manager.create() + + def __exit__(self, *args): + self.workbench.destroy() + self.workbench = None + # @with_workbench def process(self, **kwargs): """ @@ -230,7 +237,7 @@ def request_from_args(args, which_args): class MediaEntryNotFound(Exception): pass -def get_manager_for_type(media_type): +def get_processing_manager_for_type(media_type): """ Get the appropriate media manager for this type """ @@ -240,7 +247,7 @@ def get_manager_for_type(media_type): return manager -def get_entry_and_manager(media_id): +def get_entry_and_processing_manager(media_id): """ Get a MediaEntry, its media type, and its manager all in one go. @@ -250,7 +257,7 @@ def get_entry_and_manager(media_id): if entry is None: raise MediaEntryNotFound("Can't find media with id '%s'" % media_id) - manager = get_manager_for_type(entry.media_type) + manager = get_processing_manager_for_type(entry.media_type) return entry, manager diff --git a/mediagoblin/processing/task.py b/mediagoblin/processing/task.py index 240be4e5..397514d0 100644 --- a/mediagoblin/processing/task.py +++ b/mediagoblin/processing/task.py @@ -23,7 +23,7 @@ from celery import registry, task from mediagoblin import mg_globals as mgg from . import mark_entry_failed, BaseProcessingFail from mediagoblin.tools.processing import json_processing_callback -from mediagoblin.processing import get_entry_and_manager +from mediagoblin.processing import get_entry_and_processing_manager _log = logging.getLogger(__name__) logging.basicConfig() @@ -79,7 +79,7 @@ class ProcessMedia(task.Task): info for the media_type. """ reprocess_info = reprocess_info or {} - entry, manager = get_entry_and_manager(media_id) + entry, manager = get_entry_and_processing_manager(media_id) # Try to process, and handle expected errors. try: -- 2.25.1