]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/config.py
implement warming in new cli tool
[nominatim.git] / nominatim / config.py
1 """
2 Nominatim configuration accessor.
3 """
4 import sys
5 import os
6
7 from dotenv import dotenv_values
8
9 class Configuration:
10     """ Load and manage the project configuration.
11
12         Nominatim uses dotenv to configure the software. Configuration options
13         are resolved in the following order:
14
15          * from the OS environment
16          * from the .env file in the project directory of the installation
17          * from the default installation in the configuration directory
18
19         All Nominatim configuration options are prefixed with 'NOMINATIM_' to
20         avoid conflicts with other environment variables.
21     """
22
23     def __init__(self, project_dir, config_dir):
24         self._config = dotenv_values(str((config_dir / 'env.defaults').resolve()))
25         self._config.update(dotenv_values(str((project_dir / '.env').resolve())))
26
27     def __getattr__(self, name):
28         name = 'NOMINATIM_' + name
29
30         return os.environ.get(name) or self._config[name]
31
32     def get_os_env(self):
33         """ Return a copy of the OS environment with the Nominatim configuration
34             merged in.
35         """
36         env = dict(os.environ)
37         env.update(self._config)
38
39         return env