Added the new plugin I've been working at all summer at this link:
[mediagoblin.git] / mediagoblin / gmg_commands / deletemedia.py
1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 from mediagoblin.gmg_commands import util as commands_util
18
19
20 def parser_setup(subparser):
21 subparser.add_argument('media_ids',
22 help='Comma separated list of media IDs to will be deleted.')
23
24
25 def deletemedia(args):
26 app = commands_util.setup_app(args)
27
28 media_ids = set(map(int, args.media_ids.split(',')))
29 found_medias = set()
30 filter_ids = app.db.MediaEntry.id.in_(media_ids)
31 medias = app.db.MediaEntry.query.filter(filter_ids).all()
32 for media in medias:
33 found_medias.add(media.id)
34 media.delete()
35 print 'Media ID %d has been deleted.' % media.id
36 for media in media_ids - found_medias:
37 print 'Can\'t find a media with ID %d.' % media
38 print 'Done.'