comparison core/management/commands/ssl_images.py @ 981:ef1558941bc9

Additional tweaks to ssl_images.
author Brian Neal <bgneal@gmail.com>
date Sat, 24 Oct 2015 21:29:07 -0500
parents 3ebde23a59d0
children 7db9037915c4
comparison
equal deleted inserted replaced
980:3ebde23a59d0 981:ef1558941bc9
68 handler = logging.FileHandler(filename=LOGFILE, encoding='utf-8') 68 handler = logging.FileHandler(filename=LOGFILE, encoding='utf-8')
69 formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') 69 formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
70 handler.setFormatter(formatter) 70 handler.setFormatter(formatter)
71 logger.addHandler(handler) 71 logger.addHandler(handler)
72 72
73 requests_log = logging.getLogger("requests.packages.urllib3")
74 requests_log.setLevel(logging.INFO)
75 requests_log.propagate = True
76 requests_log.addHandler(handler)
77
73 78
74 def resize_image(img_path): 79 def resize_image(img_path):
75 """Resizes the image found at img_path if necessary. 80 """Resizes the image found at img_path if necessary.
76 81
77 Returns True if the image was resized or resizing wasn't necessary. 82 Returns True if the image was resized or resizing wasn't necessary.
83 logger.error("Error opening %s: %s", img_path, ex) 88 logger.error("Error opening %s: %s", img_path, ex)
84 return False 89 return False
85 90
86 if image.size > PHOTO_MAX_SIZE: 91 if image.size > PHOTO_MAX_SIZE:
87 logger.info('Resizing from %s to %s', image.size, PHOTO_MAX_SIZE) 92 logger.info('Resizing from %s to %s', image.size, PHOTO_MAX_SIZE)
88 image.thumbnail(PHOTO_MAX_SIZE, Image.ANTIALIAS) 93 try:
89 image.save(img_path) 94 image.thumbnail(PHOTO_MAX_SIZE, Image.ANTIALIAS)
95 image.save(img_path)
96 except IOError as ex:
97 logger.error("Error resizing image from %s: %s", img_path, ex)
98 return False
90 99
91 return True 100 return True
92 101
93 102
94 def gen_key(): 103 def gen_key():