added a set_media_state function. removed the --all flag (just don't enter any media_...
authorRodney Ewing <ewing.rj@gmail.com>
Thu, 1 Aug 2013 21:47:24 +0000 (14:47 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 16 Aug 2013 22:30:13 +0000 (15:30 -0700)
mediagoblin/gmg_commands/reprocess.py

index 9390861f5f99c6bf7f9402605d343e8070840be0..cad75c455384f1a840ef05d0509678894a261793 100644 (file)
@@ -24,10 +24,6 @@ def reprocess_parser_setup(subparser):
         '--available', '-a',
         action="store_true",
         help="List available actions for a given media entry")
-    subparser.add_argument(
-        '--all', '-A',
-        action="store_true",
-        help="Reprocess all media entries")
     subparser.add_argument(
         '--state', '-s',
         help="Reprocess media entries in this state"
@@ -49,7 +45,7 @@ def _set_media_type(args):
         if not args[0].type:
             args[0].type = media_type
         elif args[0].type != media_type:
-            raise Exception(_('The type that you set does not match the type'
+            raise Exception(_('The --type that you set does not match the type'
                               ' of the given media_id.'))
     elif len(args[0].media_id) > 1:
         media_types = []
@@ -65,13 +61,9 @@ def _set_media_type(args):
         if not args[0].type:
             args[0].type = media_types[0]
         elif args[0].type != media_types[0]:
-            raise Exception(_('The type that you set does not match the type'
+            raise Exception(_('The --type that you set does not match the type'
                               ' of the given media_ids.'))
 
-    elif not args[0].type:
-        raise Exception(_('You must provide either a media_id or set the'
-                          ' --type flag'))
-
 
 def _reprocess_all(args):
     if not args[0].type:
@@ -98,15 +90,35 @@ def _run_reprocessing(args):
         return hook_handle(('media_reprocess', args[0].type), args)
 
 
-def reprocess(args):
-    commands_util.setup_app(args[0])
+def _set_media_state(args):
+    if len(args[0].media_id) == 1:
+        args[0].state = MediaEntry.query.filter_by(id=args[0].media_id[0])\
+            .first().state
+
+    elif len(args[0].media_id) > 1:
+        media_states = []
 
-    if not args[0].state:
+        for id in args[0].media_id:
+            media_states.append(MediaEntry.query.filter_by(id=id).first()
+                                .state)
+        for state in media_states:
+            if state != media_states[0]:
+                raise Exception(_('You can only reprocess media that is in the'
+                                  ' same state.'))
+
+        args[0].state = media_states[0]
+
+    elif not args[0].state:
         args[0].state = 'processed'
 
-    if args[0].all:
-        return _reprocess_all(args)
 
+def reprocess(args):
+    commands_util.setup_app(args[0])
+
+    _set_media_state(args)
     _set_media_type(args)
 
+    if not args[0].media_id:
+        return _reprocess_all(args)
+
     return _run_reprocessing(args)