From 7475c676e410e2a900f9025b0000724182a2eb11 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 31 May 2009 15:17:36 -0700 Subject: [PATCH] Misc. fixes --- src/calibre/ebooks/conversion/cli.py | 17 +++++++++-------- src/calibre/ebooks/mobi/writer.py | 8 +++++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/calibre/ebooks/conversion/cli.py b/src/calibre/ebooks/conversion/cli.py index 73e1a1e523..dbf86c4d94 100644 --- a/src/calibre/ebooks/conversion/cli.py +++ b/src/calibre/ebooks/conversion/cli.py @@ -7,6 +7,15 @@ __docformat__ = 'restructuredtext en' Command line interface to conversion sub-system ''' +import sys, os +from optparse import OptionGroup, Option + +from calibre.utils.config import OptionParser +from calibre.utils.logging import Log +from calibre.constants import preferred_encoding +from calibre.customize.conversion import OptionRecommendation + + USAGE = '%prog ' + _('''\ input_file output_file [options] @@ -33,14 +42,6 @@ option. For full documentation of the conversion system see ''') + 'http://calibre.kovidgoyal.net/user_manual/conversion.html' -import sys, os -from optparse import OptionGroup, Option - -from calibre.utils.config import OptionParser -from calibre.utils.logging import Log -from calibre.constants import preferred_encoding -from calibre.customize.conversion import OptionRecommendation - def print_help(parser, log): help = parser.format_help().encode(preferred_encoding, 'replace') log(help) diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py index 288fa01c73..7d63744e57 100644 --- a/src/calibre/ebooks/mobi/writer.py +++ b/src/calibre/ebooks/mobi/writer.py @@ -357,7 +357,10 @@ class MobiWriter(object): self._map_image_names() self._generate_text() if INDEXING and not self.opts.no_mobi_index: - self._generate_index() + try: + self._generate_index() + except: + self._oeb.log.exception('Failed to generate index') self._generate_images() def _map_image_names(self): @@ -507,6 +510,9 @@ class MobiWriter(object): ctoc = self._generate_ctoc() indxt, indxt_count, indices, last_name = \ self._generate_indxt(ctoc) + if last_name is None: + self._oeb.log.warn('Input document has no TOC. No idex generated.') + return indx1 = StringIO() indx1.write('INDX'+pack('>I', 0xc0)) # header length