From d805401b2340cc46dcdf2ce1c7271353df1d5def Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 27 Nov 2011 22:35:19 -0800 Subject: [PATCH] simplifications afforded by eager result iterators (#261) --- beets/importer.py | 24 ++++++++---------------- beets/library.py | 7 ------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index 2b24047bf..0695fc46b 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -137,15 +137,11 @@ def _item_duplicate_check(lib, task, recent=None): recent.add((artist, title)) # Check the library. - item_iter = lib.items(artist=artist, title=title) - try: - for other_item in item_iter: - # Existing items not considered duplicates. - if other_item.path == task.item.path: - continue - return True - finally: - item_iter.close() + for other_item in lib.items(artist=artist, title=title): + # Existing items not considered duplicates. + if other_item.path == task.item.path: + continue + return True return False def _infer_album_fields(task): @@ -489,14 +485,12 @@ def query_tasks(config): if config.singletons: # Search for items. - items = list(lib.items(config.query)) - for item in items: + for item in lib.items(config.query): yield ImportTask.item_task(item) else: # Search for albums. - albums = lib.albums(config.query) - for album in albums: + for album in lib.albums(config.query): log.debug('yielding album %i: %s - %s' % (album.id, album.albumartist, album.album)) items = list(album.items()) @@ -613,9 +607,7 @@ def apply_choices(config): # last item is removed. replaced_items = defaultdict(list) for item in items: - dup_items = list(lib.items( - library.MatchQuery('path', item.path) - )) + dup_items = lib.items(library.MatchQuery('path', item.path)) for dup_item in dup_items: replaced_items[item].append(dup_item) log.debug('replacing item %i: %s' % (dup_item.id, item.path)) diff --git a/beets/library.py b/beets/library.py index eebc7c9c5..baf36c7c3 100644 --- a/beets/library.py +++ b/beets/library.py @@ -510,11 +510,6 @@ class ResultIterator(object): row = self.rowiter.next() # May raise StopIteration. return Item(row) - def close(self): - # No longer used. Previously, this method would close the - # cursor, but this is not necessary with the eager design. - pass - # An abstract library. @@ -1032,8 +1027,6 @@ class Library(BaseLibrary): return it.next() except StopIteration: return None - finally: - it.close() def get_album(self, item_or_id): """Given an album ID or an item associated with an album,