X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/6e89310a9285f1ad15d8002bf68f578eada367a0..f6e792f31b105447d86c78ffa10ac343a6b5e332:/src/nominatim_db/tools/exec_utils.py diff --git a/src/nominatim_db/tools/exec_utils.py b/src/nominatim_db/tools/exec_utils.py index 5450c43b..406e2511 100644 --- a/src/nominatim_db/tools/exec_utils.py +++ b/src/nominatim_db/tools/exec_utils.py @@ -13,8 +13,8 @@ import os import subprocess import shutil -from nominatim_core.typing import StrPath -from nominatim_core.db.connection import get_pg_env +from ..typing import StrPath +from ..db.connection import get_pg_env LOG = logging.getLogger() @@ -30,13 +30,7 @@ def run_osm2pgsql(options: Mapping[str, Any]) -> None: """ env = get_pg_env(options['dsn']) - osm2pgsql_cmd = options['osm2pgsql'] - if osm2pgsql_cmd is None: - osm2pgsql_cmd = shutil.which('osm2pgsql') - if osm2pgsql_cmd is None: - raise RuntimeError('osm2pgsql executable not found. Please install osm2pgsql first.') - - cmd = [str(osm2pgsql_cmd), + cmd = [_find_osm2pgsql_cmd(options['osm2pgsql']), '--slim', '--log-progress', 'true', '--number-processes', '1' if options['append'] else str(options['threads']), @@ -82,3 +76,14 @@ def run_osm2pgsql(options: Mapping[str, Any]) -> None: subprocess.run(cmd, cwd=options.get('cwd', '.'), input=options.get('import_data'), env=env, check=True) + + +def _find_osm2pgsql_cmd(cmdline: str) -> str: + if cmdline is not None: + return cmdline + + in_path = shutil.which('osm2pgsql') + if in_path is None: + raise RuntimeError('osm2pgsql executable not found. Please install osm2pgsql first.') + + return str(in_path)