mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-09 11:34:07 +00:00
use data paths from new nominatim.paths
This commit is contained in:
@@ -100,9 +100,7 @@ class CommandlineParser:
|
||||
self.parser.print_help()
|
||||
return 1
|
||||
|
||||
for arg in ('module_dir', 'osm2pgsql_path', 'phplib_dir', 'sqllib_dir',
|
||||
'data_dir', 'config_dir', 'phpcgi_path'):
|
||||
setattr(args, arg, Path(kwargs[arg]))
|
||||
args.phpcgi_path = Path(kwargs['phpcgi_path'])
|
||||
args.project_dir = Path(args.project_dir).resolve()
|
||||
|
||||
if 'cli_args' not in kwargs:
|
||||
@@ -111,13 +109,10 @@ class CommandlineParser:
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
level=max(4 - args.verbose, 1) * 10)
|
||||
|
||||
args.config = Configuration(args.project_dir, args.config_dir,
|
||||
args.config = Configuration(args.project_dir,
|
||||
environ=kwargs.get('environ', os.environ))
|
||||
args.config.set_libdirs(module=args.module_dir,
|
||||
osm2pgsql=args.osm2pgsql_path,
|
||||
php=args.phplib_dir,
|
||||
sql=args.sqllib_dir,
|
||||
data=args.data_dir)
|
||||
args.config.set_libdirs(module=kwargs['module_dir'],
|
||||
osm2pgsql=kwargs['osm2pgsql_path'])
|
||||
|
||||
log = logging.getLogger()
|
||||
log.warning('Using project directory: %s', str(args.project_dir))
|
||||
@@ -195,7 +190,7 @@ class QueryExport:
|
||||
if args.restrict_to_osm_relation:
|
||||
params.extend(('--restrict-to-osm-relation', args.restrict_to_osm_relation))
|
||||
|
||||
return run_legacy_script('export.php', *params, nominatim_env=args)
|
||||
return run_legacy_script('export.php', *params, config=args.config)
|
||||
|
||||
|
||||
class AdminServe:
|
||||
|
||||
@@ -88,4 +88,4 @@ class AdminFuncs:
|
||||
params.append('--reverse-only')
|
||||
if args.target == 'search':
|
||||
params.append('--search-only')
|
||||
return run_legacy_script(*params, nominatim_env=args)
|
||||
return run_legacy_script(*params, config=args.config)
|
||||
|
||||
@@ -42,12 +42,6 @@ class NominatimArgs:
|
||||
# Basic environment set by root program.
|
||||
config: Configuration
|
||||
project_dir: Path
|
||||
module_dir: Path
|
||||
osm2pgsql_path: Path
|
||||
phplib_dir: Path
|
||||
sqllib_dir: Path
|
||||
data_dir: Path
|
||||
config_dir: Path
|
||||
phpcgi_path: Path
|
||||
|
||||
# Global switches
|
||||
@@ -181,7 +175,7 @@ class NominatimArgs:
|
||||
from the command line arguments. The resulting dict can be
|
||||
further customized and then used in `run_osm2pgsql()`.
|
||||
"""
|
||||
return dict(osm2pgsql=self.config.OSM2PGSQL_BINARY or self.osm2pgsql_path,
|
||||
return dict(osm2pgsql=self.config.OSM2PGSQL_BINARY or self.config.lib_dir.osm2pgsql,
|
||||
osm2pgsql_cache=self.osm2pgsql_cache or default_cache,
|
||||
osm2pgsql_style=self.config.get_import_style_file(),
|
||||
osm2pgsql_style_path=self.config.config_dir,
|
||||
|
||||
@@ -87,7 +87,7 @@ class SetupAll:
|
||||
|
||||
LOG.warning('Setting up country tables')
|
||||
country_info.setup_country_tables(args.config.get_libpq_dsn(),
|
||||
args.data_dir,
|
||||
args.config.lib_dir.data,
|
||||
args.no_partitions)
|
||||
|
||||
LOG.warning('Importing OSM data file')
|
||||
|
||||
@@ -20,6 +20,7 @@ from dotenv import dotenv_values
|
||||
|
||||
from nominatim.typing import StrPath
|
||||
from nominatim.errors import UsageError
|
||||
import nominatim.paths
|
||||
|
||||
LOG = logging.getLogger()
|
||||
CONFIG_CACHE : Dict[str, Any] = {}
|
||||
@@ -58,21 +59,22 @@ class Configuration:
|
||||
avoid conflicts with other environment variables.
|
||||
"""
|
||||
|
||||
def __init__(self, project_dir: Path, config_dir: Path,
|
||||
def __init__(self, project_dir: Optional[Path],
|
||||
environ: Optional[Mapping[str, str]] = None) -> None:
|
||||
self.environ = environ or os.environ
|
||||
self.project_dir = project_dir
|
||||
self.config_dir = config_dir
|
||||
self._config = dotenv_values(str((config_dir / 'env.defaults').resolve()))
|
||||
if project_dir is not None and (project_dir / '.env').is_file():
|
||||
self._config.update(dotenv_values(str((project_dir / '.env').resolve())))
|
||||
self.config_dir = nominatim.paths.CONFIG_DIR
|
||||
self._config = dotenv_values(str(self.config_dir / 'env.defaults'))
|
||||
if self.project_dir is not None and (self.project_dir / '.env').is_file():
|
||||
self.project_dir = self.project_dir.resolve()
|
||||
self._config.update(dotenv_values(str(self.project_dir / '.env')))
|
||||
|
||||
class _LibDirs:
|
||||
module: Path
|
||||
osm2pgsql: Path
|
||||
php: Path
|
||||
sql: Path
|
||||
data: Path
|
||||
php = nominatim.paths.PHPLIB_DIR
|
||||
sql = nominatim.paths.SQLLIB_DIR
|
||||
data = nominatim.paths.DATA_DIR
|
||||
|
||||
self.lib_dir = _LibDirs()
|
||||
self._private_plugins: Dict[str, object] = {}
|
||||
@@ -82,7 +84,7 @@ class Configuration:
|
||||
""" Set paths to library functions and data.
|
||||
"""
|
||||
for key, value in kwargs.items():
|
||||
setattr(self.lib_dir, key, Path(value).resolve())
|
||||
setattr(self.lib_dir, key, Path(value))
|
||||
|
||||
|
||||
def __getattr__(self, name: str) -> str:
|
||||
@@ -136,6 +138,7 @@ class Configuration:
|
||||
cfgpath = Path(value)
|
||||
|
||||
if not cfgpath.is_absolute():
|
||||
assert self.project_dir is not None
|
||||
cfgpath = self.project_dir / cfgpath
|
||||
|
||||
return cfgpath.resolve()
|
||||
@@ -174,11 +177,11 @@ class Configuration:
|
||||
return self.find_config_file('', 'IMPORT_STYLE')
|
||||
|
||||
|
||||
def get_os_env(self) -> Dict[str, Optional[str]]:
|
||||
def get_os_env(self) -> Dict[str, str]:
|
||||
""" Return a copy of the OS environment with the Nominatim configuration
|
||||
merged in.
|
||||
"""
|
||||
env = dict(self._config)
|
||||
env = {k: v for k, v in self._config.items() if v is not None}
|
||||
env.update(self.environ)
|
||||
|
||||
return env
|
||||
|
||||
@@ -55,6 +55,7 @@ def create_tokenizer(config: Configuration, init_db: bool = True,
|
||||
module_name = config.TOKENIZER
|
||||
|
||||
# Create the directory for the tokenizer data
|
||||
assert config.project_dir is not None
|
||||
basedir = config.project_dir / 'tokenizer'
|
||||
if not basedir.exists():
|
||||
basedir.mkdir()
|
||||
@@ -80,6 +81,7 @@ def get_tokenizer_for_db(config: Configuration) -> AbstractTokenizer:
|
||||
The function looks up the appropriate tokenizer in the database
|
||||
and initialises it.
|
||||
"""
|
||||
assert config.project_dir is not None
|
||||
basedir = config.project_dir / 'tokenizer'
|
||||
if not basedir.is_dir():
|
||||
# Directory will be repopulated by tokenizer below.
|
||||
|
||||
@@ -106,6 +106,7 @@ class LegacyTokenizer(AbstractTokenizer):
|
||||
This copies all necessary data in the project directory to make
|
||||
sure the tokenizer remains stable even over updates.
|
||||
"""
|
||||
assert config.project_dir is not None
|
||||
module_dir = _install_module(config.DATABASE_MODULE_PATH,
|
||||
config.lib_dir.module,
|
||||
config.project_dir / 'module')
|
||||
@@ -127,6 +128,8 @@ class LegacyTokenizer(AbstractTokenizer):
|
||||
def init_from_project(self, config: Configuration) -> None:
|
||||
""" Initialise the tokenizer from the project directory.
|
||||
"""
|
||||
assert config.project_dir is not None
|
||||
|
||||
with connect(self.dsn) as conn:
|
||||
self.normalization = properties.get_property(conn, DBCFG_NORMALIZATION)
|
||||
|
||||
@@ -149,6 +152,8 @@ class LegacyTokenizer(AbstractTokenizer):
|
||||
def update_sql_functions(self, config: Configuration) -> None:
|
||||
""" Reimport the SQL functions for this tokenizer.
|
||||
"""
|
||||
assert config.project_dir is not None
|
||||
|
||||
with connect(self.dsn) as conn:
|
||||
max_word_freq = properties.get_property(conn, DBCFG_MAXWORDFREQ)
|
||||
modulepath = config.DATABASE_MODULE_PATH or \
|
||||
@@ -193,6 +198,8 @@ class LegacyTokenizer(AbstractTokenizer):
|
||||
This is a special migration function for updating existing databases
|
||||
to new software versions.
|
||||
"""
|
||||
assert config.project_dir is not None
|
||||
|
||||
self.normalization = config.TERM_NORMALIZATION
|
||||
module_dir = _install_module(config.DATABASE_MODULE_PATH,
|
||||
config.lib_dir.module,
|
||||
|
||||
@@ -15,6 +15,7 @@ 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 version_str
|
||||
from nominatim.db.connection import get_pg_env
|
||||
@@ -22,7 +23,7 @@ from nominatim.db.connection import get_pg_env
|
||||
LOG = logging.getLogger()
|
||||
|
||||
def run_legacy_script(script: StrPath, *args: Union[int, str],
|
||||
nominatim_env: Any,
|
||||
config: Configuration,
|
||||
throw_on_fail: bool = False) -> int:
|
||||
""" Run a Nominatim PHP script with the given arguments.
|
||||
|
||||
@@ -30,18 +31,18 @@ def run_legacy_script(script: StrPath, *args: Union[int, str],
|
||||
then throw a `CalledProcessError` on a non-zero exit.
|
||||
"""
|
||||
cmd = ['/usr/bin/env', 'php', '-Cq',
|
||||
str(nominatim_env.phplib_dir / 'admin' / script)]
|
||||
str(config.lib_dir.php / 'admin' / script)]
|
||||
cmd.extend([str(a) for a in args])
|
||||
|
||||
env = nominatim_env.config.get_os_env()
|
||||
env['NOMINATIM_DATADIR'] = str(nominatim_env.data_dir)
|
||||
env['NOMINATIM_SQLDIR'] = str(nominatim_env.sqllib_dir)
|
||||
env['NOMINATIM_CONFIGDIR'] = str(nominatim_env.config_dir)
|
||||
env['NOMINATIM_DATABASE_MODULE_SRC_PATH'] = str(nominatim_env.module_dir)
|
||||
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(nominatim_env.osm2pgsql_path)
|
||||
env['NOMINATIM_OSM2PGSQL_BINARY'] = str(config.lib_dir.osm2pgsql)
|
||||
|
||||
proc = subprocess.run(cmd, cwd=str(nominatim_env.project_dir), env=env,
|
||||
proc = subprocess.run(cmd, cwd=str(config.project_dir), env=env,
|
||||
check=throw_on_fail)
|
||||
|
||||
return proc.returncode
|
||||
|
||||
@@ -216,6 +216,7 @@ def setup_website(basedir: Path, config: Configuration, conn: Connection) -> Non
|
||||
LOG.info('Creating website directory.')
|
||||
basedir.mkdir()
|
||||
|
||||
assert config.project_dir is not None
|
||||
template = dedent(f"""\
|
||||
<?php
|
||||
|
||||
|
||||
Reference in New Issue
Block a user