mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add an --extract-to option for DOCX output
Also re-use the help string for that option everywhere.
This commit is contained in:
parent
4d88d05621
commit
8817629486
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
from calibre.customize.conversion import OutputFormatPlugin
|
from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation
|
||||||
|
|
||||||
class DOCXOutput(OutputFormatPlugin):
|
class DOCXOutput(OutputFormatPlugin):
|
||||||
|
|
||||||
@ -14,10 +14,20 @@ class DOCXOutput(OutputFormatPlugin):
|
|||||||
author = 'Kovid Goyal'
|
author = 'Kovid Goyal'
|
||||||
file_type = 'docx'
|
file_type = 'docx'
|
||||||
|
|
||||||
|
options = {
|
||||||
|
OptionRecommendation(name='extract_to',
|
||||||
|
help=_('Extract the contents of the generated %s file to the '
|
||||||
|
'specified directory. The contents of the directory are first '
|
||||||
|
'deleted, so be careful.') % 'DOCX'),
|
||||||
|
}
|
||||||
|
|
||||||
def convert(self, oeb, output_path, input_plugin, opts, log):
|
def convert(self, oeb, output_path, input_plugin, opts, log):
|
||||||
from calibre.ebooks.docx.writer.container import DOCX
|
from calibre.ebooks.docx.writer.container import DOCX
|
||||||
from calibre.ebooks.docx.writer.from_html import Convert
|
from calibre.ebooks.docx.writer.from_html import Convert
|
||||||
docx = DOCX(opts, log)
|
docx = DOCX(opts, log)
|
||||||
Convert(oeb, docx)()
|
Convert(oeb, docx)()
|
||||||
docx.write(output_path)
|
docx.write(output_path)
|
||||||
|
if opts.extract_to:
|
||||||
|
from calibre.ebooks.docx.dump import do_dump
|
||||||
|
do_dump(output_path, opts.extract_to)
|
||||||
|
|
||||||
|
@ -51,9 +51,9 @@ class EPUBOutput(OutputFormatPlugin):
|
|||||||
|
|
||||||
options = set([
|
options = set([
|
||||||
OptionRecommendation(name='extract_to',
|
OptionRecommendation(name='extract_to',
|
||||||
help=_('Extract the contents of the generated EPUB file to the '
|
help=_('Extract the contents of the generated %s file to the '
|
||||||
'specified directory. The contents of the directory are first '
|
'specified directory. The contents of the directory are first '
|
||||||
'deleted, so be careful.')),
|
'deleted, so be careful.') % 'EPUB'),
|
||||||
|
|
||||||
OptionRecommendation(name='dont_split_on_page_breaks',
|
OptionRecommendation(name='dont_split_on_page_breaks',
|
||||||
recommended_value=False, level=OptionRecommendation.LOW,
|
recommended_value=False, level=OptionRecommendation.LOW,
|
||||||
|
@ -73,10 +73,10 @@ class MOBIOutput(OutputFormatPlugin):
|
|||||||
help=_('When adding the Table of Contents to the book, add it at the start of the '
|
help=_('When adding the Table of Contents to the book, add it at the start of the '
|
||||||
'book instead of the end. Not recommended.')
|
'book instead of the end. Not recommended.')
|
||||||
),
|
),
|
||||||
OptionRecommendation(name='extract_to', recommended_value=None,
|
OptionRecommendation(name='extract_to',
|
||||||
help=_('Extract the contents of the MOBI file to the'
|
help=_('Extract the contents of the generated %s file to the '
|
||||||
' specified directory. If the directory already '
|
'specified directory. The contents of the directory are first '
|
||||||
'exists, it will be deleted.')
|
'deleted, so be careful.') % 'MOBI'
|
||||||
),
|
),
|
||||||
OptionRecommendation(name='share_not_sync', recommended_value=False,
|
OptionRecommendation(name='share_not_sync', recommended_value=False,
|
||||||
help=_('Enable sharing of book content via Facebook etc. '
|
help=_('Enable sharing of book content via Facebook etc. '
|
||||||
@ -286,11 +286,10 @@ class AZW3Output(OutputFormatPlugin):
|
|||||||
help=_('When adding the Table of Contents to the book, add it at the start of the '
|
help=_('When adding the Table of Contents to the book, add it at the start of the '
|
||||||
'book instead of the end. Not recommended.')
|
'book instead of the end. Not recommended.')
|
||||||
),
|
),
|
||||||
OptionRecommendation(name='extract_to', recommended_value=None,
|
OptionRecommendation(name='extract_to',
|
||||||
help=_('Extract the contents of the MOBI file to the'
|
help=_('Extract the contents of the generated %s file to the '
|
||||||
' specified directory. If the directory already '
|
'specified directory. The contents of the directory are first '
|
||||||
'exists, it will be deleted.')
|
'deleted, so be careful.') % 'AZW3'),
|
||||||
),
|
|
||||||
OptionRecommendation(name='share_not_sync', recommended_value=False,
|
OptionRecommendation(name='share_not_sync', recommended_value=False,
|
||||||
help=_('Enable sharing of book content via Facebook etc. '
|
help=_('Enable sharing of book content via Facebook etc. '
|
||||||
' on the Kindle. WARNING: Using this feature means that '
|
' on the Kindle. WARNING: Using this feature means that '
|
||||||
|
@ -24,15 +24,18 @@ def pretty_all_xml_in_dir(path):
|
|||||||
stream.truncate()
|
stream.truncate()
|
||||||
stream.write(etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=True))
|
stream.write(etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=True))
|
||||||
|
|
||||||
def dump(path):
|
def do_dump(path, dest):
|
||||||
dest = os.path.splitext(os.path.basename(path))[0]
|
|
||||||
dest += '-dumped'
|
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
shutil.rmtree(dest)
|
shutil.rmtree(dest)
|
||||||
with ZipFile(path) as zf:
|
with ZipFile(path) as zf:
|
||||||
zf.extractall(dest)
|
zf.extractall(dest)
|
||||||
pretty_all_xml_in_dir(dest)
|
pretty_all_xml_in_dir(dest)
|
||||||
|
|
||||||
|
def dump(path):
|
||||||
|
dest = os.path.splitext(os.path.basename(path))[0]
|
||||||
|
dest += '-dumped'
|
||||||
|
do_dump(path, dest)
|
||||||
|
|
||||||
print (path, 'dumped to', dest)
|
print (path, 'dumped to', dest)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user