mirror of
https://github.com/fergalmoran/dss.api.git
synced 2026-01-04 23:54:27 +00:00
Updated some CDN urls
This commit is contained in:
@@ -48,6 +48,7 @@ def set_azure_details(blob_name, download_name):
|
||||
except Exception, ex:
|
||||
print "Error processing blob %s: %s" % (download_name, ex.message)
|
||||
|
||||
|
||||
def file_exists(url):
|
||||
import httplib
|
||||
from urlparse import urlparse
|
||||
@@ -57,3 +58,18 @@ def file_exists(url):
|
||||
|
||||
r = c.getresponse()
|
||||
return r.status == 200
|
||||
|
||||
|
||||
def enumerate_objects(container):
|
||||
blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY)
|
||||
blobs = blob_service.list_blobs(container)
|
||||
items = []
|
||||
for blob in blobs:
|
||||
items.append(blob.name)
|
||||
|
||||
return items
|
||||
|
||||
|
||||
def delete_object(container, name):
|
||||
blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY)
|
||||
blob_service.delete_blob(container, name)
|
||||
@@ -11,12 +11,9 @@ logger = logging.getLogger('dss')
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dss.settings')
|
||||
|
||||
from django.conf import settings
|
||||
print 'Connecting to celery app'
|
||||
app = Celery('dss')
|
||||
print 'Connected'
|
||||
|
||||
# Using a string here means the worker will not have to
|
||||
# pickle the object when using Windows.
|
||||
app.config_from_object('django.conf:settings')
|
||||
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
|
||||
print 'Discovered tasks'
|
||||
|
||||
22
spa/management/commands/tidy_cdn.py
Executable file
22
spa/management/commands/tidy_cdn.py
Executable file
@@ -0,0 +1,22 @@
|
||||
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.DoesNotExist:
|
||||
# no mix found - delete the blob
|
||||
cdn.delete_object('mixes', item)
|
||||
print "Deleting blob: {0}".format(uid)
|
||||
except Exception, ex:
|
||||
print "Debug exception: %s" % ex.message
|
||||
@@ -10,7 +10,7 @@ from dss import localsettings, settings
|
||||
|
||||
|
||||
class BaseModel(models.Model):
|
||||
logger = logging.getLogger(__name__)
|
||||
logger = logging.getLogger('dss')
|
||||
|
||||
object_created = models.DateTimeField(auto_now_add=True, default=datetime.now())
|
||||
object_updated = models.DateTimeField(auto_now=True, default=datetime.now(), db_index=True)
|
||||
|
||||
@@ -166,15 +166,10 @@ class Mix(BaseModel):
|
||||
|
||||
def get_image_url(self, size='200x200', default=''):
|
||||
try:
|
||||
if self.mix_image.name and self.mix_image.storage.exists(self.mix_image.name):
|
||||
ret = get_thumbnail(self.mix_image, size, crop='center')
|
||||
return "%s/%s" % (settings.MEDIA_URL, ret.name)
|
||||
else:
|
||||
return self.user.get_sized_avatar_image(170, 170)
|
||||
return "{0}{1}".format(settings.MIXIMAGE_URL, os.path.basename(self.mix_image.name))
|
||||
except Exception, ex:
|
||||
pass
|
||||
|
||||
return super(Mix, self).get_image_url(self.mix_image, settings.DEFAULT_TRACK_IMAGE)
|
||||
self.logger.exception(ex)
|
||||
return super(Mix, self).get_image_url(self.mix_image, settings.DEFAULT_TRACK_IMAGE)
|
||||
|
||||
def get_stream_url(self):
|
||||
if self.archive_path in [None, '']:
|
||||
|
||||
Reference in New Issue
Block a user