From 447afcdd08f1c40b7def917f50f3c8c57a314d6f Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 15 Jul 2010 21:28:52 +0100 Subject: [PATCH] Fix cache problem where merging metadata did not values explicitly set to None, such as erasing series. --- src/calibre/devices/usbms/books.py | 2 +- src/calibre/ebooks/metadata/__init__.py | 14 +++++++++----- src/calibre/gui2/device.py | 15 ++++++++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index 6394626a9f..5ad4ef4723 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -78,7 +78,7 @@ class Book(MetaInformation): in C{other} takes precedence, unless the information in C{other} is NULL. ''' - MetaInformation.smart_update(self, other, replace_tags=True) + MetaInformation.smart_update(self, other, replace_metadata=True) for attr in self.BOOK_ATTRS: if hasattr(other, attr): diff --git a/src/calibre/ebooks/metadata/__init__.py b/src/calibre/ebooks/metadata/__init__.py index 0dbffd5f7f..d5e7aafb32 100644 --- a/src/calibre/ebooks/metadata/__init__.py +++ b/src/calibre/ebooks/metadata/__init__.py @@ -268,10 +268,12 @@ class MetaInformation(object): ): prints(x, getattr(self, x, 'None')) - def smart_update(self, mi, replace_tags=False): + def smart_update(self, mi, replace_metadata=False): ''' - Merge the information in C{mi} into self. In case of conflicts, the information - in C{mi} takes precedence, unless the information in mi is NULL. + Merge the information in C{mi} into self. In case of conflicts, the + information in C{mi} takes precedence, unless the information in mi is + NULL. If replace_metadata is True, then the information in mi always + takes precedence. ''' if mi.title and mi.title != _('Unknown'): self.title = mi.title @@ -285,13 +287,15 @@ class MetaInformation(object): 'cover', 'guide', 'book_producer', 'timestamp', 'lccn', 'lcc', 'ddc', 'pubdate', 'rights', 'publication_type', 'uuid'): - if hasattr(mi, attr): + if replace_metadata: + setattr(self, attr, getattr(mi, attr, None)) + elif hasattr(mi, attr): val = getattr(mi, attr) if val is not None: setattr(self, attr, val) if mi.tags: - if replace_tags: + if replace_metadata: self.tags = mi.tags else: self.tags += mi.tags diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index d81918c307..bc8ba7c381 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -1439,7 +1439,8 @@ class DeviceMixin(object): # {{{ for book in booklist: if getattr(book, 'uuid', None) in self.db_book_uuid_cache: if update_metadata: - book.smart_update(self.db_book_uuid_cache[book.uuid]) + book.smart_update(self.db_book_uuid_cache[book.uuid], + replace_metadata=True) book.in_library = True # ensure that the correct application_id is set book.application_id = \ @@ -1454,12 +1455,14 @@ class DeviceMixin(object): # {{{ if getattr(book, 'application_id', None) in d['db_ids']: book.in_library = True if update_metadata: - book.smart_update(d['db_ids'][book.application_id]) + book.smart_update(d['db_ids'][book.application_id], + replace_metadata=True) continue if book.db_id in d['db_ids']: book.in_library = True if update_metadata: - book.smart_update(d['db_ids'][book.db_id]) + book.smart_update(d['db_ids'][book.db_id], + replace_metadata=True) continue if book.authors: # Compare against both author and author sort, because @@ -1469,11 +1472,13 @@ class DeviceMixin(object): # {{{ if book_authors in d['authors']: book.in_library = True if update_metadata: - book.smart_update(d['authors'][book_authors]) + book.smart_update(d['authors'][book_authors], + replace_metadata=True) elif book_authors in d['author_sort']: book.in_library = True if update_metadata: - book.smart_update(d['author_sort'][book_authors]) + book.smart_update(d['author_sort'][book_authors], + replace_metadata=True) # Set author_sort if it isn't already asort = getattr(book, 'author_sort', None) if not asort and book.authors: