Fix #842882 (calibre.epub has 2 copies of content)

This commit is contained in:
Kovid Goyal 2011-09-06 11:52:37 -06:00
parent 48363e9d69
commit 6695f0d346
2 changed files with 51 additions and 15 deletions

View File

@ -180,30 +180,30 @@ class InterfaceAction(QObject):
description=None, triggered=None, shortcut_name=None):
'''
Convenience method to easily add actions to a QMenu.
Returns the created QAction, This action has one extra attribute
calibre_shortcut_unique_name which if not None refers to the unique
name under which this action is registered with the keyboard manager.
:param menu: The QMenu the newly created action will be added to
:param unique_name: A unique name for this action, this must be
globally unique, so make it as descriptive as possible. If in doubt add
a uuid to it.
globally unique, so make it as descriptive as possible. If in doubt add
a uuid to it.
:param text: The text of the action.
:param icon: Either a QIcon or a file name. The file name is passed to
the I() builtin, so you do not need to pass the full path to the images
directory.
the I() builtin, so you do not need to pass the full path to the images
directory.
:param shortcut: A string, a list of strings, None or False. If False,
no keyboard shortcut is registered for this action. If None, a keyboard
shortcut with no default keybinding is registered. String and list of
strings register a shortcut with default keybinding as specified.
no keyboard shortcut is registered for this action. If None, a keyboard
shortcut with no default keybinding is registered. String and list of
strings register a shortcut with default keybinding as specified.
:param description: A description for this action. Used to set
tooltips.
tooltips.
:param triggered: A callable which is connected to the triggered signal
of the created action.
of the created action.
:param shortcut_name: The test displayed to the user when customizing
the keyboard shortcuts for this action. By default it is set to the
value of ``text``.
the keyboard shortcuts for this action. By default it is set to the
value of ``text``.
:return: The created QAction, This action has one extra attribute
calibre_shortcut_unique_name which if not None refers to the unique
name under which this action is registered with the keyboard manager.
'''
if shortcut_name is None:
shortcut_name = unicode(text)

View File

@ -6,7 +6,9 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os, time
import os, time, glob
from lxml import etree
from sphinx.builders.epub import EpubBuilder
@ -55,4 +57,38 @@ class EPUBHelpBuilder(EpubBuilder):
def build_epub(self, outdir, *args, **kwargs):
if self.config.epub_cover:
self.add_cover(outdir, self.config.epub_cover)
self.fix_duplication_bugs(outdir)
EpubBuilder.build_epub(self, outdir, *args, **kwargs)
def fix_duplication_bugs(self, outdir):
opf = glob.glob(outdir+os.sep+'*.opf')[0]
root = etree.fromstring(open(opf, 'rb').read())
seen = set()
for x in root.xpath(
'//*[local-name()="spine"]/*[local-name()="itemref"]'):
idref = x.get('idref')
if idref in seen:
x.getparent().remove(x)
else:
seen.add(idref)
with open(opf, 'wb') as f:
f.write(etree.tostring(root, encoding='utf-8', xml_declaration=True))
ncx = glob.glob(outdir+os.sep+'*.ncx')[0]
root = etree.fromstring(open(ncx, 'rb').read())
seen = set()
for x in root.xpath(
'//*[local-name()="navMap"]/*[local-name()="navPoint"]'):
text = x.xpath('descendant::*[local-name()="text"]')[0]
text = text.text
if text in seen:
x.getparent().remove(x)
else:
seen.add(text)
with open(ncx, 'wb') as f:
f.write(etree.tostring(root, encoding='utf-8', xml_declaration=True))