From 343a85d482f0c2ec2d801975b8c61b74c0682980 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 23 Aug 2013 14:01:31 -0700 Subject: [PATCH] mbsync: use separate structure for old_data Assigning an attribute on Items doesn't really work here since we try to store that value to the DB as a flexattr. --- beetsplug/mbsync.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/beetsplug/mbsync.py b/beetsplug/mbsync.py index 140cb95c1..4ffe9a02e 100644 --- a/beetsplug/mbsync.py +++ b/beetsplug/mbsync.py @@ -24,14 +24,14 @@ from beets import config log = logging.getLogger('beets') -def _print_and_apply_changes(lib, item, move, pretend, write): +def _print_and_apply_changes(lib, item, old_data, move, pretend, write): """Apply changes to an Item and preview them in the console. Return a boolean indicating whether any changes were made. """ changes = {} for key in library.ITEM_KEYS_META: - if 'key' in item._dirty: - changes[key] = item.old_data[key], getattr(item, key) + if key in item._dirty: + changes[key] = old_data[key], getattr(item, key) if not changes: return False @@ -69,7 +69,7 @@ def mbsync_singletons(lib, query, move, pretend, write): .format(s.title)) continue - s.old_data = dict(s) + old_data = dict(s) # Get the MusicBrainz recording info. track_info = hooks.track_for_mbid(s.mb_trackid) @@ -80,7 +80,7 @@ def mbsync_singletons(lib, query, move, pretend, write): # Apply. with lib.transaction(): autotag.apply_item_metadata(s, track_info) - _print_and_apply_changes(lib, s, move, pretend, write) + _print_and_apply_changes(lib, s, old_data, move, pretend, write) def mbsync_albums(lib, query, move, pretend, write): @@ -93,8 +93,7 @@ def mbsync_albums(lib, query, move, pretend, write): continue items = list(a.items()) - for item in items: - item.old_data = dict(item) + old_data = {item: dict(item) for item in items} # Get the MusicBrainz album information. album_info = hooks.album_for_mbid(a.mb_albumid) @@ -116,8 +115,8 @@ def mbsync_albums(lib, query, move, pretend, write): autotag.apply_metadata(album_info, mapping) changed = False for item in items: - changed = _print_and_apply_changes(lib, item, move, pretend, - write) or changed + changed |= _print_and_apply_changes(lib, item, old_data[item], + move, pretend, write) if not changed: # No change to any item. continue