]> git.openstreetmap.org Git - nominatim.git/commitdiff
remove now unused run_legacy_script()
authorSarah Hoffmann <lonvia@denofr.de>
Thu, 20 Jul 2023 10:14:19 +0000 (12:14 +0200)
committerSarah Hoffmann <lonvia@denofr.de>
Tue, 25 Jul 2023 19:39:23 +0000 (21:39 +0200)
nominatim/tools/exec_utils.py
test/python/cli/conftest.py
test/python/tools/test_exec_utils.py

index 566ac06edc57d4374b4979095866c64c1e959d60..c8de8c7d789b076c7b9dac7e0bb1c2a57439fe07 100644 (file)
@@ -7,7 +7,7 @@
 """
 Helper functions for executing external programs.
 """
-from typing import Any, Union, Optional, Mapping, IO
+from typing import Any, Optional, Mapping, IO
 from pathlib import Path
 import logging
 import os
@@ -15,38 +15,12 @@ import subprocess
 import urllib.request as urlrequest
 from urllib.parse import urlencode
 
-from nominatim.config import Configuration
 from nominatim.typing import StrPath
 from nominatim.version import NOMINATIM_VERSION
 from nominatim.db.connection import get_pg_env
 
 LOG = logging.getLogger()
 
-def run_legacy_script(script: StrPath, *args: Union[int, str],
-                      config: Configuration,
-                      throw_on_fail: bool = False) -> int:
-    """ Run a Nominatim PHP script with the given arguments.
-
-        Returns the exit code of the script. If `throw_on_fail` is True
-        then throw a `CalledProcessError` on a non-zero exit.
-    """
-    cmd = ['/usr/bin/env', 'php', '-Cq',
-           str(config.lib_dir.php / 'admin' / script)]
-    cmd.extend([str(a) for a in args])
-
-    env = config.get_os_env()
-    env['NOMINATIM_DATADIR'] = str(config.lib_dir.data)
-    env['NOMINATIM_SQLDIR'] = str(config.lib_dir.sql)
-    env['NOMINATIM_CONFIGDIR'] = str(config.config_dir)
-    env['NOMINATIM_DATABASE_MODULE_SRC_PATH'] = str(config.lib_dir.module)
-    if not env['NOMINATIM_OSM2PGSQL_BINARY']:
-        env['NOMINATIM_OSM2PGSQL_BINARY'] = str(config.lib_dir.osm2pgsql)
-
-    proc = subprocess.run(cmd, cwd=str(config.project_dir), env=env,
-                          check=throw_on_fail)
-
-    return proc.returncode
-
 def run_api_script(endpoint: str, project_dir: Path,
                    extra_env: Optional[Mapping[str, str]] = None,
                    phpcgi_bin: Optional[Path] = None,
index 09bfd3534ad4ee96032e49db1d18d70eee9d5f32..d4e1118e780478a833fa7f7fd0700270b4dbbf7c 100644 (file)
@@ -59,13 +59,6 @@ def cli_call(src_dir):
     return _call_nominatim
 
 
-@pytest.fixture
-def mock_run_legacy(monkeypatch):
-    mock = MockParamCapture()
-    monkeypatch.setattr(nominatim.cli, 'run_legacy_script', mock)
-    return mock
-
-
 @pytest.fixture
 def mock_func_factory(monkeypatch):
     def get_mock(module, func):
index f73aec308404000e8fbab2f059b72ac5415dd73b..792c24c853ca8d29cae4ab01683b6c92bd8a595a 100644 (file)
@@ -16,75 +16,6 @@ from nominatim.config import Configuration
 import nominatim.tools.exec_utils as exec_utils
 import nominatim.paths
 
-class TestRunLegacyScript:
-
-    @pytest.fixture(autouse=True)
-    def setup_nominatim_env(self, tmp_path, monkeypatch):
-        tmp_phplib_dir = tmp_path / 'phplib'
-        tmp_phplib_dir.mkdir()
-        (tmp_phplib_dir / 'admin').mkdir()
-
-        monkeypatch.setattr(nominatim.paths, 'PHPLIB_DIR', tmp_phplib_dir)
-
-        self.phplib_dir = tmp_phplib_dir
-        self.config = Configuration(tmp_path)
-        self.config.set_libdirs(module='.', osm2pgsql='default_osm2pgsql',
-                                php=tmp_phplib_dir)
-
-
-    def mk_script(self, code):
-        codefile = self.phplib_dir / 'admin' / 't.php'
-        codefile.write_text('<?php\n' + code + '\n')
-
-        return 't.php'
-
-
-    @pytest.mark.parametrize("return_code", (0, 1, 15, 255))
-    def test_run_legacy_return_exit_code(self, return_code):
-        fname = self.mk_script('exit({});'.format(return_code))
-        assert return_code == \
-                 exec_utils.run_legacy_script(fname, config=self.config)
-
-
-    def test_run_legacy_return_throw_on_fail(self):
-        fname = self.mk_script('exit(11);')
-        with pytest.raises(subprocess.CalledProcessError):
-            exec_utils.run_legacy_script(fname, config=self.config,
-                                         throw_on_fail=True)
-
-
-    def test_run_legacy_return_dont_throw_on_success(self):
-        fname = self.mk_script('exit(0);')
-        assert exec_utils.run_legacy_script(fname, config=self.config,
-                                            throw_on_fail=True) == 0
-
-    def test_run_legacy_use_given_module_path(self):
-        fname = self.mk_script("exit($_SERVER['NOMINATIM_DATABASE_MODULE_PATH'] == '' ? 0 : 23);")
-
-        assert exec_utils.run_legacy_script(fname, config=self.config) == 0
-
-
-    def test_run_legacy_do_not_overwrite_module_path(self, monkeypatch):
-        monkeypatch.setenv('NOMINATIM_DATABASE_MODULE_PATH', 'other')
-        fname = self.mk_script(
-            "exit($_SERVER['NOMINATIM_DATABASE_MODULE_PATH'] == 'other' ? 0 : 1);")
-
-        assert exec_utils.run_legacy_script(fname, config=self.config) == 0
-
-
-    def test_run_legacy_default_osm2pgsql_binary(self, monkeypatch):
-        fname = self.mk_script("exit($_SERVER['NOMINATIM_OSM2PGSQL_BINARY'] == 'default_osm2pgsql' ? 0 : 23);")
-
-        assert exec_utils.run_legacy_script(fname, config=self.config) == 0
-
-
-    def test_run_legacy_override_osm2pgsql_binary(self, monkeypatch):
-        monkeypatch.setenv('NOMINATIM_OSM2PGSQL_BINARY', 'somethingelse')
-
-        fname = self.mk_script("exit($_SERVER['NOMINATIM_OSM2PGSQL_BINARY'] == 'somethingelse' ? 0 : 23);")
-
-        assert exec_utils.run_legacy_script(fname, config=self.config) == 0
-
 
 class TestRunApiScript: