mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use options to specify format for pdb output.
This commit is contained in:
parent
db6f6caa75
commit
8ec90ce89d
@ -211,7 +211,6 @@ def main(args=sys.argv):
|
|||||||
OptionRecommendation.HIGH) \
|
OptionRecommendation.HIGH) \
|
||||||
for n in parser.options_iter()
|
for n in parser.options_iter()
|
||||||
if n.dest]
|
if n.dest]
|
||||||
print recommendations
|
|
||||||
plumber.merge_ui_recommendations(recommendations)
|
plumber.merge_ui_recommendations(recommendations)
|
||||||
|
|
||||||
plumber.run()
|
plumber.run()
|
||||||
|
@ -6,8 +6,9 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from calibre.customize.conversion import OutputFormatPlugin
|
from calibre.customize.conversion import OutputFormatPlugin, \
|
||||||
from calibre.ebooks.pdb import PDBError, get_writer
|
OptionRecommendation
|
||||||
|
from calibre.ebooks.pdb import PDBError, get_writer, FORMAT_WRITERS
|
||||||
|
|
||||||
class PDBOutput(OutputFormatPlugin):
|
class PDBOutput(OutputFormatPlugin):
|
||||||
|
|
||||||
@ -15,20 +16,25 @@ class PDBOutput(OutputFormatPlugin):
|
|||||||
author = 'John Schember'
|
author = 'John Schember'
|
||||||
file_type = 'pdb'
|
file_type = 'pdb'
|
||||||
|
|
||||||
|
options = set([
|
||||||
|
OptionRecommendation(name='format', recommended_value='doc',
|
||||||
|
level=OptionRecommendation.LOW,
|
||||||
|
short_switch='f', choices=FORMAT_WRITERS.keys(),
|
||||||
|
help=_('Format to use inside the pdb container. Choices are: '
|
||||||
|
'%s' % FORMAT_WRITERS.keys())),
|
||||||
|
])
|
||||||
|
|
||||||
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
||||||
close = False
|
close = False
|
||||||
if not hasattr(output_path, 'write'):
|
if not hasattr(output_path, 'write'):
|
||||||
# Determine the format to write based upon the sub extension
|
|
||||||
format = os.path.splitext(os.path.splitext(output_path)[0])[1][1:]
|
|
||||||
close = True
|
close = True
|
||||||
if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '':
|
if not os.path.exists(os.path.dirname(output_path)) and os.path.dirname(output_path) != '':
|
||||||
os.makedirs(os.path.dirname(output_path))
|
os.makedirs(os.path.dirname(output_path))
|
||||||
out_stream = open(output_path, 'wb')
|
out_stream = open(output_path, 'wb')
|
||||||
else:
|
else:
|
||||||
format = os.path.splitext(os.path.splitext(output_path.name)[0])[1][1:]
|
|
||||||
out_stream = output_path
|
out_stream = output_path
|
||||||
|
|
||||||
Writer = get_writer(format)
|
Writer = get_writer(opts.format)
|
||||||
|
|
||||||
if Writer is None:
|
if Writer is None:
|
||||||
raise PDBError('No writer avaliable for format %s.' % format)
|
raise PDBError('No writer avaliable for format %s.' % format)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user