Don't trim <guide/> references, as they may *not* be spine items.

This commit is contained in:
Marshall T. Vandegrift 2009-01-14 17:44:49 -05:00
parent 14db43a40b
commit fc246ebdd5

View File

@ -9,6 +9,7 @@ __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
import sys import sys
import os import os
from itertools import chain from itertools import chain
from urlparse import urldefrag
from lxml import etree from lxml import etree
import cssutils import cssutils
from calibre.ebooks.oeb.base import XPNSMAP, CSS_MIME, OEB_DOCS from calibre.ebooks.oeb.base import XPNSMAP, CSS_MIME, OEB_DOCS
@ -29,6 +30,11 @@ class ManifestTrimmer(object):
used.add(oeb.manifest.hrefs[item.value]) used.add(oeb.manifest.hrefs[item.value])
elif item.value in oeb.manifest.ids: elif item.value in oeb.manifest.ids:
used.add(oeb.manifest.ids[item.value]) used.add(oeb.manifest.ids[item.value])
for ref in oeb.guide.values():
path, _ = urldefrag(ref.href)
if path in oeb.manifest.hrefs:
used.add(oeb.manifest.hrefs[path])
# TOC items are required to be in the spine
for item in oeb.spine: for item in oeb.spine:
used.add(item) used.add(item)
unchecked = used unchecked = used
@ -56,7 +62,6 @@ class ManifestTrimmer(object):
cssutils.replaceUrls(sheet, replacer) cssutils.replaceUrls(sheet, replacer)
used.update(new) used.update(new)
unchecked = new unchecked = new
# All guide and TOC items are required to be in the spine
for item in oeb.manifest.values(): for item in oeb.manifest.values():
if item not in used: if item not in used:
oeb.logger.info('Trimming %r from manifest' % item.href) oeb.logger.info('Trimming %r from manifest' % item.href)