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)
-
-
-
-