"initial" reprocessing subcommand now works!
authorChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 9 Aug 2013 17:13:53 +0000 (12:13 -0500)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 16 Aug 2013 22:30:15 +0000 (15:30 -0700)
We are on our way now to a working reprocessing system under this
redesign!

This commit sponsored by Bjarni RĂșnar Einarsson.  Thank you!

mediagoblin/gmg_commands/reprocess.py
mediagoblin/media_types/image/__init__.py
mediagoblin/media_types/image/processing.py
mediagoblin/processing/__init__.py

index 30575033910652d0f6358cedc2440d5e516925a1..d6ac99ac4b94c3edc0677cf2a9cdfaedfdffe97b 100644 (file)
@@ -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
+    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):
@@ -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":
index 176893931dfb427dadec32b0420fa3905298ce35..774b9bfa08bc0cfd35af21700e94a46553fd5016 100644 (file)
@@ -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,
 }
index c97811b1c6c8d9e8d3eb875780470ecb6cfca9a9..ea372e76f1ec290c5ed2a4fe2c7331a6259b88fd 100644 (file)
@@ -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
index 66ef2a5348e176a501f8cd20822b39bc785bbf20..95622b9d7359ee3a611c0198bb8b873b979838a2 100644 (file)
@@ -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