mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
EPUB Output: Cleanup zipfile code
This commit is contained in:
parent
0ac0fe5bcd
commit
ad8d2f8889
@ -216,8 +216,8 @@ class EPUBOutput(OutputFormatPlugin):
|
|||||||
encryption = self.encrypt_fonts(encrypted_fonts, tdir, uuid)
|
encryption = self.encrypt_fonts(encrypted_fonts, tdir, uuid)
|
||||||
|
|
||||||
from calibre.ebooks.epub import initialize_container
|
from calibre.ebooks.epub import initialize_container
|
||||||
epub = initialize_container(output_path, os.path.basename(opf),
|
with initialize_container(output_path, os.path.basename(opf),
|
||||||
extra_entries=extra_entries)
|
extra_entries=extra_entries) as epub:
|
||||||
epub.add_dir(tdir)
|
epub.add_dir(tdir)
|
||||||
if encryption is not None:
|
if encryption is not None:
|
||||||
epub.writestr('META-INF/encryption.xml', encryption)
|
epub.writestr('META-INF/encryption.xml', encryption)
|
||||||
@ -225,12 +225,13 @@ class EPUBOutput(OutputFormatPlugin):
|
|||||||
epub.writestr('META-INF/metadata.xml',
|
epub.writestr('META-INF/metadata.xml',
|
||||||
metadata_xml.encode('utf-8'))
|
metadata_xml.encode('utf-8'))
|
||||||
if opts.extract_to is not None:
|
if opts.extract_to is not None:
|
||||||
|
from calibre.utils.zipfile import ZipFile
|
||||||
if os.path.exists(opts.extract_to):
|
if os.path.exists(opts.extract_to):
|
||||||
shutil.rmtree(opts.extract_to)
|
shutil.rmtree(opts.extract_to)
|
||||||
os.mkdir(opts.extract_to)
|
os.mkdir(opts.extract_to)
|
||||||
epub.extractall(path=opts.extract_to)
|
with ZipFile(output_path) as zf:
|
||||||
|
zf.extractall(path=opts.extract_to)
|
||||||
self.log.info('EPUB extracted to', opts.extract_to)
|
self.log.info('EPUB extracted to', opts.extract_to)
|
||||||
epub.close()
|
|
||||||
|
|
||||||
def encrypt_fonts(self, uris, tdir, uuid): # {{{
|
def encrypt_fonts(self, uris, tdir, uuid): # {{{
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
|
Loading…
x
Reference in New Issue
Block a user