X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/1ff8751caaf3bbe470461ebd4e440a81ddd82ec9..f62c7841023777f7eb7804ae1f0131aec481361b:/nominatim/config.py diff --git a/nominatim/config.py b/nominatim/config.py index 0a595374..458c828f 100644 --- a/nominatim/config.py +++ b/nominatim/config.py @@ -21,18 +21,31 @@ class Configuration: 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()))) + if project_dir is not None: + 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_libpq_dsn(self): + """ Get configured database DSN converted into the key/value format + understood by libpq and psycopg. + """ + dsn = self.DATABASE_DSN + + if dsn.startswith('pgsql:'): + # Old PHP DSN format. Convert before returning. + return dsn[6:].replace(';', ' ') + + return dsn + 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) + env = dict(self._config) + env.update(os.environ) return env