Convert media_ids to int safely.
authorBerker Peksag <berker.peksag@gmail.com>
Fri, 9 May 2014 20:37:49 +0000 (23:37 +0300)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Fri, 13 Jun 2014 15:30:46 +0000 (10:30 -0500)
With this commit, "gmg deletemedia spam,12" will not raise
ValueError anymore.

mediagoblin/gmg_commands/deletemedia.py

index ed1ca4e9fc74f8ad14d075338b4940df27ed4817..ab5a81f63e9891dea86bc44c0de5a941cc57e0ba 100644 (file)
@@ -27,7 +27,10 @@ def parser_setup(subparser):
 def deletemedia(args):
     app = commands_util.setup_app(args)
 
-    media_ids = set(map(int, args.media_ids.split(',')))
+    media_ids = set([int(mid) for mid in args.media_ids.split(',') if mid.isdigit()])
+    if not media_ids:
+        print 'Can\'t find any valid media ID(s).'
+        sys.exit(1)
     found_medias = set()
     filter_ids = app.db.MediaEntry.id.in_(media_ids)
     medias = app.db.MediaEntry.query.filter(filter_ids).all()