]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/clicmd/refresh.py
Merge remote-tracking branch 'upstream/master'
[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
9 # Do not repeat documentation of subcommand classes.
10 # pylint: disable=C0111
11 # Using non-top-level imports to avoid eventually unused imports.
12 # pylint: disable=E0012,C0415
13
14 LOG = logging.getLogger()
15
16 class UpdateRefresh:
17     """\
18     Recompute auxiliary data used by the indexing process.
19
20     These functions must not be run in parallel with other update commands.
21     """
22
23     @staticmethod
24     def add_args(parser):
25         group = parser.add_argument_group('Data arguments')
26         group.add_argument('--postcodes', action='store_true',
27                            help='Update postcode centroid table')
28         group.add_argument('--word-counts', action='store_true',
29                            help='Compute frequency of full-word search terms')
30         group.add_argument('--address-levels', action='store_true',
31                            help='Reimport address level configuration')
32         group.add_argument('--functions', action='store_true',
33                            help='Update the PL/pgSQL functions in the database')
34         group.add_argument('--wiki-data', action='store_true',
35                            help='Update Wikipedia/data importance numbers.')
36         group.add_argument('--importance', action='store_true',
37                            help='Recompute place importances (expensive!)')
38         group.add_argument('--website', action='store_true',
39                            help='Refresh the directory that serves the scripts for the web API')
40         group = parser.add_argument_group('Arguments for function refresh')
41         group.add_argument('--no-diff-updates', action='store_false', dest='diffs',
42                            help='Do not enable code for propagating updates')
43         group.add_argument('--enable-debug-statements', action='store_true',
44                            help='Enable debug warning statements in functions')
45
46     @staticmethod
47     def run(args):
48         from ..tools import refresh
49
50         if args.postcodes:
51             LOG.warning("Update postcodes centroid")
52             refresh.update_postcodes(args.config.get_libpq_dsn(), args.sqllib_dir)
53
54         if args.word_counts:
55             LOG.warning('Recompute frequency of full-word search terms')
56             refresh.recompute_word_counts(args.config.get_libpq_dsn(), args.sqllib_dir)
57
58         if args.address_levels:
59             cfg = Path(args.config.ADDRESS_LEVEL_CONFIG)
60             LOG.warning('Updating address levels from %s', cfg)
61             with connect(args.config.get_libpq_dsn()) as conn:
62                 refresh.load_address_levels_from_file(conn, cfg)
63
64         if args.functions:
65             LOG.warning('Create functions')
66             with connect(args.config.get_libpq_dsn()) as conn:
67                 refresh.create_functions(conn, args.config, args.sqllib_dir,
68                                          args.diffs, args.enable_debug_statements)
69
70         if args.wiki_data:
71             data_path = Path(args.config.WIKIPEDIA_DATA_PATH
72                              or args.project_dir)
73             LOG.warning('Import wikipdia article importance from %s', data_path)
74             if refresh.import_wikipedia_articles(args.config.get_libpq_dsn(),
75                                                  data_path) > 0:
76                 LOG.fatal('FATAL: Wikipedia importance dump file not found')
77                 return 1
78
79         # Attention: importance MUST come after wiki data import.
80         if args.importance:
81             LOG.warning('Update importance values for database')
82             with connect(args.config.get_libpq_dsn()) as conn:
83                 refresh.recompute_importance(conn)
84
85         if args.website:
86             webdir = args.project_dir / 'website'
87             LOG.warning('Setting up website directory at %s', webdir)
88             refresh.setup_website(webdir, args.phplib_dir, args.config)
89
90         return 0