From 6ed0b2e0f3455e4414938d254fef3ed7e21fcfb6 Mon Sep 17 00:00:00 2001 From: Tom Jaspers Date: Mon, 2 Feb 2015 21:52:23 +0100 Subject: [PATCH] Expose an Item's filesize as a field - Update test-case for info to make sure the item's path is pointing to an actual file. See #1291 --- beets/library.py | 7 ++----- beets/ui/commands.py | 2 +- test/test_info.py | 4 +++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/beets/library.py b/beets/library.py index d010811aa..fd95b6d05 100644 --- a/beets/library.py +++ b/beets/library.py @@ -420,6 +420,8 @@ 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: os.path.getsize(syspath(i.path)) return getters @classmethod @@ -603,11 +605,6 @@ class Item(LibModel): """ return int(os.path.getmtime(syspath(self.path))) - def filesize(self): - """Returns the size, in bytes, of the file. - """ - return os.path.getsize(syspath(self.path)) - # Model methods. def remove(self, delete=False, with_album=True): diff --git a/beets/ui/commands.py b/beets/ui/commands.py index b8f492a9e..d800493e5 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -439,7 +439,7 @@ def summarize_items(items, singleton): average_bitrate = sum([item.bitrate for item in items]) / len(items) total_duration = sum([item.length for item in items]) - total_filesize = sum([item.filesize() for item in items]) + total_filesize = sum([item.filesize for item in items]) summary_parts.append('{0}kbps'.format(int(average_bitrate / 1000))) summary_parts.append(ui.human_seconds_short(total_duration)) summary_parts.append(ui.human_bytes(total_filesize)) diff --git a/test/test_info.py b/test/test_info.py index d528517ed..e382f4872 100644 --- a/test/test_info.py +++ b/test/test_info.py @@ -94,7 +94,9 @@ class InfoTest(unittest.TestCase, TestHelper): self.assertIn(u'title: [various]', out) def test_include_pattern(self): - item = self.add_item(album='xxxx') + item, = self.add_item_fixtures() + item.album = 'xxxx' + item.store() out = self.run_with_output('--library', 'album:xxxx', '--include-keys', '*lbu*')