Files
NibasaViewer/viewer/management/commands/makethumbnails.py

39 lines
1.4 KiB
Python
Raw Normal View History

2023-07-30 18:55:12 -04:00
# Django imports.
from django.core.management.base import BaseCommand
from django.conf import settings
# Project imports.
from viewer.utils import make_thumbnail, is_image_file
2023-07-30 18:55:12 -04:00
###########################################################################################
# Command subclass. #
###########################################################################################
2025-01-15 15:14:40 -04:00
2023-07-30 18:55:12 -04:00
class Command(BaseCommand):
"""
Assorted data fix and clean up commands for the Meters module.
"""
def _make_missing_thumbnails(self, directory):
"""
Goes through the GALLERY_ROOT directory recursively and creates a new thumbnail
for each image that does not have a corresponding file (same name) in the THUMBNAILS_ROOT
2025-01-15 15:14:40 -04:00
directory.
2023-07-30 18:55:12 -04:00
"""
# Make a thumbnail for each file in the current directory.
for image in [i for i in directory.iterdir() if i.is_file() and is_image_file(i)]:
2023-07-30 18:55:12 -04:00
make_thumbnail(image)
# Handle each sub-directory recursively.
for subdir in [i for i in directory.iterdir() if i.is_dir()]:
self._make_missing_thumbnails(subdir)
def handle(self, *args, **options):
try:
self._make_missing_thumbnails(settings.GALLERY_ROOT)
2025-01-15 15:14:40 -04:00
except KeyboardInterrupt:
2023-07-30 18:55:12 -04:00
self.stderr.write(self.style.ERROR('\nInterrupted'))