Commit a349f728 authored by Dan Pascu's avatar Dan Pascu

Fixed displaying the owner of a failed icon retrieval

parent 8ae35147
...@@ -481,6 +481,7 @@ class GoogleContactIconRetriever(object): ...@@ -481,6 +481,7 @@ class GoogleContactIconRetriever(object):
@run_in_threadpool(threadpool) @run_in_threadpool(threadpool)
def run(self): def run(self):
owner = self.contact.name or self.contact.organization or self.contact.id
icon = self.contact.icon icon = self.contact.icon
http = self.credentials.authorize(Http(timeout=5)) http = self.credentials.authorize(Http(timeout=5))
try: try:
...@@ -489,7 +490,7 @@ class GoogleContactIconRetriever(object): ...@@ -489,7 +490,7 @@ class GoogleContactIconRetriever(object):
else: else:
response = content = None response = content = None
except (HttpLib2Error, socket.error) as e: except (HttpLib2Error, socket.error) as e:
log.warning(u"could not retrieve icon for {}: {!s}".format(self.contact.name, e)) log.warning(u'could not retrieve icon for {owner}: {exception!s}'.format(owner=owner, exception=e))
else: else:
if response is None: if response is None:
icon_manager = IconManager() icon_manager = IconManager()
...@@ -500,27 +501,27 @@ class GoogleContactIconRetriever(object): ...@@ -500,27 +501,27 @@ class GoogleContactIconRetriever(object):
try: try:
icon_manager.store_data(self.contact.id, content) icon_manager.store_data(self.contact.id, content)
except Exception as e: except Exception as e:
log.error(u"could not store icon for {}: {!s}".format(self.contact.name, e)) log.error(u'could not store icon for {owner}: {exception!s}'.format(owner=owner, exception=e))
else: else:
icon.downloaded_url = icon.url icon.downloaded_url = icon.url
elif response['status'] in ('403', '404') and icon.alternate_url: # private or unavailable photo. use old GData protocol if alternate_url is available. elif response['status'] in ('403', '404') and icon.alternate_url: # private or unavailable photo. use old GData protocol if alternate_url is available.
try: try:
response, content = http.request(icon.alternate_url, headers={'GData-Version': '3.0'}) response, content = http.request(icon.alternate_url, headers={'GData-Version': '3.0'})
except (HttpLib2Error, socket.error) as e: except (HttpLib2Error, socket.error) as e:
log.warning(u"could not retrieve icon for {}: {!s}".format(self.contact.name, e)) log.warning(u'could not retrieve icon for {owner}: {exception!s}'.format(owner=owner, exception=e))
else: else:
if response['status'] == '200' and response['content-type'].startswith('image/'): if response['status'] == '200' and response['content-type'].startswith('image/'):
icon_manager = IconManager() icon_manager = IconManager()
try: try:
icon_manager.store_data(self.contact.id, content) icon_manager.store_data(self.contact.id, content)
except Exception as e: except Exception as e:
log.error(u"could not store icon for {}: {!s}".format(self.contact.name, e)) log.error(u'could not store icon for {owner}: {exception!s}'.format(owner=owner, exception=e))
else: else:
icon.downloaded_url = icon.url icon.downloaded_url = icon.url
else: else:
log.error(u"could not retrieve icon for {} (status={}, content type={})".format(self.contact.name, response['status'], response['content-type'])) log.error(u'could not retrieve icon for {} (status={}, content-type={!r})'.format(owner, response['status'], response['content-type']))
else: else:
log.error(u"could not retrieve icon for {} (status={}, content type={})".format(self.contact.name, response['status'], response['content-type'])) log.error(u'could not retrieve icon for {} (status={}, content-type={!r})'.format(owner, response['status'], response['content-type']))
finally: finally:
self._event.set() self._event.set()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment