forked from hans/Nominatim
allow relative paths for flatnode file
This commit is contained in:
@@ -354,6 +354,9 @@ location for OSM nodes. For larger imports it can significantly speed up
|
|||||||
the import. When this option is unset, then osm2pgsql uses a PsotgreSQL table
|
the import. When this option is unset, then osm2pgsql uses a PsotgreSQL table
|
||||||
to store the locations.
|
to store the locations.
|
||||||
|
|
||||||
|
When a relative path is given, then the flatnode file is created/searched
|
||||||
|
relative to the project directory.
|
||||||
|
|
||||||
!!! warning
|
!!! warning
|
||||||
|
|
||||||
The flatnode file is not only used during the initial import but also
|
The flatnode file is not only used during the initial import but also
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class NominatimArgs:
|
|||||||
osm2pgsql_style=self.config.get_import_style_file(),
|
osm2pgsql_style=self.config.get_import_style_file(),
|
||||||
threads=self.threads or default_threads,
|
threads=self.threads or default_threads,
|
||||||
dsn=self.config.get_libpq_dsn(),
|
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,
|
tablespaces=dict(slim_data=self.config.TABLESPACE_OSM_DATA,
|
||||||
slim_index=self.config.TABLESPACE_OSM_INDEX,
|
slim_index=self.config.TABLESPACE_OSM_INDEX,
|
||||||
main_data=self.config.TABLESPACE_PLACE_DATA,
|
main_data=self.config.TABLESPACE_PLACE_DATA,
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ class SetupFreeze:
|
|||||||
|
|
||||||
with connect(args.config.get_libpq_dsn()) as conn:
|
with connect(args.config.get_libpq_dsn()) as conn:
|
||||||
freeze.drop_update_tables(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
|
return 0
|
||||||
|
|||||||
@@ -93,6 +93,23 @@ class Configuration:
|
|||||||
raise UsageError("Configuration error.") from exp
|
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):
|
def get_libpq_dsn(self):
|
||||||
""" Get configured database DSN converted into the key/value format
|
""" Get configured database DSN converted into the key/value format
|
||||||
understood by libpq and psycopg.
|
understood by libpq and psycopg.
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
Test for loading dotenv configuration.
|
Test for loading dotenv configuration.
|
||||||
"""
|
"""
|
||||||
|
from pathlib import Path
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from nominatim.config import Configuration
|
from nominatim.config import Configuration
|
||||||
@@ -166,6 +167,33 @@ def test_get_int_empty(make_config):
|
|||||||
config.get_int('DATABASE_MODULE_PATH')
|
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):
|
def test_get_import_style_intern(make_config, src_dir, monkeypatch):
|
||||||
config = make_config()
|
config = make_config()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user