From: Sarah Hoffmann Date: Sun, 3 Jul 2022 16:36:33 +0000 (+0200) Subject: fix uses of config.get_path() to expect None X-Git-Tag: v4.1.0~10^2~29 X-Git-Url: https://git.openstreetmap.org./nominatim.git/commitdiff_plain/aaf2b6032eb3297aeb20b5c98223e9da734f56d4 fix uses of config.get_path() to expect None --- diff --git a/nominatim/clicmd/args.py b/nominatim/clicmd/args.py index d1f47ba0..6a3c8387 100644 --- a/nominatim/clicmd/args.py +++ b/nominatim/clicmd/args.py @@ -29,7 +29,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=str(self.config.get_path('FLATNODE_FILE')), + flatnode_file=str(self.config.get_path('FLATNODE_FILE') or ''), tablespaces=dict(slim_data=self.config.TABLESPACE_OSM_DATA, slim_index=self.config.TABLESPACE_OSM_INDEX, main_data=self.config.TABLESPACE_PLACE_DATA, diff --git a/nominatim/clicmd/freeze.py b/nominatim/clicmd/freeze.py index 85eb1b4a..b11880ca 100644 --- a/nominatim/clicmd/freeze.py +++ b/nominatim/clicmd/freeze.py @@ -37,6 +37,6 @@ class SetupFreeze: with connect(args.config.get_libpq_dsn()) as conn: freeze.drop_update_tables(conn) - freeze.drop_flatnode_file(str(args.config.get_path('FLATNODE_FILE'))) + freeze.drop_flatnode_file(args.config.get_path('FLATNODE_FILE')) return 0 diff --git a/nominatim/tools/freeze.py b/nominatim/tools/freeze.py index e502c963..b0ebb2c0 100644 --- a/nominatim/tools/freeze.py +++ b/nominatim/tools/freeze.py @@ -42,10 +42,8 @@ def drop_update_tables(conn): conn.commit() -def drop_flatnode_file(fname): +def drop_flatnode_file(fpath): """ Remove the flatnode file if it exists. """ - if fname: - fpath = Path(fname) - if fpath.exists(): - fpath.unlink() + if fpath and fpath.exists(): + fpath.unlink() diff --git a/nominatim/tools/refresh.py b/nominatim/tools/refresh.py index 561bcf83..257d587e 100644 --- a/nominatim/tools/refresh.py +++ b/nominatim/tools/refresh.py @@ -174,7 +174,7 @@ def _quote_php_variable(var_type, config, conf_name): return 'false' if var_type == Path: - value = str(config.get_path(conf_name)) + value = str(config.get_path(conf_name) or '') else: value = getattr(config, conf_name) diff --git a/test/python/tools/test_freeze.py b/test/python/tools/test_freeze.py index 30b673ff..3ebb1730 100644 --- a/test/python/tools/test_freeze.py +++ b/test/python/tools/test_freeze.py @@ -39,17 +39,17 @@ def test_drop_tables(temp_db_conn, temp_db_cursor, table_factory): assert not temp_db_cursor.table_exists(table) def test_drop_flatnode_file_no_file(): - freeze.drop_flatnode_file('') + freeze.drop_flatnode_file(None) def test_drop_flatnode_file_file_already_gone(tmp_path): - freeze.drop_flatnode_file(str(tmp_path / 'something.store')) + freeze.drop_flatnode_file(tmp_path / 'something.store') def test_drop_flatnode_file_delte(tmp_path): flatfile = tmp_path / 'flatnode.store' flatfile.write_text('Some content') - freeze.drop_flatnode_file(str(flatfile)) + freeze.drop_flatnode_file(flatfile) assert not flatfile.exists()