Lambda-free reference to instance method

Amends 9cdd541943, the fix for #1326.
This commit is contained in:
Adrian Sampson 2015-02-13 17:37:55 -08:00
parent 9cdd541943
commit b80713ce5b

View file

@ -420,8 +420,7 @@ class Item(LibModel):
def _getters(cls):
getters = plugins.item_field_getters()
getters['singleton'] = lambda i: i.album_id is None
# Filesize is given in bytes
getters['filesize'] = lambda i: i.try_filesize()
getters['filesize'] = Item.try_filesize # In bytes.
return getters
@classmethod
@ -606,6 +605,10 @@ class Item(LibModel):
return int(os.path.getmtime(syspath(self.path)))
def try_filesize(self):
"""Get the size of the underlying file in bytes.
If the file is missing, return 0 (and log a warning).
"""
try:
return os.path.getsize(syspath(self.path))
except (OSError, Exception) as exc: