1
# -*- coding: utf-8 -*-
4
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
5
__docformat__ = 'restructuredtext en'
9
from calibre.customize.conversion import OutputFormatPlugin, \
11
from calibre.ebooks.pdb import PDBError, get_writer, FORMAT_WRITERS
13
class PDBOutput(OutputFormatPlugin):
16
author = 'John Schember'
20
OptionRecommendation(name='format', recommended_value='doc',
21
level=OptionRecommendation.LOW,
22
short_switch='f', choices=FORMAT_WRITERS.keys(),
23
help=(_('Format to use inside the pdb container. Choices are:')+\
24
' %s' % FORMAT_WRITERS.keys())),
25
OptionRecommendation(name='output_encoding', recommended_value='cp1252',
26
level=OptionRecommendation.LOW,
27
help=_('Specify the character encoding of the output document. ' \
28
'The default is cp1252. Note: This option is not honored by all ' \
32
def convert(self, oeb_book, output_path, input_plugin, opts, log):
34
if not hasattr(output_path, 'write'):
36
if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '':
37
os.makedirs(os.path.dirname(output_path))
38
out_stream = open(output_path, 'wb')
40
out_stream = output_path
42
Writer = get_writer(opts.format)
45
raise PDBError('No writer available for format %s.' % format)
47
writer = Writer(opts, log)
52
writer.write_content(oeb_book, out_stream, oeb_book.metadata)