Steps toward working "run" reprocessing command.
This commit sponsored by Philippe Casteleyn. Thank you!
This commit is contained in:
parent
7a414c8d42
commit
4ba5bdd96e
@ -21,6 +21,7 @@ from mediagoblin.db.models import MediaEntry
|
|||||||
from mediagoblin.gmg_commands import util as commands_util
|
from mediagoblin.gmg_commands import util as commands_util
|
||||||
from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
|
from mediagoblin.tools.translate import lazy_pass_to_ugettext as _
|
||||||
from mediagoblin.tools.pluginapi import hook_handle
|
from mediagoblin.tools.pluginapi import hook_handle
|
||||||
|
from mediagoblin.processing import ProcessorDoesNotExist, ProcessorNotEligible
|
||||||
|
|
||||||
|
|
||||||
def reprocess_parser_setup(subparser):
|
def reprocess_parser_setup(subparser):
|
||||||
@ -204,8 +205,17 @@ def _set_media_state(args):
|
|||||||
args[0].state = 'processed'
|
args[0].state = 'processed'
|
||||||
|
|
||||||
|
|
||||||
|
class MediaEntryNotFound(Exception): pass
|
||||||
|
|
||||||
def extract_entry_and_type(media_id):
|
def extract_entry_and_type(media_id):
|
||||||
raise NotImplementedError
|
"""
|
||||||
|
Fetch a media entry, as well as its media type
|
||||||
|
"""
|
||||||
|
entry = MediaEntry.query.filter_by(id=media_id).first()
|
||||||
|
if entry is None:
|
||||||
|
raise MediaEntryNotFound("Can't find media with id '%s'" % media_id)
|
||||||
|
|
||||||
|
return entry.media_type, entry
|
||||||
|
|
||||||
|
|
||||||
def available(args):
|
def available(args):
|
||||||
@ -247,16 +257,29 @@ def available(args):
|
|||||||
|
|
||||||
|
|
||||||
def run(args):
|
def run(args):
|
||||||
### OLD CODE, review
|
media_type, media_entry = extract_entry_and_type(args.media_id)
|
||||||
|
|
||||||
_set_media_state(args)
|
manager_class = hook_handle(('reprocess_manager', media_type))
|
||||||
_set_media_type(args)
|
manager = manager_class()
|
||||||
|
|
||||||
# If no media_ids were given, then try to reprocess all entries
|
# TOOD: Specify in error
|
||||||
if not args[0].media_id:
|
try:
|
||||||
return _reprocess_all(args)
|
processor_class = manager.get_processor(
|
||||||
|
args.reprocess_command, media_entry)
|
||||||
|
except ProcessorDoesNotExist:
|
||||||
|
print 'No such processor "%s" for media with id "%s"' % (
|
||||||
|
args.reprocess_command, media_entry.id)
|
||||||
|
return
|
||||||
|
except ProcessorNotEligible:
|
||||||
|
print 'Processor "%s" exists but media "%s" is not eligible' % (
|
||||||
|
args.reprocess_command, media_entry.id)
|
||||||
|
return
|
||||||
|
|
||||||
return _run_reprocessing(args)
|
reprocess_parser = processor_class.generate_parser()
|
||||||
|
reprocess_args = reprocess_parser.parse_args(args.reprocess_args)
|
||||||
|
|
||||||
|
import pdb
|
||||||
|
pdb.set_trace()
|
||||||
|
|
||||||
|
|
||||||
def reprocess(args):
|
def reprocess(args):
|
||||||
|
@ -333,7 +333,7 @@ class InitialProcessor(CommonImageProcessor):
|
|||||||
description = "Initial processing"
|
description = "Initial processing"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def media_is_eligibile(cls, media_entry):
|
def media_is_eligible(cls, media_entry):
|
||||||
"""
|
"""
|
||||||
Determine if this media type is eligible for processing
|
Determine if this media type is eligible for processing
|
||||||
"""
|
"""
|
||||||
|
@ -126,7 +126,7 @@ class MediaProcessor(object):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def media_is_eligibile(cls, media_entry):
|
def media_is_eligible(cls, media_entry):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
###############################
|
###############################
|
||||||
@ -146,6 +146,11 @@ class MediaProcessor(object):
|
|||||||
##########################################
|
##########################################
|
||||||
|
|
||||||
|
|
||||||
|
class ProcessingKeyError(Exception): pass
|
||||||
|
class ProcessorDoesNotExist(ProcessingKeyError): pass
|
||||||
|
class ProcessorNotEligible(ProcessingKeyError): pass
|
||||||
|
|
||||||
|
|
||||||
class ProcessingManager(object):
|
class ProcessingManager(object):
|
||||||
"""Manages all the processing actions available for a media type
|
"""Manages all the processing actions available for a media type
|
||||||
|
|
||||||
@ -183,6 +188,25 @@ class ProcessingManager(object):
|
|||||||
# Got to figure out what actually goes here before I can write this properly
|
# Got to figure out what actually goes here before I can write this properly
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def get_processor(self, key, entry=None):
|
||||||
|
"""
|
||||||
|
Get the processor with this key.
|
||||||
|
|
||||||
|
If entry supplied, make sure this entry is actually compatible;
|
||||||
|
otherwise raise error.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
processor = self.processors[key]
|
||||||
|
except KeyError:
|
||||||
|
raise ProcessorDoesNotExist(
|
||||||
|
"'%s' processor does not exist for this media type" % key)
|
||||||
|
|
||||||
|
if entry and not processor.media_is_eligible(entry):
|
||||||
|
raise ProcessorNotEligible(
|
||||||
|
"This entry is not eligible for processor with name '%s'" % key)
|
||||||
|
|
||||||
|
return processor
|
||||||
|
|
||||||
def process(self, entry, directive, request):
|
def process(self, entry, directive, request):
|
||||||
"""
|
"""
|
||||||
Process a media entry.
|
Process a media entry.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user