Created
January 13, 2014 14:28
-
-
Save andybak/8401198 to your computer and use it in GitHub Desktop.
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
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." |
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
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment