add bulk_run, thumbs, and initial sub_commands
authorRodney Ewing <ewing.rj@gmail.com>
Mon, 12 Aug 2013 21:28:03 +0000 (14:28 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 16 Aug 2013 22:30:18 +0000 (15:30 -0700)
mediagoblin/gmg_commands/reprocess.py
mediagoblin/media_types/image/processing.py
mediagoblin/processing/__init__.py

index bd8039b58ff1ebd9ace36b224e414c9eea37e109..34311f6d2f7c1c056e94a6e95e780f57e8f14df8 100644 (file)
@@ -41,7 +41,7 @@ def reprocess_parser_setup(subparser):
     available_parser = subparsers.add_parser(
         "available",
         help="Find out what actions are available for this media")
-    
+
     available_parser.add_argument(
         "id_or_type",
         help="Media id or media type to check")
@@ -51,27 +51,19 @@ def reprocess_parser_setup(subparser):
         action="store_true",
         help="List argument help for each action available")
 
-    
-    ############################################
-    # run command (TODO: and bulk_run command??)
-    ############################################
-    
+    available_parser.add_argument(
+        "--state",
+        help="The state of media you would like to reprocess")
+
+
+    #############
+    # run command
+    #############
+
     run_parser = subparsers.add_parser(
         "run",
         help="Run a reprocessing on one or more media")
 
-    run_parser.add_argument(
-        '--state', '-s',
-        help="Reprocess media entries in this state"
-             " such as 'failed' or 'processed'")
-    run_parser.add_argument(
-        '--type', '-t',
-        help="The type of media to be reprocessed such as 'video' or 'image'")
-    run_parser.add_argument(
-        '--thumbnails',
-        action="store_true",
-        help="Regenerate thumbnails for all processed media")
-
     run_parser.add_argument(
         'media_id',
         help="The media_entry id(s) you wish to reprocess.")
@@ -86,6 +78,48 @@ def reprocess_parser_setup(subparser):
         help="rest of arguments to the reprocessing tool")
 
 
+    ################
+    # thumbs command
+    ################
+    thumbs = subparsers.add_parser(
+        'thumbs',
+        help='Regenerate thumbs for all processed media')
+
+    thumbs.add_argument(
+        '--size',
+        nargs=2,
+        type=int,
+        metavar=('max_width', 'max_height'))
+
+    #################
+    # initial command
+    #################
+    subparsers.add_parser(
+        'initial',
+        help='Reprocess all failed media')
+
+    ##################
+    # bulk_run command
+    ##################
+    bulk_run_parser = subparsers.add_parser(
+        'bulk_run',
+        help='Run reprocessing on a given media type or state')
+
+    bulk_run_parser.add_argument(
+        'type',
+        help='The type of media you would like to process')
+
+    bulk_run_parser.add_argument(
+        'state',
+        default='processed',
+        help='The state of the media you would like to process. Defaults to' \
+             " 'processed'")
+
+    bulk_run_parser.add_argument(
+        'reprocess_args',
+        nargs=argparse.REMAINDER,
+        help='The rest of the arguments to the reprocessing tool')
+
     ###############
     # help command?
     ###############
@@ -220,7 +254,9 @@ def available(args):
         media_entry = None
         manager = get_processing_manager_for_type(media_type)
 
-    if media_entry is None:
+    if args.state:
+        processors = manager.list_all_processors_by_state(args.state)
+    elif media_entry is None:
         processors = manager.list_all_processors()
     else:
         processors = manager.list_eligible_processors(media_entry)
@@ -271,6 +307,19 @@ def run(args):
         reprocess_action=args.reprocess_command,
         reprocess_info=reprocess_request)
 
+def bulk_run(args):
+    pass
+
+
+def thumbs(args):
+    #TODO regenerate thumbs for all processed media
+    pass
+
+
+def initial(args):
+    #TODO initial processing on all failed media
+    pass
+
 
 def reprocess(args):
     # Run eagerly unless explicetly set not to
@@ -284,3 +333,12 @@ def reprocess(args):
 
     elif args.reprocess_subcommand == "available":
         available(args)
+
+    elif args.reprocess_subcommand == "bulk_run":
+        bulk_run(args)
+
+    elif args.reprocess_subcommand == "thumbs":
+        thumbs(args)
+
+    elif args.reprocess_subcommand == "initial":
+        initial(args)
index 6eb8302cbc85446fa7ad39500b580d7ae738c885..c3dfc5fedfc4f622064f45e860f049ef76d01889 100644 (file)
@@ -203,11 +203,13 @@ class InitialProcessor(CommonImageProcessor):
     description = "Initial processing"
 
     @classmethod
-    def media_is_eligible(cls, entry):
+    def media_is_eligible(cls, entry=None, state=None):
         """
         Determine if this media type is eligible for processing
         """
-        return entry.state in (
+        if not state:
+            state = entry.state
+        return state in (
             "unprocessed", "failed")
 
     ###############################
@@ -256,11 +258,13 @@ class Resizer(CommonImageProcessor):
     description = 'Resize image'
 
     @classmethod
-    def media_is_eligible(cls, entry):
+    def media_is_eligible(cls, entry=None, state=None):
         """
         Determine if this media type is eligible for processing
         """
-        return entry.state in 'processed'
+        if not state:
+            state = entry.state
+        return state in 'processed'
 
     ###############################
     # Command line interface things
index 19e88199a44cbf5a73395df61943c47295d4fea7..1930a480e183c783af5aa1493f1c15b0ce1c26f5 100644 (file)
@@ -137,7 +137,7 @@ class MediaProcessor(object):
         raise NotImplementedError
 
     @classmethod
-    def media_is_eligible(cls, entry):
+    def media_is_eligible(cls, entry=None, state=None):
         raise NotImplementedError
 
     ###############################
@@ -204,7 +204,18 @@ class ProcessingManager(object):
         return [
             processor
             for processor in self.processors.values()
-            if processor.media_is_eligible(entry)]
+            if processor.media_is_eligible(entry=entry)]
+
+    def list_all_processors_by_state(self, state):
+        """
+        List all processors that this media state is eligible to be processed
+        for.
+        """
+        return [
+            processor
+            for processor in self.processors.values()
+            if processor.media_is_eligible(state=state)]
+
 
     def list_all_processors(self):
         return self.processors.values()