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