diff options
author | Rodney Ewing <ewing.rj@gmail.com> | 2013-08-01 14:47:24 -0700 |
---|---|---|
committer | Rodney Ewing <ewing.rj@gmail.com> | 2013-08-16 15:30:13 -0700 |
commit | 243756e0205b2c8c009b6ac3e96eca8923508c38 (patch) | |
tree | 3afd491ed1e4345a830d7d311096c9a27c175fd9 /mediagoblin/gmg_commands/reprocess.py | |
parent | 4a36407d39a18f295e5fc09125fac8e2a7252f55 (diff) | |
download | mediagoblin-243756e0205b2c8c009b6ac3e96eca8923508c38.tar.lz mediagoblin-243756e0205b2c8c009b6ac3e96eca8923508c38.tar.xz mediagoblin-243756e0205b2c8c009b6ac3e96eca8923508c38.zip |
added a set_media_state function. removed the --all flag (just don't enter any media_ids to process all media). slight refactor
Diffstat (limited to 'mediagoblin/gmg_commands/reprocess.py')
-rw-r--r-- | mediagoblin/gmg_commands/reprocess.py | 42 |
1 files 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 @@ -25,10 +25,6 @@ def reprocess_parser_setup(subparser): 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" " such as 'failed' or 'processed'") @@ -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) |