have ADDRESS_LEVEL_CONFIG use load_sub_configuration

This means that relative paths now are looked up in the
project directory.
This commit is contained in:
Sarah Hoffmann
2021-10-22 16:31:33 +02:00
parent c77df2d1eb
commit 0ae8d7ac08
8 changed files with 33 additions and 34 deletions

View File

@@ -75,10 +75,9 @@ class UpdateRefresh:
self._get_tokenizer(args.config).update_statistics()
if args.address_levels:
cfg = Path(args.config.ADDRESS_LEVEL_CONFIG)
LOG.warning('Updating address levels from %s', cfg)
LOG.warning('Updating address levels')
with connect(args.config.get_libpq_dsn()) as conn:
refresh.load_address_levels_from_file(conn, cfg)
refresh.load_address_levels_from_config(conn, args.config)
if args.functions:
LOG.warning('Create functions')

View File

@@ -150,7 +150,7 @@ class SetupAll:
refresh.create_functions(conn, config, False, False)
LOG.warning('Create tables')
database_import.create_tables(conn, config, reverse_only=reverse_only)
refresh.load_address_levels_from_file(conn, Path(config.ADDRESS_LEVEL_CONFIG))
refresh.load_address_levels_from_config(conn, config)
LOG.warning('Create functions (2nd pass)')
refresh.create_functions(conn, config, False, False)
LOG.warning('Create table triggers')

View File

@@ -56,12 +56,6 @@ class Configuration:
if project_dir is not None and (project_dir / '.env').is_file():
self._config.update(dotenv_values(str((project_dir / '.env').resolve())))
# Add defaults for variables that are left empty to set the default.
# They may still be overwritten by environment variables.
if not self._config['NOMINATIM_ADDRESS_LEVEL_CONFIG']:
self._config['NOMINATIM_ADDRESS_LEVEL_CONFIG'] = \
str(config_dir / 'address-levels.json')
class _LibDirs:
pass

View File

@@ -1,7 +1,6 @@
"""
Functions for bringing auxiliary data in the database up-to-date.
"""
import json
import logging
from textwrap import dedent
@@ -58,12 +57,15 @@ def load_address_levels(conn, table, levels):
conn.commit()
def load_address_levels_from_file(conn, config_file):
""" Replace the `address_levels` table with the contents of the config
file.
def load_address_levels_from_config(conn, config):
""" Replace the `address_levels` table with the content as
defined in the given configuration. Uses the parameter
NOMINATIM_ADDRESS_LEVEL_CONFIG to determine the location of the
configuration file.
"""
with config_file.open('r') as fdesc:
load_address_levels(conn, 'address_levels', json.load(fdesc))
cfg = config.load_sub_configuration('', config='ADDRESS_LEVEL_CONFIG')
load_address_levels(conn, 'address_levels', cfg)
def create_functions(conn, config, enable_diff_updates=True, enable_debug=False):