# HG changeset patch # User Brian Neal # Date 1445740147 18000 # Node ID ef1558941bc933bd8e9f278a9ec95566d0b387aa # Parent 3ebde23a59d0d365134409dded8346c51746d61d Additional tweaks to ssl_images. diff -r 3ebde23a59d0 -r ef1558941bc9 core/download.py --- a/core/download.py Thu Oct 15 18:35:56 2015 -0500 +++ b/core/download.py Sat Oct 24 21:29:07 2015 -0500 @@ -5,6 +5,7 @@ import os import shutil import tempfile +from urlparse import urlparse import requests @@ -38,10 +39,15 @@ if not path: content_type = r.headers.get('content-type') suffix = mimetypes.guess_extension(content_type) if content_type else '' + + # mimetypes currently returns '.jpe' for jpeg; so fix that up here... if suffix == '.jpe': suffix = '.jpg' - elif suffix is None: - suffix = '' + elif not suffix: + # No content-type so guess based on extension if we can + p = urlparse(url) + suffix = os.path.splitext(p.path)[1] + fd, path = tempfile.mkstemp(suffix=suffix) os.close(fd) diff -r 3ebde23a59d0 -r ef1558941bc9 core/management/commands/ssl_images.py --- a/core/management/commands/ssl_images.py Thu Oct 15 18:35:56 2015 -0500 +++ b/core/management/commands/ssl_images.py Sat Oct 24 21:29:07 2015 -0500 @@ -70,6 +70,11 @@ handler.setFormatter(formatter) logger.addHandler(handler) + requests_log = logging.getLogger("requests.packages.urllib3") + requests_log.setLevel(logging.INFO) + requests_log.propagate = True + requests_log.addHandler(handler) + def resize_image(img_path): """Resizes the image found at img_path if necessary. @@ -85,8 +90,12 @@ if image.size > PHOTO_MAX_SIZE: logger.info('Resizing from %s to %s', image.size, PHOTO_MAX_SIZE) - image.thumbnail(PHOTO_MAX_SIZE, Image.ANTIALIAS) - image.save(img_path) + try: + image.thumbnail(PHOTO_MAX_SIZE, Image.ANTIALIAS) + image.save(img_path) + except IOError as ex: + logger.error("Error resizing image from %s: %s", img_path, ex) + return False return True