From 516e1ca9623ffb501ad6fe7d6b861012b1640a33 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 20 Aug 2009 10:15:26 -0600 Subject: [PATCH] Fix #3218 (Adding a book in an existing format causes a temporary duplication of formats) --- src/calibre/ebooks/epub/output.py | 12 +++++++----- src/calibre/gui2/dialogs/metadata_single.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/epub/output.py b/src/calibre/ebooks/epub/output.py index d76e3cb20c..c03d103e3a 100644 --- a/src/calibre/ebooks/epub/output.py +++ b/src/calibre/ebooks/epub/output.py @@ -358,25 +358,25 @@ class EPUBOutput(OutputFormatPlugin): if body: body = body[0] else: - return 0 # Impossible? + return False tree = body.getroottree() elem = XPath('//*[@id="%s" or @name="%s"]'%(frag, frag))(root) if elem: elem = elem[0] else: - return 0 + return False path = tree.getpath(elem) for el in body.iterdescendants(): epath = tree.getpath(el) if epath == path: break if el.text and el.text.strip(): - return 0 + return False if not path.startswith(epath): # Only check tail of non-parent elements if el.tail and el.tail.strip(): - return 0 - return 1 + return False + return True def simplify_toc_entry(toc): if toc.href: @@ -385,6 +385,8 @@ class EPUBOutput(OutputFormatPlugin): for x in self.oeb.spine: if x.href == href: if frag_is_at_top(x.data, frag): + self.log.debug('Removing anchor from TOC href:', + href+'#'+frag) toc.href = href break for x in toc: diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py index 42785e3f3e..ab86cc810d 100644 --- a/src/calibre/gui2/dialogs/metadata_single.py +++ b/src/calibre/gui2/dialogs/metadata_single.py @@ -144,7 +144,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog): ext = os.path.splitext(_file)[1].lower().replace('.', '') for row in range(self.formats.count()): fmt = self.formats.item(row) - if fmt.ext == ext: + if fmt.ext.lower() == ext: self.formats.takeItem(row) break Format(self.formats, ext, size, path=_file)