From cf818b1c621e19e85c9cb666796ad33e70063e4a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 13 Jul 2009 18:21:58 -0600 Subject: [PATCH] Fix #2825 ("No such file or directory" error in viewer) --- src/calibre/ebooks/mobi/writer.py | 5 +++++ src/calibre/ebooks/oeb/iterator.py | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py index 5bd75d5e9a..04fd835c96 100644 --- a/src/calibre/ebooks/mobi/writer.py +++ b/src/calibre/ebooks/mobi/writer.py @@ -1963,6 +1963,11 @@ class MobiWriter(object): self._oeb.logger.warn(' Ignoring TOC entry with no href:', child.title) continue + if h not in self._id_offsets: + self._oeb.logger.warn(' Ignoring missing TOC entry:', + child) + continue + currentOffset = self._id_offsets[h] # print "_generate_ctoc: child offset: 0x%X" % currentOffset diff --git a/src/calibre/ebooks/oeb/iterator.py b/src/calibre/ebooks/oeb/iterator.py index 2b68b6cf57..03c09262d4 100644 --- a/src/calibre/ebooks/oeb/iterator.py +++ b/src/calibre/ebooks/oeb/iterator.py @@ -41,9 +41,12 @@ class SpineItem(unicode): def __new__(cls, *args): args = list(args) - args[0] = args[0].partition('#')[0] - obj = super(SpineItem, cls).__new__(cls, *args) path = args[0] + ppath = path.partition('#')[0] + if not os.path.exists(path) and os.path.exists(ppath): + path = ppath + args[0] = path + obj = super(SpineItem, cls).__new__(cls, *args) raw = open(path, 'rb').read() raw, obj.encoding = xml_to_unicode(raw) obj.character_count = character_count(raw)