mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix cache problem where merging metadata did not values explicitly set to None, such as erasing series.
This commit is contained in:
parent
09490d2b0a
commit
447afcdd08
@ -78,7 +78,7 @@ class Book(MetaInformation):
|
|||||||
in C{other} takes precedence, unless the information in C{other} is NULL.
|
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:
|
for attr in self.BOOK_ATTRS:
|
||||||
if hasattr(other, attr):
|
if hasattr(other, attr):
|
||||||
|
@ -268,10 +268,12 @@ class MetaInformation(object):
|
|||||||
):
|
):
|
||||||
prints(x, getattr(self, x, 'None'))
|
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
|
Merge the information in C{mi} into self. In case of conflicts, the
|
||||||
in C{mi} takes precedence, unless the information in mi is NULL.
|
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'):
|
if mi.title and mi.title != _('Unknown'):
|
||||||
self.title = mi.title
|
self.title = mi.title
|
||||||
@ -285,13 +287,15 @@ class MetaInformation(object):
|
|||||||
'cover', 'guide', 'book_producer',
|
'cover', 'guide', 'book_producer',
|
||||||
'timestamp', 'lccn', 'lcc', 'ddc', 'pubdate', 'rights',
|
'timestamp', 'lccn', 'lcc', 'ddc', 'pubdate', 'rights',
|
||||||
'publication_type', 'uuid'):
|
'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)
|
val = getattr(mi, attr)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
setattr(self, attr, val)
|
setattr(self, attr, val)
|
||||||
|
|
||||||
if mi.tags:
|
if mi.tags:
|
||||||
if replace_tags:
|
if replace_metadata:
|
||||||
self.tags = mi.tags
|
self.tags = mi.tags
|
||||||
else:
|
else:
|
||||||
self.tags += mi.tags
|
self.tags += mi.tags
|
||||||
|
@ -1439,7 +1439,8 @@ class DeviceMixin(object): # {{{
|
|||||||
for book in booklist:
|
for book in booklist:
|
||||||
if getattr(book, 'uuid', None) in self.db_book_uuid_cache:
|
if getattr(book, 'uuid', None) in self.db_book_uuid_cache:
|
||||||
if update_metadata:
|
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
|
book.in_library = True
|
||||||
# ensure that the correct application_id is set
|
# ensure that the correct application_id is set
|
||||||
book.application_id = \
|
book.application_id = \
|
||||||
@ -1454,12 +1455,14 @@ class DeviceMixin(object): # {{{
|
|||||||
if getattr(book, 'application_id', None) in d['db_ids']:
|
if getattr(book, 'application_id', None) in d['db_ids']:
|
||||||
book.in_library = True
|
book.in_library = True
|
||||||
if update_metadata:
|
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
|
continue
|
||||||
if book.db_id in d['db_ids']:
|
if book.db_id in d['db_ids']:
|
||||||
book.in_library = True
|
book.in_library = True
|
||||||
if update_metadata:
|
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
|
continue
|
||||||
if book.authors:
|
if book.authors:
|
||||||
# Compare against both author and author sort, because
|
# Compare against both author and author sort, because
|
||||||
@ -1469,11 +1472,13 @@ class DeviceMixin(object): # {{{
|
|||||||
if book_authors in d['authors']:
|
if book_authors in d['authors']:
|
||||||
book.in_library = True
|
book.in_library = True
|
||||||
if update_metadata:
|
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']:
|
elif book_authors in d['author_sort']:
|
||||||
book.in_library = True
|
book.in_library = True
|
||||||
if update_metadata:
|
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
|
# Set author_sort if it isn't already
|
||||||
asort = getattr(book, 'author_sort', None)
|
asort = getattr(book, 'author_sort', None)
|
||||||
if not asort and book.authors:
|
if not asort and book.authors:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user