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 two hardcoded
listings.

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

* pg_path was set just bellow using the same cli->file fallback logic
* test_enable was 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, more than 10 years ago...

Task-3380313
  • Loading branch information
Julien00859 committed Jan 24, 2024
1 parent f433ea0 commit 46b2231
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 @@ -468,17 +468,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_replica_host', 'db_sslmode',
'db_port', 'db_replica_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 @@ -494,37 +488,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])

die(bool(self.options['syslog']) and bool(self.options['logfile']),
"the syslog and logfile options are exclusive")

Expand Down Expand Up @@ -571,9 +534,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 46b2231

Please sign in to comment.