]> git.openstreetmap.org Git - nominatim.git/commitdiff
allow relative paths for flatnode file
authorSarah Hoffmann <lonvia@denofr.de>
Fri, 22 Oct 2021 15:32:51 +0000 (17:32 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Fri, 22 Oct 2021 15:32:51 +0000 (17:32 +0200)
docs/customize/Settings.md
nominatim/clicmd/args.py
nominatim/clicmd/freeze.py
nominatim/config.py
test/python/test_config.py

index 3a45e8fecd80f1db79ceb8e06639660af38153cc..b056a78bf2cc66256e97f3455b5c03eeb6ddade7 100644 (file)
@@ -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
 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
index 694e6fc5d9c045aff8b3c12473b3dc3436d67ac7..4e2c23a7baea190798cf4346d562af835e9824d4 100644 (file)
@@ -23,7 +23,7 @@ class NominatimArgs:
                     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,
index 8a6c928e7f3ade5ec8e5c06cfcc089853358d578..41dd610ed67f8f2246cda918f94f4558895730e1 100644 (file)
@@ -31,6 +31,6 @@ class SetupFreeze:
 
         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
index 66375f6ce336bc310f1994a17796d7bc150234e4..bc3556f3cdf101f722df036730eb7311d88c6474 100644 (file)
@@ -93,6 +93,23 @@ class Configuration:
             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.
index de7b93016658a177a77869109fe6ad2a5aae73de..a71324f9e4ac85eb7fc810b087693c37efb65044 100644 (file)
@@ -1,6 +1,7 @@
 """
 Test for loading dotenv configuration.
 """
+from pathlib import Path
 import pytest
 
 from nominatim.config import Configuration
@@ -166,6 +167,33 @@ def test_get_int_empty(make_config):
         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()