From 6d84c8dc15dab98e1fa91dda2384fdce985e0f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gra=C3=9Fl?= Date: Wed, 3 Nov 2010 11:58:04 +0100 Subject: [PATCH 1/4] bugfixes --- src/calibre/ebooks/html/output.py | 13 +++++++------ src/calibre/ptempfile.py | 6 +----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/calibre/ebooks/html/output.py b/src/calibre/ebooks/html/output.py index f1178d3259..52b2e62421 100644 --- a/src/calibre/ebooks/html/output.py +++ b/src/calibre/ebooks/html/output.py @@ -5,7 +5,9 @@ __docformat__ = 'restructuredtext en' import os, re, shutil -from os.path import dirname, abspath, relpath, exists +from calibre.utils import zipfile + +from os.path import dirname, abspath, relpath, exists, basename from lxml import etree from templite import Templite @@ -70,7 +72,7 @@ class HTMLOutput(OutputFormatPlugin): def generate_html_toc(self, oeb_book, ref_url, output_dir): root = self.generate_toc(oeb_book, ref_url, output_dir) return etree.tostring(root, pretty_print=True, encoding='utf-8', - xml_declaration=True) + xml_declaration=False) def convert(self, oeb_book, output_path, input_plugin, opts, log): @@ -100,7 +102,7 @@ class HTMLOutput(OutputFormatPlugin): tempdir = PersistentTemporaryDirectory() output_file = os.path.join(tempdir, - os.path.basename(re.sub(r'\.zip', '', output_path)+'.html')) + basename(re.sub(r'\.zip', '', output_path)+'.html')) output_dir = re.sub(r'\.html', '', output_file)+'_files' if not exists(output_dir): @@ -184,7 +186,8 @@ class HTMLOutput(OutputFormatPlugin): item.unload_data_from_memory(memory=path) zfile = ZipFile(output_path, "w") - zfile.add_dir(output_dir) + zfile.add_dir(output_dir, basename(output_dir)) + zfile.write(output_file, basename(output_file), zipfile.ZIP_DEFLATED) if opts.extract_to: if os.path.exists(opts.extract_to): @@ -197,5 +200,3 @@ class HTMLOutput(OutputFormatPlugin): # cleanup temp dir shutil.rmtree(tempdir) - - diff --git a/src/calibre/ptempfile.py b/src/calibre/ptempfile.py index 71ae9b0789..459305885e 100644 --- a/src/calibre/ptempfile.py +++ b/src/calibre/ptempfile.py @@ -87,7 +87,7 @@ def PersistentTemporaryDirectory(suffix='', prefix='', dir=None): ''' if dir is None: dir = base_dir() - tdir = tempfile.mkdtemp(suffix, __appname__+"_"+ __version__+"_" +prefix, dir) + tdir = os.path.realpath(tempfile.mkdtemp(suffix, __appname__+"_"+ __version__+"_" +prefix, dir)) atexit.register(remove_dir, tdir) return tdir @@ -134,7 +134,3 @@ class TemporaryFile(object): def __exit__(self, *args): cleanup(self._name) - - - - From e3a9863f9fc77f623843ee7c958455f14e67767a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gra=C3=9Fl?= Date: Wed, 3 Nov 2010 13:16:59 +0100 Subject: [PATCH 2/4] added view variable --- src/calibre/ebooks/html/output.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/html/output.py b/src/calibre/ebooks/html/output.py index 52b2e62421..6c81ea8ef5 100644 --- a/src/calibre/ebooks/html/output.py +++ b/src/calibre/ebooks/html/output.py @@ -121,7 +121,8 @@ class HTMLOutput(OutputFormatPlugin): tocUrl = relpath(output_file, dirname(output_file)) t = templite.render(has_toc=bool(oeb_book.toc.count()), toc=html_toc, meta=meta, nextLink=nextLink, - tocUrl=tocUrl, cssLink=cssLink) + tocUrl=tocUrl, cssLink=cssLink, + firstContentPageLink=nextLink) f.write(t) with CurrentDir(output_dir): @@ -170,6 +171,7 @@ class HTMLOutput(OutputFormatPlugin): cssLink = relpath(abspath(css_path), dir) tocUrl = relpath(output_file, dir) + firstContentPageLink = oeb_book.spine[0].href # render template templite = Templite(template_html_data) @@ -178,7 +180,8 @@ class HTMLOutput(OutputFormatPlugin): prevLink=prevLink, nextLink=nextLink, has_toc=bool(oeb_book.toc.count()), toc=toc, tocUrl=tocUrl, head_content=head_content, - meta=meta, cssLink=cssLink) + meta=meta, cssLink=cssLink, + firstContentPageLink=firstContentPageLink) # write html to file with open(path, 'wb') as f: From 78b66ad54d67f448b59e09628ffb3226de80543a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gra=C3=9Fl?= Date: Wed, 3 Nov 2010 15:05:46 +0100 Subject: [PATCH 3/4] no need to delete the contents of the specified directory --- src/calibre/ebooks/html/output.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/html/output.py b/src/calibre/ebooks/html/output.py index 6c81ea8ef5..3acb316c3f 100644 --- a/src/calibre/ebooks/html/output.py +++ b/src/calibre/ebooks/html/output.py @@ -39,7 +39,7 @@ class HTMLOutput(OutputFormatPlugin): help=_('Template used for the generation of the html contents of the book instead of the default file')), OptionRecommendation(name='extract_to', - help=_('Extract the contents of the generated ZIP file to the directory of the generated ZIP file') + help=_('Extract the contents of the generated ZIP file to the specified directory') ), ]) @@ -193,9 +193,8 @@ class HTMLOutput(OutputFormatPlugin): zfile.write(output_file, basename(output_file), zipfile.ZIP_DEFLATED) if opts.extract_to: - if os.path.exists(opts.extract_to): - shutil.rmtree(opts.extract_to) - os.makedirs(opts.extract_to) + if not os.path.exists(opts.extract_to): + os.makedirs(opts.extract_to) zfile.extractall(opts.extract_to) self.log('Zip file extracted to', opts.extract_to) From fb1f60cee37435e4fc4530c80863c779345be479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gra=C3=9Fl?= Date: Thu, 4 Nov 2010 20:33:19 +0100 Subject: [PATCH 4/4] little bf --- src/calibre/ebooks/html/output.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calibre/ebooks/html/output.py b/src/calibre/ebooks/html/output.py index 3acb316c3f..d486add040 100644 --- a/src/calibre/ebooks/html/output.py +++ b/src/calibre/ebooks/html/output.py @@ -154,6 +154,7 @@ class HTMLOutput(OutputFormatPlugin): body = root.xpath('//h:body', namespaces={'h': 'http://www.w3.org/1999/xhtml'})[0] ebook_content = etree.tostring(body, pretty_print=True, encoding='utf-8') ebook_content = re.sub(r'\<\/?body.*\>', '', ebook_content) + ebook_content = re.sub(r'<(div|a|span)([^>]*)/>', r'<\1\2>', ebook_content) # generate link to next page if item.spine_position+1 < len(oeb_book.spine):