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):
29 if options['time'] is not None and time() - t > options['time']:
31 if options['limit'] is not None and counter >= options['limit']:
33 tasks = EbookField.find_all_stale(Book, 1)
36 for field_name, book in tasks:
37 print(field_name, book)
39 getattr(book, field_name).build()
40 except Exception as e: