1 # -*- coding: utf-8 -*-
3 # This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
7 from optparse import make_option
8 from django.contrib.auth.models import User
9 from django.core.management.base import BaseCommand
10 from catalogue.models import Book
13 class XmlUpdaterCommand(BaseCommand):
14 """Base class for creating massive XML-updating commands.
16 In a subclass, provide an XmlUpdater class in the `updater' attribute.
18 option_list = BaseCommand.option_list + (
19 make_option('-q', '--quiet', action='store_false', dest='verbose',
20 default=True, help='Less output'),
21 make_option('-d', '--dry-run', action='store_true', dest='dry_run',
22 default=False, help="Don't actually touch anything"),
23 make_option('-u', '--username', dest='username', metavar='USER',
24 help='Assign commits to this user (required, preferably yourself).'),
28 def handle(self, *args, **options):
29 verbose = options.get('verbose')
30 dry_run = options.get('dry_run')
31 username = options.get('username')
34 user = User.objects.get(username=username)
36 print 'Please provide a username.'
39 books = Book.objects.filter(slug__in=args) if args else None
41 updater = self.updater()
42 updater.run(user, verbose=verbose, dry_run=dry_run, books=books)
43 updater.print_results()