refactor exceptions in get_size method
This commit is contained in:
@@ -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."""
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user