Cleaning some requirements.
[wolnelektury.git] / src / catalogue / management / commands / gencover.py
1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
3 #
4 from django.core.management.base import BaseCommand
5
6 from catalogue.models import Book
7 from librarian.cover import make_cover
8
9
10 class Command(BaseCommand):
11     def add_arguments(self, parser):
12         parser.add_argument('slug')
13         parser.add_argument('--width', type=int)
14         parser.add_argument('--height', type=int)
15         parser.add_argument('--bleed', action='store_true')
16         parser.add_argument('--cover-class', type=str)
17
18     def handle(self, *args, **options):
19         slug = options['slug']
20         width = options['width']
21         height = options.get('height')
22         cover_class = options.get('cover_class')
23         bleed = 20 if options['bleed'] else 0
24         wldoc = Book.objects.get(slug=slug).wldocument()
25         kwargs = {}
26         if cover_class:
27             kwargs['cover_class'] = cover_class
28         cover = make_cover(wldoc.book_info, width=width, height=height, bleed=bleed, **kwargs)
29         cover.save('%s.jpg' % slug)