Fix updating the calibre application id in EPUBs that also use the application id as the package id.

This commit is contained in:
Kovid Goyal 2013-03-05 09:51:36 +05:30
parent 6fc800d6c6
commit be977db0d9

View File

@ -941,9 +941,19 @@ class OPF(object): # {{{
return self.get_text(match) or None
def fset(self, val):
removed_ids = set()
for x in tuple(self.application_id_path(self.metadata)):
removed_ids.add(x.get('id', None))
x.getparent().remove(x)
uuid_id = None
for attr in self.root.attrib:
if attr.endswith('unique-identifier'):
uuid_id = self.root.attrib[attr]
break
attrib = {'{%s}scheme'%self.NAMESPACES['opf']: 'calibre'}
if uuid_id and uuid_id in removed_ids:
attrib['id'] = uuid_id
self.set_text(self.create_metadata_element(
'identifier', attrib=attrib), unicode(val))