diff --git a/bookwyrm/management/commands/generate_preview_images.py b/bookwyrm/management/commands/generate_preview_images.py index 754f6e9a..28ea1c0c 100644 --- a/bookwyrm/management/commands/generate_preview_images.py +++ b/bookwyrm/management/commands/generate_preview_images.py @@ -6,44 +6,52 @@ from django.core.management.base import BaseCommand from bookwyrm import activitystreams, models, settings, preview_images -def generate_preview_images(): - """generate preview images""" - print(" | Hello! I will be generating preview images for your instance.") - print( - "šŸ§‘ā€šŸŽØ āŽØ This might take quite long if your instance has a lot of books and users." - ) - print(" | āœ§ Thank you for your patience āœ§") - - # Site - sys.stdout.write(" ā†’ Site preview image: ") - preview_images.generate_site_preview_image_task() - sys.stdout.write(" OK šŸ–¼\n") - - # Users - users = models.User.objects.filter( - local=True, - is_active=True, - ) - sys.stdout.write(" ā†’ User preview images ({}): ".format(len(users))) - for user in users: - preview_images.generate_user_preview_image_task(user.id) - sys.stdout.write(".") - sys.stdout.write(" OK šŸ–¼\n") - - # Books - books = models.Book.objects.select_subclasses().filter() - sys.stdout.write(" ā†’ Book preview images ({}): ".format(len(books))) - for book in books: - preview_images.generate_edition_preview_image_task(book.id) - sys.stdout.write(".") - sys.stdout.write(" OK šŸ–¼\n") - - print("šŸ§‘ā€šŸŽØ āŽØ Iā€™m all done! āœ§ Enjoy āœ§") - - class Command(BaseCommand): help = "Generate preview images" + + def add_arguments(self, parser): + parser.add_argument('--all', '-a', action="store_true", help="Generates images for ALL types: site, users and books. Can use a lot of computing power.") + # pylint: disable=no-self-use,unused-argument def handle(self, *args, **options): - """run feed builder""" - generate_preview_images() + """generate preview images""" + self.stdout.write(" | Hello! I will be generating preview images for your instance.") + if options['all']: + self.stdout.write( + "šŸ§‘ā€šŸŽØ āŽØ This might take quite long if your instance has a lot of books and users." + ) + self.stdout.write(" | āœ§ Thank you for your patience āœ§") + else: + self.stdout.write( + "šŸ§‘ā€šŸŽØ āŽØ I will only generate the instance preview image." + ) + self.stdout.write(" | āœ§ Be right back! āœ§") + + # Site + self.stdout.write(" ā†’ Site preview image: ", ending='') + preview_images.generate_site_preview_image_task.delay() + self.stdout.write(" OK šŸ–¼") + + if options['all']: + # Users + users = models.User.objects.filter( + local=True, + is_active=True, + ) + self.stdout.write(" ā†’ User preview images ({}): ".format(len(users)), ending='') + for user in users: + preview_images.generate_user_preview_image_task.delay(user.id) + self.stdout.write(".", ending='') + self.stdout.write(" OK šŸ–¼") + + # Books + books = models.Book.objects.select_subclasses().filter() + self.stdout.write(" ā†’ Book preview images ({}): ".format(len(books)), ending='') + for book in books: + preview_images.generate_edition_preview_image_task.delay(book.id) + self.stdout.write(".", ending='') + self.stdout.write(" OK šŸ–¼") + + self.stdout.write("šŸ§‘ā€šŸŽØ āŽØ Iā€™m all done! āœ§ Enjoy āœ§") + + diff --git a/bw-dev b/bw-dev index 95681b11..5ef049f1 100755 --- a/bw-dev +++ b/bw-dev @@ -108,7 +108,7 @@ case "$CMD" in runweb python manage.py populate_streams ;; generate_preview_images) - runweb python manage.py generate_preview_images + runweb python manage.py generate_preview_images $@ ;; *) echo "Unrecognised command. Try: build, clean, up, initdb, resetdb, makemigrations, migrate, bash, shell, dbshell, restart_celery, test, pytest, test_report, black, populate_feeds, generate_preview_images"