From 243756e0205b2c8c009b6ac3e96eca8923508c38 Mon Sep 17 00:00:00 2001 From: Rodney Ewing Date: Thu, 1 Aug 2013 14:47:24 -0700 Subject: [PATCH] added a set_media_state function. removed the --all flag (just don't enter any media_ids to process all media). slight refactor --- mediagoblin/gmg_commands/reprocess.py | 42 +++++++++++++++++---------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/mediagoblin/gmg_commands/reprocess.py b/mediagoblin/gmg_commands/reprocess.py index 9390861f..cad75c45 100644 --- a/mediagoblin/gmg_commands/reprocess.py +++ b/mediagoblin/gmg_commands/reprocess.py @@ -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) -- 2.25.1