Skip to content

Commit

Permalink
[REF] core: ConfigCleaner(6) load keys via the index
Browse files Browse the repository at this point in the history
This commit is part of a larger refactor, see associated PR.

Using the new `cli_loadable` and `file_loadable` attributes, it is
possible to list all keys that were defined in the hardcoded listing.

The difference are `pg_path` and `test_enable` that were not present in
the previous listing but present in the new comprehension:

* for pg_path, it was set just bellow using the same cli->file fallback
  logic

* for test_enable, its value is reset on `bool(test_tags)` anyway...

The previous code was using two (almost) identical loops with two
hardcoded listing. The two loops were at first difference but d5e7247
made them basically identical, almost 10 years ago.
  • Loading branch information
Julien00859 committed Sep 22, 2023
1 parent f5190f1 commit ca38632
Showing 1 changed file with 5 additions and 45 deletions.
50 changes: 5 additions & 45 deletions odoo/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,17 +482,11 @@ def die(cond, msg):
if self.options['server_wide_modules'] in ('', 'None', 'False'):
self.options['server_wide_modules'] = 'base,web'

# if defined do not take the configfile value even if the defined value is None
keys = ['gevent_port', 'http_interface', 'http_port', 'longpolling_port', 'http_enable', 'x_sendfile',
'db_name', 'db_user', 'db_password', 'db_host', 'db_sslmode',
'db_port', 'db_template', 'logfile', 'pidfile', 'smtp_port',
'email_from', 'smtp_server', 'smtp_user', 'smtp_password', 'from_filter',
'smtp_ssl_certificate_filename', 'smtp_ssl_private_key_filename',
'db_maxconn', 'db_maxconn_gevent', 'import_partial', 'addons_path', 'upgrade_path',
'syslog', 'without_demo', 'screencasts', 'screenshots',
'dbfilter', 'log_level', 'log_db',
'log_db_level', 'geoip_city_db', 'geoip_country_db', 'dev_mode',
'shell_interface',
keys = [
option_name for option_name, option
in self.options_index.items()
if option.cli_loadable and option.file_loadable
if option.action != 'append'
]

for arg in keys:
Expand All @@ -508,37 +502,6 @@ def die(cond, msg):
self.options['log_handler'] = self.options['log_handler'].split(',')
self.options['log_handler'].extend(opt.log_handler)

# if defined but None take the configfile value
keys = [
'language', 'translate_out', 'translate_in', 'overwrite_existing_translations',
'dev_mode', 'shell_interface', 'smtp_ssl', 'load_language',
'stop_after_init', 'without_demo', 'http_enable', 'syslog',
'list_db', 'proxy_mode',
'test_file', 'test_tags',
'osv_memory_count_limit', 'transient_age_limit', 'max_cron_threads', 'unaccent',
'data_dir',
'server_wide_modules',
]

posix_keys = [
'workers',
'limit_memory_hard', 'limit_memory_soft',
'limit_time_cpu', 'limit_time_real', 'limit_request', 'limit_time_real_cron'
]

if os.name == 'posix':
keys += posix_keys
else:
self.options.update(dict.fromkeys(posix_keys, None))

# Copy the command-line arguments...
for arg in keys:
if getattr(opt, arg) is not None:
self.options[arg] = getattr(opt, arg)
# ... or keep, but cast, the config file value.
elif isinstance(self.options[arg], str) and self.casts[arg].type in optparse.Option.TYPE_CHECKER:
self.options[arg] = optparse.Option.TYPE_CHECKER[self.casts[arg].type](self.casts[arg], arg, self.options[arg])

ismultidb = ',' in (self.options.get('db_name') or '')
die(ismultidb and (opt.init or opt.update), "Cannot use -i/--init or -u/--update with multiple databases in the -d/--database/db_name")

Expand Down Expand Up @@ -573,9 +536,6 @@ def die(cond, msg):
dev_split = [s.strip() for s in opt.dev_mode.split(',')] if opt.dev_mode else []
self.options['dev_mode'] = dev_split + (['reload', 'qweb', 'xml'] if 'all' in dev_split else [])

if opt.pg_path:
self.options['pg_path'] = opt.pg_path

self.options['test_enable'] = bool(self.options['test_tags'])

if self.options['longpolling_port']:
Expand Down

0 comments on commit ca38632

Please sign in to comment.