Skip to content

Commit

Permalink
[REF] core: ConfigCleaner(5) lists de-facto cli-only options
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Julien00859 committed Sep 22, 2023
1 parent 6b187c9 commit f5190f1
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions odoo/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 []
Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit f5190f1

Please sign in to comment.