implement warming in new cli tool

Adds infrastructure for calling the legacy PHP scripts. As the
CONST_* values cannot be set from the python script, hand the values
in via secret environment variables instead. These are all
temporary hacks for the transition phase to python code.
This commit is contained in:
Sarah Hoffmann
2021-01-13 18:25:15 +01:00
parent ec636111ba
commit 04690ad8c4
5 changed files with 96 additions and 11 deletions

39
nominatim/config.py Normal file
View File

@@ -0,0 +1,39 @@
"""
Nominatim configuration accessor.
"""
import sys
import os
from dotenv import dotenv_values
class Configuration:
""" Load and manage the project configuration.
Nominatim uses dotenv to configure the software. Configuration options
are resolved in the following order:
* from the OS environment
* from the .env file in the project directory of the installation
* from the default installation in the configuration directory
All Nominatim configuration options are prefixed with 'NOMINATIM_' to
avoid conflicts with other environment variables.
"""
def __init__(self, project_dir, config_dir):
self._config = dotenv_values(str((config_dir / 'env.defaults').resolve()))
self._config.update(dotenv_values(str((project_dir / '.env').resolve())))
def __getattr__(self, name):
name = 'NOMINATIM_' + name
return os.environ.get(name) or self._config[name]
def get_os_env(self):
""" Return a copy of the OS environment with the Nominatim configuration
merged in.
"""
env = dict(os.environ)
env.update(self._config)
return env