Skip to content

Instantly share code, notes, and snippets.

@andybak
Created January 13, 2014 14:28
Show Gist options
  • Save andybak/8401198 to your computer and use it in GitHub Desktop.
Save andybak/8401198 to your computer and use it in GitHub Desktop.
from django.core.management.base import BaseCommand, CommandError
from sorl.thumbnail import default
from shutil import rmtree
from os import listdir
class Command(BaseCommand):
help = (
u'Truncates kvstore and cleanup _thumbs_ folder'
)
args = '[delete]'
option_list = BaseCommand.option_list
def handle(self, cmd, *args, **kwargs):
if cmd not in ['delete']:
raise CommandError('`%s` is not a valid argument' % cmd)
if cmd == 'delete':
default.kvstore.clear()
print 'Cleared the Key Value Store.'
thumbs_folder = default.storage.path('_thumbs_')
for item in listdir(thumbs_folder):
rmtree('/'.join([thumbs_folder, item]))
print "Cleanup thumbnails storage done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment