From e67a32142b1635538450ba9885d9486d106bf380 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Sun, 31 Aug 2014 20:04:46 +0100 Subject: [PATCH] Added azure content-disposition fixer --- spa/management/commands/azure_util.py | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 spa/management/commands/azure_util.py diff --git a/spa/management/commands/azure_util.py b/spa/management/commands/azure_util.py new file mode 100644 index 0000000..76275b8 --- /dev/null +++ b/spa/management/commands/azure_util.py @@ -0,0 +1,50 @@ +from azure.storage import BlobService +from azure import WindowsAzureMissingResourceError +from django.core.management.base import NoArgsCommand +from django.utils.encoding import smart_str +from dss.storagesettings import AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY, AZURE_CONTAINER +from spa.models import Mix + + +class Command(NoArgsCommand): + def handle_noargs(self, **options): + try: + blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY) + mixes = Mix.objects.all() + for mix in mixes: + try: + blob_name = "%s.%s" % (mix.uid, mix.filetype) + blob = blob_service.get_blob(AZURE_CONTAINER, blob_name) + if blob: + download_name = smart_str('Deep South Sounds - %s.%s' % (mix.title, mix.filetype)) + blob_service.set_blob_properties( + AZURE_CONTAINER, + blob_name, + x_ms_blob_content_type='application/octet-stream', + x_ms_blob_content_disposition='attachment;filename="%s"' % download_name + ) + print "Processed: %s" % download_name + else: + print "No blob found for: %s" % mix.uid + except WindowsAzureMissingResourceError: + print "No blob found for: %s" % mix.uid + + except Exception, ex: + print "Ooopsies" + + +def _test_set_header(self): + try: + blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY) + blobs = blob_service.list_blobs(AZURE_CONTAINER) + for blob in blobs: + blob_service.set_blob_properties( + AZURE_CONTAINER, + blob.name, + x_ms_blob_content_type='application/octet-stream', + x_ms_blob_content_disposition='attachment;filename="Arg.mp3"' + ) + print "Got properties" + + except Exception, ex: + print "Debug exception: %s" % ex.message \ No newline at end of file