from calibre.customize.conversion import OptionRecommendation
from calibre import patheq
USAGE = '%prog ' + _('input_file output_file [options]\n\nConvert an ebook from one format to another.\n\ninput_file is the input and output_file is the output. Both must be specified as the first two arguments to the command.\n\nThe output ebook format is guessed from the file extension of output_file. output_file can also be of the special format .EXT where EXT is the output file extension. In this case, the name of the output file is derived the name of the input file. Note that the filenames must not start with a hyphen. Finally, if output_file has no extension, then it is treated as a directory and an "open ebook" (OEB) consisting of HTML files is written to that directory. These files are the files that would normally have been passed to the output plugin.\n\nAfter specifying the input and output file you can customize the conversion by specifying various options. The available options depend on the input and output file types. To get help on them specify the input and output file and then use the -h option.\n\nFor full documentation of the conversion system see\n') + 'http://calibre-ebook.com/user_manual/conversion.html'
def print_help(parser, log):
help = parser.format_help().encode(preferred_encoding, 'replace')
attrs['action'] = None if rec.recommended_value else 'store_true'
elif isinstance(rec.recommended_value, int):
attrs['type'] = 'int'
if isinstance(rec.recommended_value, float):
attrs['type'] = 'float'
if opt.long_switch == 'verbose':
attrs['action'] = 'count'
attrs.pop('type', '')
add_option(Option(*switches, **attrs))
def add_input_output_options(parser, plumber):
input_options = plumber.input_options
output_options = plumber.output_options
def add_options(group, options):
for opt in options:
option_recommendation_to_cli_option(group, opt)
if input_options:
title = _('INPUT OPTIONS')
io = OptionGroup(parser, title, _('Options to control the processing of the input %s file') % plumber.input_fmt)
add_options(io.add_option, input_options)
parser.add_option_group(io)
if output_options:
title = _('OUTPUT OPTIONS')
oo = OptionGroup(parser, title, _('Options to control the processing of the output %s') % plumber.output_fmt)
add_options(oo.add_option, output_options)
parser.add_option_group(oo)
def add_pipeline_options(parser, plumber):
groups = {
'': ('', [
'input_profile',
'output_profile']),
'LOOK AND FEEL': (_('Options to control the look and feel of the output'), [
'base_font_size',
'disable_font_rescaling',
'font_size_mapping',
'line_height',
'linearize_tables',
'extra_css',
'margin_top',
'margin_left',
'margin_right',
'margin_bottom',
'change_justification',
'insert_blank_line',
'remove_paragraph_spacing',
'remove_paragraph_spacing_indent_size',
'asciiize',
'remove_header',
'header_regex',
'remove_footer',
'footer_regex']),
'STRUCTURE DETECTION': (_('Control auto-detection of document structure.'), [
'chapter',
'chapter_mark',
'prefer_metadata_cover',
'remove_first_image',
'insert_metadata',
'page_breaks_before',
'preprocess_html']),
'TABLE OF CONTENTS': (_('Control the automatic generation of a Table of Contents. By default, if the source file has a Table of Contents, it will be used in preference to the automatically generated one.'), [
'level1_toc',
'level2_toc',
'level3_toc',
'toc_threshold',
'max_toc_links',
'no_chapters_in_toc',
'use_auto_toc',
'toc_filter']),
'METADATA': (_('Options to set metadata in the output'), plumber.metadata_option_names),
'DEBUG': (_('Options to help with debugging the conversion'), [
'verbose',
'debug_pipeline']) }
group_order = [
'',
'LOOK AND FEEL',
'STRUCTURE DETECTION',
'TABLE OF CONTENTS',
'METADATA',
'DEBUG']
for group in group_order:
(desc, options) = groups[group]
if group:
group = OptionGroup(parser, group, desc)
parser.add_option_group(group)
add_option = None if group != '' else parser.add_option