From 5dbc4252a77b7a0f42e79d91f6a7e6193dd8c012 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 4 Jul 2009 14:51:05 -0400 Subject: [PATCH] Plumber: Dummy mode that loads all options from all formats so that the default values will be set in preferences. --- src/calibre/ebooks/conversion/plumber.py | 31 ++++++++++++++++++------ src/calibre/gui2/dialogs/config.py | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/calibre/ebooks/conversion/plumber.py b/src/calibre/ebooks/conversion/plumber.py index 77ae507867..e33df27412 100644 --- a/src/calibre/ebooks/conversion/plumber.py +++ b/src/calibre/ebooks/conversion/plumber.py @@ -7,7 +7,8 @@ import os, re, sys from calibre.customize.conversion import OptionRecommendation, DummyReporter from calibre.customize.ui import input_profiles, output_profiles, \ - plugin_for_input_format, plugin_for_output_format + plugin_for_input_format, plugin_for_output_format, \ + available_input_formats, available_output_formats from calibre.ebooks.conversion.preprocess import HTMLPreProcessor from calibre.ptempfile import PersistentTemporaryDirectory from calibre import extract, walk @@ -50,7 +51,7 @@ class Plumber(object): 'tags', 'book_producer', 'language' ] - def __init__(self, input, output, log, report_progress=DummyReporter()): + def __init__(self, input, output, log, report_progress=DummyReporter(), dummy=False): ''' :param input: Path to input file. :param output: Path to output file/directory @@ -419,12 +420,28 @@ OptionRecommendation(name='list_recipes', self.input_fmt = input_fmt self.output_fmt = output_fmt + + self.all_format_options = set() + self.input_options = set() + self.output_options = set() # Build set of all possible options. Two options are equal if their # names are the same. - self.input_options = self.input_plugin.options.union( - self.input_plugin.common_options) - self.output_options = self.output_plugin.options.union( + if not dummy: + self.input_options = self.input_plugin.options.union( + self.input_plugin.common_options) + self.output_options = self.output_plugin.options.union( self.output_plugin.common_options) + else: + for fmt in available_input_formats(): + input_plugin = plugin_for_input_format(fmt) + if input_plugin: + self.all_format_options = self.all_format_options.union( + input_plugin.options.union(input_plugin.common_options)) + for fmt in available_output_formats(): + output_plugin = plugin_for_output_format(fmt) + if output_plugin: + self.all_format_options = self.all_format_options.union( + output_plugin.options.union(output_plugin.common_options)) # Remove the options that have been disabled by recommendations from the # plugins. @@ -469,7 +486,7 @@ OptionRecommendation(name='list_recipes', def get_option_by_name(self, name): for group in (self.input_options, self.pipeline_options, - self.output_options): + self.output_options, self.all_format_options): for rec in group: if rec.option == name: return rec @@ -535,7 +552,7 @@ OptionRecommendation(name='list_recipes', ''' self.opts = OptionValues() for group in (self.input_options, self.pipeline_options, - self.output_options): + self.output_options, self.all_format_options): for rec in group: setattr(self.opts, rec.option.name, rec.recommended_value) diff --git a/src/calibre/gui2/dialogs/config.py b/src/calibre/gui2/dialogs/config.py index 2b5e9d4cf2..aacccbd6b9 100644 --- a/src/calibre/gui2/dialogs/config.py +++ b/src/calibre/gui2/dialogs/config.py @@ -39,7 +39,7 @@ class ConfigTabs(QTabWidget): log = Log() log.outputs = [] - self.plumber = Plumber('dummt.epub', 'dummy.epub', log) + self.plumber = Plumber('dummy.epub', 'dummy.epub', log, dummy=True) def widget_factory(cls): return cls(self, self.plumber.get_option_by_name,