aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodney Ewing <ewing.rj@gmail.com>2013-08-01 15:40:26 -0700
committerRodney Ewing <ewing.rj@gmail.com>2013-08-16 15:30:13 -0700
commit842ba30529040fb47ac9905df6373d7c1f0286ed (patch)
treef3ace474bb58a85fc7e6d6d2cf2c05528c648621
parent11a99d787f899808b10410e271491cbdfb69e55f (diff)
downloadmediagoblin-842ba30529040fb47ac9905df6373d7c1f0286ed.tar.lz
mediagoblin-842ba30529040fb47ac9905df6373d7c1f0286ed.tar.xz
mediagoblin-842ba30529040fb47ac9905df6373d7c1f0286ed.zip
make media_id an optional argument
-rw-r--r--mediagoblin/gmg_commands/reprocess.py82
1 files changed, 42 insertions, 40 deletions
diff --git a/mediagoblin/gmg_commands/reprocess.py b/mediagoblin/gmg_commands/reprocess.py
index 60df697f..f3445ea6 100644
--- a/mediagoblin/gmg_commands/reprocess.py
+++ b/mediagoblin/gmg_commands/reprocess.py
@@ -32,37 +32,38 @@ def reprocess_parser_setup(subparser):
'--type', '-t',
help="The type of media to be reprocessed such as 'video' or 'image'")
subparser.add_argument(
- 'media_id',
+ '--media_id',
nargs='*',
help="The media_entry id(s) you wish to reprocess.")
def _set_media_type(args):
- if len(args[0].media_id) == 1:
- media_type = MediaEntry.query.filter_by(id=args[0].media_id[0])\
- .first().media_type.split('.')[-1]
-
- 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'
- ' of the given media_id.'))
- elif len(args[0].media_id) > 1:
- media_types = []
-
- for id in args[0].media_id:
- media_types.append(MediaEntry.query.filter_by(id=id).first()
- .media_type.split('.')[-1])
- for type in media_types:
- if media_types[0] != type:
- raise Exception((u'You cannot reprocess different media_types'
- ' at the same time.'))
-
- 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'
- ' of the given media_ids.'))
+ if args[0].media_id:
+ if len(args[0].media_id) == 1:
+ media_type = MediaEntry.query.filter_by(id=args[0].media_id[0])\
+ .first().media_type.split('.')[-1]
+
+ 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'
+ ' of the given media_id.'))
+ elif len(args[0].media_id) > 1:
+ media_types = []
+
+ for id in args[0].media_id:
+ media_types.append(MediaEntry.query.filter_by(id=id).first()
+ .media_type.split('.')[-1])
+ for type in media_types:
+ if media_types[0] != type:
+ raise Exception((u'You cannot reprocess different media_types'
+ ' at the same time.'))
+
+ 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'
+ ' of the given media_ids.'))
def _reprocess_all(args):
@@ -99,24 +100,25 @@ def _run_reprocessing(args):
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
+ if args[0].media_id:
+ 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 = []
+ elif len(args[0].media_id) > 1:
+ media_states = []
- 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.'))
+ 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]
+ args[0].state = media_states[0]
- elif not args[0].state:
+ if not args[0].state:
args[0].state = 'processed'