EPUB 3 metadata: Fix updating metadata in EPUB 3 files not overwriting existing authors. Fixes #1602227 [Polish Epub3 - proliferation of dc:creator, dc:contributor](https://bugs.launchpad.net/calibre/+bug/1602227)

This commit is contained in:
Kovid Goyal 2016-07-12 22:28:17 +05:30
parent 6cd282bced
commit 57c3a2d6af
2 changed files with 6 additions and 3 deletions

View File

@ -421,7 +421,7 @@ def set_authors(root, prefixes, refines, authors):
for item in XPath('./opf:metadata/dc:creator')(root):
props = properties_for_id_with_scheme(item.get('id'), prefixes, refines)
opf_role = item.get(OPF('role'))
if (is_relators_role(props, 'aut')) or (opf_role and opf_role.lower() != 'aut'):
if (opf_role and opf_role.lower() != 'aut') or (props.get('role') and not is_relators_role(props, 'aut')):
continue
remove_element(item, refines)
metadata = XPath('./opf:metadata')(root)[0]
@ -457,7 +457,7 @@ def set_book_producers(root, prefixes, refines, producers):
for item in XPath('./opf:metadata/dc:contributor')(root):
props = properties_for_id_with_scheme(item.get('id'), prefixes, refines)
opf_role = item.get(OPF('role'))
if (is_relators_role(props, 'bkp')) or (opf_role and opf_role.lower() != 'bkp'):
if (opf_role and opf_role.lower() != 'bkp') or (props.get('role') and not is_relators_role(props, 'bkp')):
continue
remove_element(item, refines)
metadata = XPath('./opf:metadata')(root)[0]

View File

@ -141,6 +141,9 @@ class TestOPF3(unittest.TestCase):
authors = [Author('x y', 'y, x'), Author('u i', None)]
self.ae(authors, st(root, authors))
self.ae(root.get('prefix'), 'calibre: %s' % CALIBRE_PREFIX)
root = self.get_opf('''<dc:creator>a b</dc:creator><dc:creator opf:role="aut">c d</dc:creator>''')
self.ae([Author('c d', None)], rl(root))
self.ae(authors, st(root, authors))
# }}}
def test_book_producer(self): # {{{
@ -155,7 +158,7 @@ class TestOPF3(unittest.TestCase):
self.ae(['c d'], rl(root))
root = self.get_opf('''<dc:contributor>a b</dc:contributor><dc:contributor opf:role="bkp">c d</dc:contributor>''')
self.ae(['c d'], rl(root))
self.ae('12'.split(), st(root, '12'.split()))
self.ae(['12'], st(root, ['12']))
# }}}
def test_dates(self): # {{{