refactor exceptions in get_size method

This commit is contained in:
franek
2015-06-15 11:12:22 +02:00
parent 78b23090fe
commit c84a621984
2 changed files with 4 additions and 14 deletions

View File

@@ -171,21 +171,11 @@ class Image(Media):
@cached_property
def size(self):
try:
return get_size(self.dst_path)
except (IOError, IndexError, TypeError, AttributeError):
self.logger.warning(u'Could not read size %s',
self.dst_path)
return None
return get_size(self.dst_path)
@cached_property
def thumb_size(self):
try:
return get_size(self.thumb_path)
except (IOError, IndexError, TypeError, AttributeError):
self.logger.warning(u'Could not read size %s',
self.thumb_path)
return None
return get_size(self.thumb_path)
class Video(Media):
"""Gather all informations on a video file."""

View File

@@ -166,8 +166,8 @@ def get_size(file_path):
logger = logging.getLogger(__name__)
try:
im = PILImage.open(file_path)
except:
logger.error("Failed to open %s", file_path)
except (IOError, IndexError, TypeError, AttributeError) as e :
logger.error("Could not read size of %s due to %r", file_path, e)
else:
width,height = im.size
return {