From eadb7172c4583c64b6b603f047fa8c214182c87e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 24 Sep 2008 12:23:43 -0700 Subject: [PATCH] Various minor bug fixes. Fixes #1053 (Problem converting html to Epub) --- src/calibre/ebooks/epub/from_any.py | 8 ++++---- src/calibre/ebooks/html.py | 18 +++++++++++------- src/calibre/ebooks/lrf/comic/convert_from.py | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/calibre/ebooks/epub/from_any.py b/src/calibre/ebooks/epub/from_any.py index d4d2240bca..8a5d77861a 100644 --- a/src/calibre/ebooks/epub/from_any.py +++ b/src/calibre/ebooks/epub/from_any.py @@ -74,7 +74,7 @@ MAP = { 'txt' : txt2opf, 'pdf' : pdf2opf, } -SOURCE_FORMATS = ['lit', 'mobi', 'prc', 'fb2', 'rtf', 'txt', 'pdf', 'rar', 'zip', 'htm', 'html'] +SOURCE_FORMATS = ['lit', 'mobi', 'prc', 'fb2', 'rtf', 'txt', 'pdf', 'rar', 'zip', 'oebzip', 'htm', 'html'] def unarchive(path, tdir): extract(path, tdir) @@ -109,7 +109,7 @@ def any2epub(opts, path, notification=None): opts.output = os.path.splitext(os.path.basename(path))[0]+'.epub' with nested(TemporaryDirectory('_any2epub1'), TemporaryDirectory('_any2epub2')) as (tdir1, tdir2): - if ext in ['rar', 'zip']: + if ext in ['rar', 'zip', 'oebzip']: path, ext = unarchive(path, tdir1) print 'Found %s file in archive'%(ext.upper()) @@ -129,7 +129,7 @@ def config(defaults=None): def formats(): - return ['html', 'rar', 'zip']+list(MAP.keys()) + return ['html', 'rar', 'zip', 'oebzip']+list(MAP.keys()) def option_parser(): @@ -151,4 +151,4 @@ def main(args=sys.argv): return 0 if __name__ == '__main__': - sys.exit(main()) \ No newline at end of file + sys.exit(main()) diff --git a/src/calibre/ebooks/html.py b/src/calibre/ebooks/html.py index 575a2ac82d..2524987d08 100644 --- a/src/calibre/ebooks/html.py +++ b/src/calibre/ebooks/html.py @@ -491,17 +491,21 @@ class Processor(Parser): referrer = toc if self.htmlfile.referrer is not None: - name = self.htmlfile_map[self.htmlfile.referrer] - href = 'content/'+name - for i in toc.flat(): - if href == i.href and i.fragment is None: - referrer = i - break - + try: + name = self.htmlfile_map[self.htmlfile.referrer] + href = 'content/'+name + for i in toc.flat(): + if href == i.href and i.fragment is None: + referrer = i + break + except KeyError: + pass + name = self.htmlfile_map[self.htmlfile.path] href = 'content/'+name + if referrer.href != href: # Happens for root file target = add_item(href, None, unicode(self.htmlfile.title), referrer, type='file') diff --git a/src/calibre/ebooks/lrf/comic/convert_from.py b/src/calibre/ebooks/lrf/comic/convert_from.py index dad015da5d..56f6cd8c94 100755 --- a/src/calibre/ebooks/lrf/comic/convert_from.py +++ b/src/calibre/ebooks/lrf/comic/convert_from.py @@ -286,7 +286,7 @@ def config(defaults=None): help=_('Set the author in the metadata of the generated ebook. Default is %default'), default=_('Unknown')) c.add_opt('output', ['-o', '--output'], - help=_('Path to output LRF file. By default a file is created in the current directory.')) + help=_('Path to output file. By default a file is created in the current directory.')) c.add_opt('colors', ['-c', '--colors'], type='int', default=64, help=_('Number of colors for grayscale image conversion. Default: %default')) c.add_opt('dont_normalize', ['-n', '--disable-normalize'], default=False, @@ -306,7 +306,7 @@ def config(defaults=None): c.add_opt('no_sort', ['--no-sort'], default=False, help=_("Don't sort the files found in the comic alphabetically by name. Instead use the order they were added to the comic.")) c.add_opt('profile', ['-p', '--profile'], default='prs500', choices=PROFILES.keys(), - help=_('Choose a profile for the device you are generating this LRF for. The default is the SONY PRS-500 with a screen size of 584x754 pixels. Choices are %s')%PROFILES.keys()) + help=_('Choose a profile for the device you are generating this file for. The default is the SONY PRS-500 with a screen size of 584x754 pixels. This is suitable for any reader with the same screen size. Choices are %s')%PROFILES.keys()) c.add_opt('verbose', ['-v', '--verbose'], default=0, action='count', help=_('Be verbose, useful for debugging. Can be specified multiple times for greater verbosity.')) c.add_opt('no_progress_bar', ['--no-progress-bar'], default=False,