From 298ed11261cdb959406435b97be750abb0abc4af Mon Sep 17 00:00:00 2001 From: Sarah Hoffmann Date: Tue, 9 Feb 2021 18:45:45 +0100 Subject: [PATCH] introduce constant for configuration directory This replaces {data_dir}/settings throughout the code, so that the configuration may be placed somewhere else in the directory structure (e.g. in /etc). --- cmake/script.tmpl | 1 + cmake/tool.tmpl | 1 + lib-php/dotenv_loader.php | 2 +- lib-php/lib.php | 3 ++- lib-php/setup_functions.php | 2 +- nominatim/cli.py | 4 ++-- nominatim/tools/exec_utils.py | 1 + test/bdd/steps/nominatim_environment.py | 1 + 8 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmake/script.tmpl b/cmake/script.tmpl index f0fa2118..053e94ae 100755 --- a/cmake/script.tmpl +++ b/cmake/script.tmpl @@ -7,6 +7,7 @@ require('@CMAKE_SOURCE_DIR@/lib-php/dotenv_loader.php'); @define('CONST_BinDir', '@CMAKE_SOURCE_DIR@/utils'); @define('CONST_DataDir', '@CMAKE_SOURCE_DIR@'); @define('CONST_SqlDir', '@CMAKE_SOURCE_DIR@/lib-sql'); +@define('CONST_ConfigDir', '@CMAKE_SOURCE_DIR@/settings'); loadDotEnv(); $_SERVER['NOMINATIM_NOMINATIM_TOOL'] = '@CMAKE_BINARY_DIR@/nominatim'; diff --git a/cmake/tool.tmpl b/cmake/tool.tmpl index 76f80924..9823c75f 100755 --- a/cmake/tool.tmpl +++ b/cmake/tool.tmpl @@ -13,4 +13,5 @@ exit(cli.nominatim(module_dir='@CMAKE_BINARY_DIR@/module', phplib_dir='@CMAKE_SOURCE_DIR@/lib-php', sqllib_dir='@CMAKE_SOURCE_DIR@/lib-sql', data_dir='@CMAKE_SOURCE_DIR@', + config_dir='@CMAKE_SOURCE_DIR@/settings', phpcgi_path='@PHPCGI_BIN@')) diff --git a/lib-php/dotenv_loader.php b/lib-php/dotenv_loader.php index 919891a0..35471fdc 100644 --- a/lib-php/dotenv_loader.php +++ b/lib-php/dotenv_loader.php @@ -5,7 +5,7 @@ require('Symfony/Component/Dotenv/autoload.php'); function loadDotEnv() { $dotenv = new \Symfony\Component\Dotenv\Dotenv(); - $dotenv->load(CONST_DataDir.'/settings/env.defaults'); + $dotenv->load(CONST_ConfigDir.'/env.defaults'); if (file_exists('.env')) { $dotenv->load('.env'); diff --git a/lib-php/lib.php b/lib-php/lib.php index 04b9bf86..c75bf00a 100644 --- a/lib-php/lib.php +++ b/lib-php/lib.php @@ -9,6 +9,7 @@ function loadSettings($sProjectDir) defined('CONST_DataDir') or define('CONST_DataDir', $_SERVER['NOMINATIM_DATADIR']); defined('CONST_BinDir') or define('CONST_BinDir', $_SERVER['NOMINATIM_BINDIR']); defined('CONST_SqlDir') or define('CONST_SqlDir', $_SERVER['NOMINATIM_SQLDIR']); + defined('CONST_ConfigDir') or define('CONST_ConfigDir', $_SERVER['NOMINATIM_CONFIGDIR']); defined('CONST_Default_ModulePath') or define('CONST_Default_ModulePath', $_SERVER['NOMINATIM_DATABASE_MODULE_SRC_PATH']); } @@ -37,7 +38,7 @@ function getSettingConfig($sConfName, $sSystemConfig) $sValue = $_SERVER['NOMINATIM_'.$sConfName]; if (!$sValue) { - return CONST_DataDir.'/settings/'.$sSystemConfig; + return CONST_ConfigDir.'/'.$sSystemConfig; } return $sValue; diff --git a/lib-php/setup_functions.php b/lib-php/setup_functions.php index dc84cf92..c89db534 100755 --- a/lib-php/setup_functions.php +++ b/lib-php/setup_functions.php @@ -27,7 +27,7 @@ function getImportStyle() $sStyle = getSetting('IMPORT_STYLE'); if (in_array($sStyle, array('admin', 'street', 'address', 'full', 'extratags'))) { - return CONST_DataDir.'/settings/import-'.$sStyle.'.style'; + return CONST_ConfigDir.'/import-'.$sStyle.'.style'; } return $sStyle; diff --git a/nominatim/cli.py b/nominatim/cli.py index 784250e8..8cb73a8e 100644 --- a/nominatim/cli.py +++ b/nominatim/cli.py @@ -69,7 +69,7 @@ class CommandlineParser: return 1 for arg in ('module_dir', 'osm2pgsql_path', 'phplib_dir', 'sqllib_dir', - 'data_dir', 'phpcgi_path'): + 'data_dir', 'config_dir', 'phpcgi_path'): setattr(args, arg, Path(kwargs[arg])) args.project_dir = Path(args.project_dir).resolve() @@ -78,7 +78,7 @@ class CommandlineParser: datefmt='%Y-%m-%d %H:%M:%S', level=max(4 - args.verbose, 1) * 10) - args.config = Configuration(args.project_dir, args.data_dir / 'settings') + args.config = Configuration(args.project_dir, args.config_dir) log = logging.getLogger() log.warning('Using project directory: %s', str(args.project_dir)) diff --git a/nominatim/tools/exec_utils.py b/nominatim/tools/exec_utils.py index 502fb4fe..23dd8a1d 100644 --- a/nominatim/tools/exec_utils.py +++ b/nominatim/tools/exec_utils.py @@ -27,6 +27,7 @@ def run_legacy_script(script, *args, nominatim_env=None, throw_on_fail=False): env['NOMINATIM_DATADIR'] = str(nominatim_env.data_dir) env['NOMINATIM_BINDIR'] = str(nominatim_env.data_dir / 'utils') env['NOMINATIM_SQLDIR'] = str(nominatim_env.sqllib_dir) + env['NOMINATIM_CONFIGDIR'] = str(nominatim_env.config_dir) env['NOMINATIM_DATABASE_MODULE_SRC_PATH'] = nominatim_env.module_dir if not env['NOMINATIM_OSM2PGSQL_BINARY']: env['NOMINATIM_OSM2PGSQL_BINARY'] = nominatim_env.osm2pgsql_path diff --git a/test/bdd/steps/nominatim_environment.py b/test/bdd/steps/nominatim_environment.py index 6dcaf64a..70325536 100644 --- a/test/bdd/steps/nominatim_environment.py +++ b/test/bdd/steps/nominatim_environment.py @@ -89,6 +89,7 @@ class NominatimEnvironment: self.test_env['NOMINATIM_USE_US_TIGER_DATA'] = 'yes' self.test_env['NOMINATIM_DATADIR'] = self.src_dir self.test_env['NOMINATIM_SQLDIR'] = self.src_dir / 'lib-sql' + self.test_env['NOMINATIM_CONFIGDIR'] = self.src_dir / 'settings' self.test_env['NOMINATIM_BINDIR'] = self.src_dir / 'utils' self.test_env['NOMINATIM_DATABASE_MODULE_SRC_PATH'] = self.build_dir / 'module' self.test_env['NOMINATIM_OSM2PGSQL_BINARY'] = self.build_dir / 'osm2pgsql' / 'osm2pgsql' -- 2.39.5