1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.conf import settings
6 from django.core.management.base import BaseCommand
8 from catalogue.fields import EbookField
9 from catalogue.models import Book
12 class Command(BaseCommand):
13 help = 'Schedule regenerating stale ebook files.'
15 def add_arguments(self, parser):
17 '-l', '--limit', type=int,
18 help='Limit number of files to build'
21 '-t', '--time', type=int, metavar='SECONDS',
22 help='Limit timenumber of files to build'
25 def handle(self, **options):
30 if options['time'] is not None and time() - t > options['time']:
32 if options['limit'] is not None and counter >= options['limit']:
35 tasks = EbookField.find_all_stale(Book, options['limit'] or 100)
38 field_name, book = tasks.pop(0)
39 print(field_name, book)
42 getattr(book, field_name).build()
43 except Exception as e: