From f5190f1ebe1c857ba40ad1153487c96b69cfe413 Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Mon, 26 Jun 2023 20:02:44 +0200 Subject: [PATCH] [REF] core: ConfigCleaner(5) lists de-facto cli-only options This commit is part of a larger refactor, see associated PR. Many options are de-facto cli-only, some are explicitely not saved to or loaded from the config file, some can be loaded from the config file but are always erased at runtime, some are options to load/save the config file itself. Some i18n options *could* be loaded from the config file but this would be buggy as the various validations are only performed on the CLI. --- odoo/tools/config.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/odoo/tools/config.py b/odoo/tools/config.py index 492388b3a92f7..5562eb5408b7f 100644 --- a/odoo/tools/config.py +++ b/odoo/tools/config.py @@ -36,7 +36,12 @@ class MyOption (optparse.Option, object): def __init__(self, *opts, **attrs): self.my_default = attrs.pop('my_default', None) self.cli_loadable = attrs.pop('cli_loadable', True) - self.file_exportable = attrs.pop('file_exportable', True) + self.file_loadable = attrs.pop('file_loadable', True) + self.file_exportable = attrs.pop('file_exportable', self.file_loadable) + if self.file_exportable and not self.file_loadable: + raise ValueError(f"it makes no sense that the option {self}" + " can be exported to the config file but" + " not loaded from the config file") super(MyOption, self).__init__(*opts, **attrs) if self.dest and self.dest not in config.options_index: config.options_index[self.dest] = self @@ -107,13 +112,13 @@ def _build_cli(self): # Server startup config group = optparse.OptionGroup(parser, "Common options") - group.add_option("-c", "--config", dest="config", file_exportable=False, + group.add_option("-c", "--config", dest="config", file_loadable=False, help="specify alternate config file") - group.add_option("-s", "--save", action="store_true", dest="save", default=False, file_exportable=False, + group.add_option("-s", "--save", action="store_true", dest="save", default=False, file_loadable=False, help="save configuration to ~/.odoorc (or to ~/.openerp_serverrc if it exists)") - group.add_option("-i", "--init", dest="init", file_exportable=False, + group.add_option("-i", "--init", dest="init", file_loadable=False, help="install one or more modules (comma-separated list, use \"all\" for all modules), requires -d") - group.add_option("-u", "--update", dest="update", file_exportable=False, + group.add_option("-u", "--update", dest="update", file_loadable=False, help="update one or more modules (comma-separated list, use \"all\" for all modules). Requires -d.") group.add_option("--without-demo", dest="without_demo", help="disable loading demo data for modules to be installed (comma-separated, use \"all\" for all modules). Requires -d and -i. Default is %default", @@ -276,17 +281,17 @@ def _build_cli(self): "See i18n section of the user manual. Option '-d' is mandatory. " "Option '-l' is mandatory in case of importation" ) - group.add_option('--load-language', dest="load_language", file_exportable=False, + group.add_option('--load-language', dest="load_language", file_loadable=False, help="specifies the languages for the translations you want to be loaded") - group.add_option('-l', "--language", dest="language", + group.add_option('-l', "--language", dest="language", file_loadable=False, help="specify the language of the translation file. Use it with --i18n-export or --i18n-import") - group.add_option("--i18n-export", dest="translate_out", file_exportable=False, + group.add_option("--i18n-export", dest="translate_out", file_loadable=False, help="export all sentences to be translated to a CSV file, a PO file or a TGZ archive and exit") - group.add_option("--i18n-import", dest="translate_in", file_exportable=False, + group.add_option("--i18n-import", dest="translate_in", file_loadable=False, help="import a CSV or a PO file with translations and exit. The '-l' option is required.") - group.add_option("--i18n-overwrite", dest="overwrite_existing_translations", action="store_true", my_default=False, file_exportable=False, + group.add_option("--i18n-overwrite", dest="overwrite_existing_translations", action="store_true", my_default=False, file_loadable=False, help="overwrites existing translation terms on updating a module or importing a CSV or a PO file.") - group.add_option("--modules", dest="translate_modules", file_exportable=False, + group.add_option("--modules", dest="translate_modules", default='all', file_loadable=False, help="specify modules to export. Use in combination with --i18n-export") parser.add_option_group(group) @@ -562,7 +567,7 @@ def die(cond, msg): self.options['demo'] = (dict(self.options['init']) if not self.options['without_demo'] else {}) self.options['update'] = opt.update and dict.fromkeys(opt.update.split(','), 1) or {} - self.options['translate_modules'] = opt.translate_modules and [m.strip() for m in opt.translate_modules.split(',')] or ['all'] + self.options['translate_modules'] = [m.strip() for m in opt.translate_modules.split(',')] self.options['translate_modules'].sort() dev_split = [s.strip() for s in opt.dev_mode.split(',')] if opt.dev_mode else [] @@ -652,6 +657,9 @@ def load(self): p.read([self.rcfile]) for (name,value) in p.items('options'): name = outdated_options_map.get(name, name) + option = self.options_index.get(name) + if option and not option.file_loadable: + continue if value=='True' or value=='true': value = True if value=='False' or value=='false':