Archiving mixes to azure working

This commit is contained in:
Fergal Moran
2014-08-27 18:41:49 +01:00
parent 1578f183c2
commit d43147c35a
2 changed files with 14 additions and 9 deletions

View File

@@ -95,7 +95,7 @@ MIDDLEWARE_CLASSES = (
'django_user_agents.middleware.UserAgentMiddleware',
'pipeline.middleware.MinifyHTMLMiddleware',
# 'spa.middleware.uploadify.SWFUploadMiddleware',
'spa.middleware.sqlprinter.SqlPrintingMiddleware' if DEBUG else None,
#'spa.middleware.sqlprinter.SqlPrintingMiddleware' if DEBUG else None,
#'debug_toolbar.middleware.DebugToolbarMiddleware',
)

View File

@@ -8,6 +8,7 @@ from datetime import datetime, timedelta
from django.db.models import Count
import os
import urlparse
from os.path import isfile, join, basename
class Command(NoArgsCommand):
@@ -17,12 +18,11 @@ class Command(NoArgsCommand):
driver = cls(settings.AZURE_ACCOUNT_NAME, settings.AZURE_ACCOUNT_KEY)
container = driver.get_container(container_name=settings.AZURE_CONTAINER)
mixes = Mix.objects.filter(slug='lsd')
"""
mixes = Mix.objects.filter(upload_date__lte=datetime.today() - timedelta(days=180)) \
.annotate(num_plays=Count('activity_plays')) \
.order_by('num_plays')[:1]
"""
mixes = Mix.objects \
.filter(upload_date__lte=datetime.today() - timedelta(days=180)) \
.exclude(archive_path__isnull=False) \
.annotate(num_plays=Count('activity_plays')) \
.order_by('num_plays')[:10]
for mix in mixes:
if os.path.isfile(mix.get_absolute_path()):
print "Uploading file for: %s" % mix.slug
@@ -36,8 +36,13 @@ class Command(NoArgsCommand):
object_name=file_name
)
print "Uploaded"
mix.archive_path = archive_path
mix.save()
mix.archive_path = archive_path
mix.save()
expired_path = join(settings.MEDIA_ROOT, "mixes/archived")
new_file = os.path.join(expired_path, basename(iterator.name))
os.rename(iterator.name, new_file)
print "done- file is %s" % mix.archive_path
except Exception, ex: