mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
bugfixes
This commit is contained in:
parent
219feadc1e
commit
6d84c8dc15
@ -5,7 +5,9 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os, re, shutil
|
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 lxml import etree
|
||||||
from templite import Templite
|
from templite import Templite
|
||||||
@ -70,7 +72,7 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
def generate_html_toc(self, oeb_book, ref_url, output_dir):
|
def generate_html_toc(self, oeb_book, ref_url, output_dir):
|
||||||
root = self.generate_toc(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',
|
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):
|
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
||||||
|
|
||||||
@ -100,7 +102,7 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
|
|
||||||
tempdir = PersistentTemporaryDirectory()
|
tempdir = PersistentTemporaryDirectory()
|
||||||
output_file = os.path.join(tempdir,
|
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'
|
output_dir = re.sub(r'\.html', '', output_file)+'_files'
|
||||||
|
|
||||||
if not exists(output_dir):
|
if not exists(output_dir):
|
||||||
@ -184,7 +186,8 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
item.unload_data_from_memory(memory=path)
|
item.unload_data_from_memory(memory=path)
|
||||||
|
|
||||||
zfile = ZipFile(output_path, "w")
|
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 opts.extract_to:
|
||||||
if os.path.exists(opts.extract_to):
|
if os.path.exists(opts.extract_to):
|
||||||
@ -197,5 +200,3 @@ class HTMLOutput(OutputFormatPlugin):
|
|||||||
|
|
||||||
# cleanup temp dir
|
# cleanup temp dir
|
||||||
shutil.rmtree(tempdir)
|
shutil.rmtree(tempdir)
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ def PersistentTemporaryDirectory(suffix='', prefix='', dir=None):
|
|||||||
'''
|
'''
|
||||||
if dir is None:
|
if dir is None:
|
||||||
dir = base_dir()
|
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)
|
atexit.register(remove_dir, tdir)
|
||||||
return tdir
|
return tdir
|
||||||
|
|
||||||
@ -134,7 +134,3 @@ class TemporaryFile(object):
|
|||||||
|
|
||||||
def __exit__(self, *args):
|
def __exit__(self, *args):
|
||||||
cleanup(self._name)
|
cleanup(self._name)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user