From 8eeaead1356a6d349f56cc3259270ba85d43101c Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 4 Aug 2010 11:30:02 -0700 Subject: [PATCH] fixed pause & resume, which neither paused nor resumed In the multithreaded version, the "directory done" state was written before other progress states, causing it to be overwritten. This was because I had stupidly put the "done" message in the initial generator, which of course finishes before the entire pipeline finished. This manifested as two problems: the tagger would always want to "resume" even when it had finished the last time; "aBort"ing the process would not cause the next run to resume. --- beets/ui/commands.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 4caab7a80..cc95ef979 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -290,6 +290,10 @@ def progress_get(toppath): # Core autotagger pipeline stages. +# This sentinel is passed along as the "path" when a directory has finished +# tagging. +DONE_SENTINEL = '__IMPORT_DONE_SENTINEL__' + def read_albums(paths): """A generator yielding all the albums (as sets of Items) found in the user-specified list of paths. @@ -327,8 +331,8 @@ def read_albums(paths): yield toppath, path, items - # Indicate that the import completed. - progress_set(toppath, None) + # Indicate the directory is finished. + yield toppath, DONE_SENTINEL, None def initial_lookup(): """A coroutine for performing the initial MusicBrainz lookup for an @@ -338,10 +342,15 @@ def initial_lookup(): """ toppath, path, items = yield while True: - try: - cur_artist, cur_album, candidates, rec = autotag.tag_album(items) - except autotag.AutotagError: + if path is DONE_SENTINEL: cur_artist, cur_album, candidates, rec = None, None, None, None + else: + try: + cur_artist, cur_album, candidates, rec = \ + autotag.tag_album(items) + except autotag.AutotagError: + cur_artist, cur_album, candidates, rec = \ + None, None, None, None toppath, path, items = yield toppath, path, items, cur_artist, \ cur_album, candidates, rec @@ -361,6 +370,10 @@ def user_query(lib, logfile=None, color=True): out = None while True: toppath, path, items, cur_artist, cur_album, candidates, rec = yield out + + if path is DONE_SENTINEL: + out = toppath, path, None, None + continue # Empty lines between albums. if not first: @@ -412,6 +425,12 @@ def apply_choices(lib, copy, write, art): while True: # Get next chunk of work. toppath, path, items, info = yield + + # Check for "path finished" message. + if path is DONE_SENTINEL: + # Mark path as complete. + progress_set(toppath, None) + continue # Only process the items if info is not None (indicating a # skip).