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
+ 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
+
+ manager_class = hook_handle(('reprocess_manager', media_type))
+ manager = manager_class()
- ### TODO: look up by id
+ if media_entry is None:
+ processors = manager.list_all_processors()
+ else:
+ processors = manager.list_eligible_processors(media_entry)
+
+ print "Available processors:"
+ print "---------------------"
- #
- pass
+ for processor in processors:
+ if processor.description:
+ print " - %s: %s" % (processor.name, processor.description)
+ else:
+ print " - %s" % processor.name
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)
def reprocess(args):
+ commands_util.setup_app(args)
+
if args.reprocess_subcommand == "run":
run(args)
elif args.reprocess_subcommand == "available":
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__)
'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,
}
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, \
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
# 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
"""
def __init__(self):
# Dict of all MediaProcessors of this media type
- self.processors = {}
+ self.processors = OrderedDict()
def add_processor(self, processor):
"""
"""
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