]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/clicmd/refresh.py
rename sql directory to lib-sql
[nominatim.git] / nominatim / clicmd / refresh.py
1 """
2 Implementation of 'refresh' subcommand.
3 """
4 import logging
5 from pathlib import Path
6
7 from ..db.connection import connect
8 from ..tools.exec_utils import run_legacy_script
9
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
14
15 LOG = logging.getLogger()
16
17 class UpdateRefresh:
18     """\
19     Recompute auxiliary data used by the indexing process.
20
21     These functions must not be run in parallel with other update commands.
22     """
23
24     @staticmethod
25     def add_args(parser):
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')
46
47     @staticmethod
48     def run(args):
49         from ..tools import refresh
50
51         if args.postcodes:
52             LOG.warning("Update postcodes centroid")
53             conn = connect(args.config.get_libpq_dsn())
54             refresh.update_postcodes(conn, args.sqllib_dir)
55             conn.close()
56
57         if args.word_counts:
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)
61             conn.close()
62
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)
68             conn.close()
69
70         if args.functions:
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)
75             conn.close()
76
77         if args.wiki_data:
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.
81         if args.importance:
82             run_legacy_script('update.php', '--recompute-importance',
83                               nominatim_env=args, throw_on_fail=True)
84         if args.website:
85             run_legacy_script('setup.php', '--setup-website',
86                               nominatim_env=args, throw_on_fail=True)
87
88         return 0