From e3f9b8b791afdad360099ee5cc319037b2ebd5da Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Wed, 1 Jul 2015 20:38:43 +0100 Subject: [PATCH] Added extra logging to social redirect --- clean_thumbnails | 5 +++ core/utils/cdn.py | 2 - dss/settings.py | 2 +- spa/management/commands/azure_util.py | 15 ++++++- spa/management/commands/helpers.py | 23 +++++++++++ spa/management/commands/waveforms.py | 27 +++++++++---- .../commands/zoom_convert_waveforms.py | 27 +------------ spa/social/views.py | 39 ++++++++++--------- 8 files changed, 84 insertions(+), 56 deletions(-) create mode 100755 clean_thumbnails create mode 100644 spa/management/commands/helpers.py diff --git a/clean_thumbnails b/clean_thumbnails new file mode 100755 index 0000000..1666437 --- /dev/null +++ b/clean_thumbnails @@ -0,0 +1,5 @@ +python manage.py thumbnail cleanup +python manage.py thumbnail clear +python manage.py thumbnail clear_delete_referenced +python manage.py thumbnail clear_delete_all + diff --git a/core/utils/cdn.py b/core/utils/cdn.py index 2ed141f..09f5a80 100755 --- a/core/utils/cdn.py +++ b/core/utils/cdn.py @@ -12,8 +12,6 @@ def upload_to_azure(in_file, filetype, uid): if os.path.isfile(in_file): print "Uploading file for: %s" % in_file file_name = "%s.%s" % (uid, filetype) - archive_path = url_path_join(settings.AZURE_ITEM_BASE_URL, settings.AZURE_CONTAINER, file_name) - cls = get_driver(Provider.AZURE_BLOBS) driver = cls(settings.AZURE_ACCOUNT_NAME, settings.AZURE_ACCOUNT_KEY) container = driver.get_container(container_name=settings.AZURE_CONTAINER) diff --git a/dss/settings.py b/dss/settings.py index 21f3018..3a933af 100755 --- a/dss/settings.py +++ b/dss/settings.py @@ -29,7 +29,7 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': DATABASE_NAME, - 'ADMINUSER': DATABASE_USER, + 'ADMINUSER': 'postgres', 'USER': DATABASE_USER, 'PASSWORD': DATABASE_PASSWORD, 'HOST': DATABASE_HOST, diff --git a/spa/management/commands/azure_util.py b/spa/management/commands/azure_util.py index d18e62e..d86f2b2 100755 --- a/spa/management/commands/azure_util.py +++ b/spa/management/commands/azure_util.py @@ -1,10 +1,18 @@ -from django.core.management.base import NoArgsCommand +from django.core.management.base import NoArgsCommand, BaseCommand from core.utils.cdn import upload_to_azure from spa.models import Mix -class Command(NoArgsCommand): +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') + def handle_noargs(self, **options): try: mixes = Mix.objects.filter(archive_updated=False) @@ -16,3 +24,6 @@ class Command(NoArgsCommand): except Exception, ex: print "Fatal error, bailing. {0}".format(ex.message) + + def handle(self, *args, **options): + pass diff --git a/spa/management/commands/helpers.py b/spa/management/commands/helpers.py new file mode 100644 index 0000000..37b2eac --- /dev/null +++ b/spa/management/commands/helpers.py @@ -0,0 +1,23 @@ +def download_file( url, file_name): + import urllib2 + + u = urllib2.urlopen(url) + f = open(file_name, 'wb') + meta = u.info() + file_size = int(meta.getheaders("Content-Length")[0]) + print "Downloading: %s Bytes: %s" % (file_name, file_size) + + file_size_dl = 0 + block_sz = 8192 + while True: + file_buffer = u.read(block_sz) + if not file_buffer: + break + + file_size_dl += len(file_buffer) + f.write(file_buffer) + status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size) + status += chr(8) * (len(status) + 1) + print status, + + f.close() diff --git a/spa/management/commands/waveforms.py b/spa/management/commands/waveforms.py index 872edcc..8824b7c 100755 --- a/spa/management/commands/waveforms.py +++ b/spa/management/commands/waveforms.py @@ -1,6 +1,7 @@ from optparse import make_option import os from django.core.management.base import NoArgsCommand, BaseCommand +from spa.management.commands import helpers from spa.models.mix import Mix from core.tasks import create_waveform_task @@ -18,20 +19,30 @@ class Command(BaseCommand): @staticmethod def _get_file(mix): - #Check for file in mix directory - processed_file = "" try: - processed_file = mix.get_absolute_path() - if not os.path.isfile(processed_file): - processed_file = mix.get_cache_path() + if mix.archive_updated: + print "Mix is archived: boo hoo" + file_name = "/tmp/%s.mp3" % mix.uid + url = mix.get_stream_url() + print "Downloading: %s To: %s" % (url, file_name) + helpers.download_file(url, file_name) + if not os.path.isfile(file_name): + print "File failed to download" + else: + return file_name + else: + processed_file = mix.get_absolute_path() if not os.path.isfile(processed_file): - print "File for [%s] not found tried\n\t%s\n\t%s" % (mix.title, processed_file, processed_file) - return "" + processed_file = mix.get_cache_path() + if not os.path.isfile(processed_file): + print "File for [%s] not found tried\n\t%s\n\t%s" % (mix.title, processed_file, processed_file) + return "" + return processed_file except Exception, ex: print "Error generating waveform: %s" % ex.message - return processed_file + return "" def handle(self, *args, **options): print "Scanning for missing waveforms" diff --git a/spa/management/commands/zoom_convert_waveforms.py b/spa/management/commands/zoom_convert_waveforms.py index 6fd8e73..ac6a715 100755 --- a/spa/management/commands/zoom_convert_waveforms.py +++ b/spa/management/commands/zoom_convert_waveforms.py @@ -3,32 +3,9 @@ from django.core.management.base import NoArgsCommand from core.utils.waveform import generate_waveform from dss import settings from spa.models.mix import Mix - +import helpers class Command(NoArgsCommand): - def _download_file(self, url, file_name): - import urllib2 - - u = urllib2.urlopen(url) - f = open(file_name, 'wb') - meta = u.info() - file_size = int(meta.getheaders("Content-Length")[0]) - print "Downloading: %s Bytes: %s" % (file_name, file_size) - - file_size_dl = 0 - block_sz = 8192 - while True: - file_buffer = u.read(block_sz) - if not file_buffer: - break - - file_size_dl += len(file_buffer) - f.write(file_buffer) - status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size) - status += chr(8) * (len(status) + 1) - print status, - - f.close() def _convert_remote(self): mixes = Mix.objects.exclude(waveform_version=2) @@ -38,7 +15,7 @@ class Command(NoArgsCommand): file_name = "/tmp/%s.mp3" % mix.uid url = mix.get_stream_url() print "Downloading: %s To: %s" % (url, file_name) - self._download_file(url, file_name) + helpers.download_file(url, file_name) if not os.path.isfile(file_name): print "File failed to download" else: diff --git a/spa/social/views.py b/spa/social/views.py index 767d5c0..feccf2f 100755 --- a/spa/social/views.py +++ b/spa/social/views.py @@ -16,7 +16,6 @@ from spa.models import Playlist from spa.models.mix import Mix from spa.models.userprofile import UserProfile - logger = logging.getLogger(__name__) """ @@ -38,22 +37,25 @@ def facebook_mix(request, slug): except Mix.DoesNotExist: raise Http404 - image = mix.get_image_url('400x400') - mix_url = mix.get_absolute_url() - default = _getPayload(request) - extras = { - "description": mix.description.replace('
', '\n'), - "title": mix.title, - "image_url": image, - "mix_url": 'http://%s%s' % (Site.objects.get_current().domain, mix_url) - } - payload = dict(default.items() + extras.items()) - response = render_to_response( - 'social/facebook/mix.html', - payload, - context_instance=RequestContext(request) - ) - return response + try: + image = mix.get_image_url('400x400') + mix_url = mix.get_absolute_url() + default = _getPayload(request) + extras = { + "description": mix.description.replace('
', '\n'), + "title": mix.title, + "image_url": image, + "mix_url": 'http://%s%s' % (Site.objects.get_current().domain, mix_url) + } + payload = dict(default.items() + extras.items()) + response = render_to_response( + 'social/facebook/mix.html', + payload, + context_instance=RequestContext(request) + ) + return response + except Exception, ex: + logger.error(ex.message) def playlist(request, args): @@ -156,7 +158,8 @@ def post_like(request, mix): def delete_like(request, uid): try: - tokens = SocialToken.objects.filter(account__user=request.user, account__provider='facebook') + tokens = SocialToken.objects.filter(account__user=request.user, + account__provider='facebook') for token in tokens: url = "https://graph.facebook.com/%s" % uid values = {