2 Implementation of 'refresh' subcommand.
5 from pathlib import Path
7 from ..db.connection import connect
8 from ..tools.exec_utils import run_legacy_script
10 # Do not repeat documentation of subcommand classes.
11 # pylint: disable=C0111
12 # Using non-top-level imports to avoid eventually unused imports.
13 # pylint: disable=E0012,C0415
15 LOG = logging.getLogger()
19 Recompute auxiliary data used by the indexing process.
21 These functions must not be run in parallel with other update commands.
26 group = parser.add_argument_group('Data arguments')
27 group.add_argument('--postcodes', action='store_true',
28 help='Update postcode centroid table')
29 group.add_argument('--word-counts', action='store_true',
30 help='Compute frequency of full-word search terms')
31 group.add_argument('--address-levels', action='store_true',
32 help='Reimport address level configuration')
33 group.add_argument('--functions', action='store_true',
34 help='Update the PL/pgSQL functions in the database')
35 group.add_argument('--wiki-data', action='store_true',
36 help='Update Wikipedia/data importance numbers.')
37 group.add_argument('--importance', action='store_true',
38 help='Recompute place importances (expensive!)')
39 group.add_argument('--website', action='store_true',
40 help='Refresh the directory that serves the scripts for the web API')
41 group = parser.add_argument_group('Arguments for function refresh')
42 group.add_argument('--no-diff-updates', action='store_false', dest='diffs',
43 help='Do not enable code for propagating updates')
44 group.add_argument('--enable-debug-statements', action='store_true',
45 help='Enable debug warning statements in functions')
49 from ..tools import refresh
52 LOG.warning("Update postcodes centroid")
53 conn = connect(args.config.get_libpq_dsn())
54 refresh.update_postcodes(conn, args.sqllib_dir)
58 LOG.warning('Recompute frequency of full-word search terms')
59 conn = connect(args.config.get_libpq_dsn())
60 refresh.recompute_word_counts(conn, args.data_dir)
63 if args.address_levels:
64 cfg = Path(args.config.ADDRESS_LEVEL_CONFIG)
65 LOG.warning('Updating address levels from %s', cfg)
66 conn = connect(args.config.get_libpq_dsn())
67 refresh.load_address_levels_from_file(conn, cfg)
71 LOG.warning('Create functions')
72 conn = connect(args.config.get_libpq_dsn())
73 refresh.create_functions(conn, args.config, args.sqllib_dir,
74 args.diffs, args.enable_debug_statements)
78 run_legacy_script('setup.php', '--import-wikipedia-articles',
79 nominatim_env=args, throw_on_fail=True)
80 # Attention: importance MUST come after wiki data import.
82 run_legacy_script('update.php', '--recompute-importance',
83 nominatim_env=args, throw_on_fail=True)
85 run_legacy_script('setup.php', '--setup-website',
86 nominatim_env=args, throw_on_fail=True)