"initial" reprocessing subcommand now works!
We are on our way now to a working reprocessing system under this redesign! This commit sponsored by Bjarni Rúnar Einarsson. Thank you!
This commit is contained in:
parent
58bacb33ac
commit
85ead8ac3c
@ -199,13 +199,35 @@ def _set_media_state(args):
|
||||
args[0].state = 'processed'
|
||||
|
||||
|
||||
def extract_entry_and_type(media_id):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
def available(args):
|
||||
# Get the media type, either by looking up media id, or by specific type
|
||||
|
||||
### TODO: look up by id
|
||||
try:
|
||||
media_id = int(args.id_or_type)
|
||||
media_type, media_entry = extract_entry_and_type(media_id)
|
||||
except ValueError:
|
||||
media_type = args.id_or_type
|
||||
media_entry = None
|
||||
|
||||
#
|
||||
pass
|
||||
manager_class = hook_handle(('reprocess_manager', media_type))
|
||||
manager = manager_class()
|
||||
|
||||
if media_entry is None:
|
||||
processors = manager.list_all_processors()
|
||||
else:
|
||||
processors = manager.list_eligible_processors(media_entry)
|
||||
|
||||
print "Available processors:"
|
||||
print "---------------------"
|
||||
|
||||
for processor in processors:
|
||||
if processor.description:
|
||||
print " - %s: %s" % (processor.name, processor.description)
|
||||
else:
|
||||
print " - %s" % processor.name
|
||||
|
||||
|
||||
def run(args):
|
||||
@ -214,7 +236,6 @@ def run(args):
|
||||
# Run eagerly unless explicetly set not to
|
||||
if not args.celery:
|
||||
os.environ['CELERY_ALWAYS_EAGER'] = 'true'
|
||||
commands_util.setup_app(args)
|
||||
|
||||
_set_media_state(args)
|
||||
_set_media_type(args)
|
||||
@ -227,6 +248,8 @@ def run(args):
|
||||
|
||||
|
||||
def reprocess(args):
|
||||
commands_util.setup_app(args)
|
||||
|
||||
if args.reprocess_subcommand == "run":
|
||||
run(args)
|
||||
elif args.reprocess_subcommand == "available":
|
||||
|
@ -18,7 +18,7 @@ import logging
|
||||
|
||||
from mediagoblin.media_types import MediaManagerBase
|
||||
from mediagoblin.media_types.image.processing import ProcessImage, \
|
||||
sniff_handler
|
||||
sniff_handler, ImageProcessingManager
|
||||
from mediagoblin.tools import pluginapi
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
@ -72,6 +72,6 @@ hooks = {
|
||||
'get_media_type_and_manager': get_media_type_and_manager,
|
||||
'sniff_handler': sniff_handler,
|
||||
('media_manager', MEDIA_TYPE): lambda: ImageMediaManager,
|
||||
('reprocess_action', MEDIA_TYPE): ProcessImage().reprocess_action,
|
||||
('media_reprocess', MEDIA_TYPE): ProcessImage().media_reprocess,
|
||||
('reprocess_manager', MEDIA_TYPE): lambda: ImageProcessingManager,
|
||||
# ('media_reprocess', MEDIA_TYPE): ProcessImage().media_reprocess,
|
||||
}
|
||||
|
@ -24,7 +24,9 @@ import argparse
|
||||
|
||||
from mediagoblin import mg_globals as mgg
|
||||
from mediagoblin.db.models import MediaEntry
|
||||
from mediagoblin.processing import BadMediaFail, FilenameBuilder
|
||||
from mediagoblin.processing import (
|
||||
BadMediaFail, FilenameBuilder,
|
||||
MediaProcessor, ProcessingManager)
|
||||
from mediagoblin.submit.lib import run_process_media
|
||||
from mediagoblin.tools.exif import exif_fix_image_orientation, \
|
||||
extract_exif, clean_exif, get_gps_data, get_useful, \
|
||||
@ -302,6 +304,66 @@ class ProcessImage(object):
|
||||
|
||||
return reprocess_info
|
||||
|
||||
|
||||
class CommonImageProcessor(MediaProcessor):
|
||||
"""
|
||||
Provides a base for various media processing steps
|
||||
"""
|
||||
# Common resizing step
|
||||
def resize_step(self):
|
||||
pass
|
||||
|
||||
def _add_width_height_args(self, parser):
|
||||
parser.add_argument(
|
||||
"--width", default=None,
|
||||
help=(
|
||||
"Width of the resized image (if not using defaults)"))
|
||||
parser.add_argument(
|
||||
"--height", default=None,
|
||||
help=(
|
||||
"Height of the resized image (if not using defaults)"))
|
||||
|
||||
|
||||
class InitialProcessor(CommonImageProcessor):
|
||||
"""
|
||||
Initial processing step for new images
|
||||
"""
|
||||
name = "initial"
|
||||
description = "Initial processing"
|
||||
|
||||
@classmethod
|
||||
def media_is_eligibile(self, media_entry):
|
||||
"""
|
||||
Determine if this media type is eligible for processing
|
||||
"""
|
||||
return media_entry.state in (
|
||||
"unprocessed", "failed")
|
||||
|
||||
###############################
|
||||
# Command line interface things
|
||||
###############################
|
||||
|
||||
@classmethod
|
||||
def generate_parser(self):
|
||||
parser = argparse.ArgumentParser(
|
||||
description=self.description)
|
||||
|
||||
self._add_width_height_args(parser)
|
||||
|
||||
return parser
|
||||
|
||||
@classmethod
|
||||
def args_to_request(self, args):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
|
||||
class ImageProcessingManager(ProcessingManager):
|
||||
def __init__(self):
|
||||
super(self.__class__, self).__init__()
|
||||
self.add_processor(InitialProcessor)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import pprint
|
||||
|
@ -14,6 +14,7 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from collections import OrderedDict
|
||||
import logging
|
||||
import os
|
||||
|
||||
@ -153,7 +154,7 @@ class ProcessingManager(object):
|
||||
"""
|
||||
def __init__(self):
|
||||
# Dict of all MediaProcessors of this media type
|
||||
self.processors = {}
|
||||
self.processors = OrderedDict()
|
||||
|
||||
def add_processor(self, processor):
|
||||
"""
|
||||
@ -172,9 +173,12 @@ class ProcessingManager(object):
|
||||
"""
|
||||
return [
|
||||
processor
|
||||
for processor in self.processors.keys()
|
||||
for processor in self.processors.values()
|
||||
if processor.media_is_eligible(entry)]
|
||||
|
||||
def list_all_processors(self):
|
||||
return self.processors.values()
|
||||
|
||||
def gen_process_request_via_cli(self, subparser):
|
||||
# Got to figure out what actually goes here before I can write this properly
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user