Skip to content

Commit

Permalink
Added the delete_orphaned_thumbs command
Browse files Browse the repository at this point in the history
  • Loading branch information
capooti committed Jul 24, 2018
1 parent 185aa86 commit ee47d18
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hypermap/aggregator/management/commands/delete_orphaned_thumbs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os
from uuid import UUID

from django.conf import settings
from django.core.management.base import BaseCommand

from hypermap.aggregator.models import Layer


class Command(BaseCommand):
help = ("Delete orphaned thumbnails.")

def handle(self, *args, **options):
thumbs_path = os.path.join(settings.MEDIA_ROOT, 'layers')
for filename in os.listdir(thumbs_path):
if filename.endswith(".jpg"):
if Layer.objects.filter(thumbnail='layers/%s' % filename).count() == 0:
print 'Deleting orphaned thumb %s' % filename
fn = os.path.join(thumbs_path, filename)
os.remove(fn)

0 comments on commit ee47d18

Please sign in to comment.