From 3cf015606d9a171aedd349478781cfd855a4b334 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Thu, 17 Jul 2014 09:54:29 -0700 Subject: [PATCH] Use ordinary dict for progress (#873) This is compatible with older versions of beets. It should also be less surprising when deserializing. --- beets/importer.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index 9cfbc4911..b034d5bbc 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -84,7 +84,7 @@ def _save_state(state): @contextmanager def progress_state(): state = _open_state() - progress = state.setdefault(PROGRESS_KEY, defaultdict(list)) + progress = state.setdefault(PROGRESS_KEY, {}) yield progress _save_state(state) @@ -94,7 +94,7 @@ def progress_add(toppath, *paths): under `toppath`. """ with progress_state() as state: - imported = state[toppath] + imported = state.setdefault(toppath, []) for path in paths: # Normally `progress_add` will be called with the path # argument increasing. This is because of the ordering in @@ -110,6 +110,8 @@ def progress_element(toppath, path): """Return whether `path` has been imported in `toppath`. """ with progress_state() as state: + if toppath not in state: + return False imported = state[toppath] i = bisect_left(imported, path) return i != len(imported) and imported[i] == path @@ -120,12 +122,13 @@ def has_progress(toppath): imported under `toppath`. """ with progress_state() as state: - return len(state[toppath]) != 0 + return state.get(toppath) def progress_reset(toppath): with progress_state() as state: - state[toppath] = [] + if toppath in state: + del state[toppath] # Similarly, utilities for manipulating the "incremental" import log.