Merge branch 'master' of https://github.com/cbhaley/calibre into master

This commit is contained in:
Kovid Goyal 2020-08-05 16:25:15 +05:30
commit 02dcac0702
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 15 additions and 0 deletions

View File

@ -436,6 +436,19 @@ class Metadata(object):
_data = object.__getattribute__(self, '_data')
_data['user_metadata'][field] = m
def remove_stale_user_metadata(self, other_mi):
'''
Remove user metadata keys (custom column keys) if they
don't exist in 'other_mi', which must be a metadata object
'''
me = self.get_all_user_metadata(make_copy=False)
other = set(other_mi.custom_field_keys())
new = {}
for k,v in me.items():
if k in other:
new[k] = v
self.set_all_user_metadata(new)
def template_to_attribute(self, other, ops):
'''
Takes a list [(src,dest), (src,dest)], evaluates the template in the

View File

@ -1312,6 +1312,7 @@ class OPF(object): # {{{
if apply_null or langs:
self.languages = langs or []
temp = self.to_book_metadata()
temp.remove_stale_user_metadata(mi)
temp.smart_update(mi, replace_metadata=replace_metadata)
if not replace_metadata and callable(getattr(temp, 'custom_field_keys', None)):
# We have to replace non-null fields regardless of the value of

View File

@ -1066,6 +1066,7 @@ def apply_metadata(root, mi, cover_prefix='', cover_data=None, apply_null=False,
set_application_id(root, prefixes, refines, mi.application_id)
if mi.uuid:
set_uuid(root, prefixes, refines, mi.uuid)
current_mi.remove_stale_user_metadata(mi)
new_user_metadata, current_user_metadata = mi.get_all_user_metadata(True), current_mi.get_all_user_metadata(True)
missing = object()
for key in tuple(new_user_metadata):