Updated azure headers management command

This commit is contained in:
Fergal Moran
2015-09-13 14:53:52 +01:00
parent 51568f79dd
commit 42b30b8e3a
12 changed files with 236 additions and 46 deletions

View File

@@ -1,5 +1,6 @@
import os
from django.core.management.base import BaseCommand
from django.core.management.base import LabelCommand, CommandError
import sys
from core.utils import cdn
from spa.models.mix import Mix
@@ -8,8 +9,10 @@ from spa.models.mix import Mix
def _update_azure_headers():
ms = Mix.objects.all()
for m in ms:
print("Update headers for {0}".format(m.title))
cdn.set_azure_details('{0}.mp3'.format(m.uid), 'Deep South Sounds - {0}'.format(m.title), 'mixes')
def _check_missing_mixes():
ms = Mix.objects.all()
found = 0
@@ -28,16 +31,12 @@ def _check_missing_mixes():
print(('{0} of {1} missing'.format(found, Mix.objects.count())))
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
'--delete',
action='store_true',
dest='delete',
default=False,
help='Delete poll instead of closing it')
class Command(LabelCommand):
def handle_noargs(self, **options):
def handle_label(self, label, **options):
pass
def upload_mix(self, **options):
try:
mixes = Mix.objects.filter(archive_updated=False)
for mix in mixes:
@@ -49,12 +48,28 @@ class Command(BaseCommand):
except Exception as ex:
print("Fatal error, bailing. {0}".format(ex.message))
def handle(self, *args, **options):
if len(args) == 0:
print("Commands are \n\t_check_missing_mixes")
elif args[0] == 'check_missing_mix':
def handle(self, *labels, **options):
verbosity = int(options.get('verbosity'))
# Django 1.4 compatibility fix
stdout = options.get('stdout', None)
stdout = stdout if stdout else sys.stdout
stderr = options.get('stderr', None)
stderr = stderr if stderr else sys.stderr
if not labels:
print(self.print_help('thumbnail', ''), file=stderr)
sys.exit(1)
if len(labels) != 1:
raise CommandError('`%s` is not a valid argument' % labels)
label = labels[0]
if label not in ['check_missing_mixes', 'update_azure_headers']:
raise CommandError('`%s` unknown action' % label)
if label == 'check_missing_mixes':
_check_missing_mixes()
elif args[0] == 'update_azure_headers':
if label == 'update_azure_headers':
_update_azure_headers()
else:
print("Commands are \n\tcheck_missing_mix")