-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the delete_orphaned_thumbs command
- Loading branch information
Showing
1 changed file
with
20 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
hypermap/aggregator/management/commands/delete_orphaned_thumbs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |