From c5acda690f0ba76469c1f7f88aa3fce89e9d4507 Mon Sep 17 00:00:00 2001 From: "Marshall T. Vandegrift" Date: Sun, 25 Jan 2009 18:30:06 -0500 Subject: [PATCH] Handle missing stylesheets --- src/calibre/ebooks/oeb/stylizer.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index c2d12f317e..29c6c5b2b4 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -110,7 +110,8 @@ class Stylizer(object): def __init__(self, tree, path, oeb, profile=PROFILES['PRS505']): self.profile = profile - base = os.path.dirname(path) + self.logger = oeb.logger + item = oeb.manifest.hrefs[path] basename = os.path.basename(path) cssname = os.path.splitext(basename)[0] + '.css' stylesheets = [HTML_CSS_STYLESHEET] @@ -128,8 +129,12 @@ class Stylizer(object): and elem.get('rel', 'stylesheet') == 'stylesheet' \ and elem.get('type', CSS_MIME) in OEB_STYLES: href = urlnormalize(elem.attrib['href']) - path = os.path.join(base, href) - path = os.path.normpath(path).replace('\\', '/') + path = item.abshref(href) + if path not in oeb.manifest.hrefs: + self.logger.warn( + 'Stylesheet %r referenced by file %r not in manifest' % + (path, item.href)) + continue if path in self.STYLESHEETS: stylesheet = self.STYLESHEETS[path] else: