diff --git a/src/calibre/ebooks/conversion/plugins/docx_output.py b/src/calibre/ebooks/conversion/plugins/docx_output.py index 5b40618e41..915b56dd55 100644 --- a/src/calibre/ebooks/conversion/plugins/docx_output.py +++ b/src/calibre/ebooks/conversion/plugins/docx_output.py @@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' -from calibre.customize.conversion import OutputFormatPlugin +from calibre.customize.conversion import OutputFormatPlugin, OptionRecommendation class DOCXOutput(OutputFormatPlugin): @@ -14,10 +14,20 @@ class DOCXOutput(OutputFormatPlugin): author = 'Kovid Goyal' 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): from calibre.ebooks.docx.writer.container import DOCX from calibre.ebooks.docx.writer.from_html import Convert docx = DOCX(opts, log) Convert(oeb, docx)() docx.write(output_path) + if opts.extract_to: + from calibre.ebooks.docx.dump import do_dump + do_dump(output_path, opts.extract_to) diff --git a/src/calibre/ebooks/conversion/plugins/epub_output.py b/src/calibre/ebooks/conversion/plugins/epub_output.py index 0fb0b69ce7..6569d069be 100644 --- a/src/calibre/ebooks/conversion/plugins/epub_output.py +++ b/src/calibre/ebooks/conversion/plugins/epub_output.py @@ -51,9 +51,9 @@ class EPUBOutput(OutputFormatPlugin): options = set([ 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 ' - 'deleted, so be careful.')), + 'deleted, so be careful.') % 'EPUB'), OptionRecommendation(name='dont_split_on_page_breaks', recommended_value=False, level=OptionRecommendation.LOW, diff --git a/src/calibre/ebooks/conversion/plugins/mobi_output.py b/src/calibre/ebooks/conversion/plugins/mobi_output.py index afea62e2f3..c005ad4dd2 100644 --- a/src/calibre/ebooks/conversion/plugins/mobi_output.py +++ b/src/calibre/ebooks/conversion/plugins/mobi_output.py @@ -73,10 +73,10 @@ class MOBIOutput(OutputFormatPlugin): help=_('When adding the Table of Contents to the book, add it at the start of the ' 'book instead of the end. Not recommended.') ), - OptionRecommendation(name='extract_to', recommended_value=None, - help=_('Extract the contents of the MOBI file to the' - ' specified directory. If the directory already ' - 'exists, it will be deleted.') + 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.') % 'MOBI' ), OptionRecommendation(name='share_not_sync', recommended_value=False, 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 ' 'book instead of the end. Not recommended.') ), - OptionRecommendation(name='extract_to', recommended_value=None, - help=_('Extract the contents of the MOBI file to the' - ' specified directory. If the directory already ' - 'exists, it will be deleted.') - ), + 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.') % 'AZW3'), OptionRecommendation(name='share_not_sync', recommended_value=False, help=_('Enable sharing of book content via Facebook etc. ' ' on the Kindle. WARNING: Using this feature means that ' diff --git a/src/calibre/ebooks/docx/dump.py b/src/calibre/ebooks/docx/dump.py index d5bda75405..f0699ef223 100644 --- a/src/calibre/ebooks/docx/dump.py +++ b/src/calibre/ebooks/docx/dump.py @@ -24,15 +24,18 @@ def pretty_all_xml_in_dir(path): stream.truncate() stream.write(etree.tostring(root, pretty_print=True, encoding='utf-8', xml_declaration=True)) -def dump(path): - dest = os.path.splitext(os.path.basename(path))[0] - dest += '-dumped' +def do_dump(path, dest): if os.path.exists(dest): shutil.rmtree(dest) with ZipFile(path) as zf: zf.extractall(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) if __name__ == '__main__':