the import. When this option is unset, then osm2pgsql uses a PsotgreSQL table
to store the locations.
+When a relative path is given, then the flatnode file is created/searched
+relative to the project directory.
+
!!! warning
The flatnode file is not only used during the initial import but also
osm2pgsql_style=self.config.get_import_style_file(),
threads=self.threads or default_threads,
dsn=self.config.get_libpq_dsn(),
- flatnode_file=self.config.FLATNODE_FILE,
+ flatnode_file=str(self.config.get_path('FLATNODE_FILE')),
tablespaces=dict(slim_data=self.config.TABLESPACE_OSM_DATA,
slim_index=self.config.TABLESPACE_OSM_INDEX,
main_data=self.config.TABLESPACE_PLACE_DATA,
with connect(args.config.get_libpq_dsn()) as conn:
freeze.drop_update_tables(conn)
- freeze.drop_flatnode_file(args.config.FLATNODE_FILE)
+ freeze.drop_flatnode_file(str(args.config.get_path('FLATNODE_FILE')))
return 0
raise UsageError("Configuration error.") from exp
+ def get_path(self, name):
+ """ Return the given configuration parameter as a Path.
+ If a relative path is configured, then the function converts this
+ into an absolute path with the project directory as root path.
+ If the configuration is unset, a falsy value is returned.
+ """
+ value = self.__getattr__(name)
+ if value:
+ value = Path(value)
+
+ if not value.is_absolute():
+ value = self.project_dir / value
+
+ value = value.resolve()
+
+ return value
+
def get_libpq_dsn(self):
""" Get configured database DSN converted into the key/value format
understood by libpq and psycopg.
"""
Test for loading dotenv configuration.
"""
+from pathlib import Path
import pytest
from nominatim.config import Configuration
config.get_int('DATABASE_MODULE_PATH')
+def test_get_path_empty(make_config):
+ config = make_config()
+
+ assert config.DATABASE_MODULE_PATH == ''
+ assert not config.get_path('DATABASE_MODULE_PATH')
+
+
+def test_get_path_absolute(make_config, monkeypatch):
+ config = make_config()
+
+ monkeypatch.setenv('NOMINATIM_FOOBAR', '/dont/care')
+ result = config.get_path('FOOBAR')
+
+ assert isinstance(result, Path)
+ assert str(result) == '/dont/care'
+
+
+def test_get_path_relative(make_config, monkeypatch, tmp_path):
+ config = make_config(tmp_path)
+
+ monkeypatch.setenv('NOMINATIM_FOOBAR', 'an/oyster')
+ result = config.get_path('FOOBAR')
+
+ assert isinstance(result, Path)
+ assert str(result) == str(tmp_path / 'an/oyster')
+
+
def test_get_import_style_intern(make_config, src_dir, monkeypatch):
config = make_config()