Files
dss.api/spa/management/commands/tidy_cdn.py
2016-09-23 00:21:02 +01:00

25 lines
909 B
Python

import os
from django.core.management.base import NoArgsCommand
from core.utils import cdn
from spa.models import Mix
class Command(NoArgsCommand):
def handle_noargs(self, **options):
try:
print('Enumerating items')
items = cdn.enumerate_objects('mixes')
for item in items:
# Check if we have a corresponding mix
uid, type = os.path.splitext(item)
try:
Mix.objects.get(uid=uid)
except Mix.MultipleObjectsReturned:
print('uid: {0} is duplicated'.format(uid))
except Mix.DoesNotExist:
# no mix found - delete the blob
cdn.delete_object('mixes', item)
print(("Deleting blob: {0}".format(uid)))
except Exception as ex:
print(('Debug exception: %s' % ex.message))