mirror of
https://github.com/beetbox/beets.git
synced 2026-01-07 16:34:45 +01:00
Use ordinary dict for progress (#873)
This is compatible with older versions of beets. It should also be less surprising when deserializing.
This commit is contained in:
parent
3eafd9f7a6
commit
3cf015606d
1 changed files with 7 additions and 4 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue