]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/clicmd/admin.py
040b92327ebe0d6cef743b21bf8a8c57b7eac691
[nominatim.git] / nominatim / clicmd / admin.py
1 """
2 Implementation of the 'admin' subcommand.
3 """
4 from ..tools.exec_utils import run_legacy_script
5
6 # Do not repeat documentation of subcommand classes.
7 # pylint: disable=C0111
8 # Using non-top-level imports to avoid eventually unused imports.
9 # pylint: disable=E0012,C0415
10
11 class AdminFuncs:
12     """\
13     Analyse and maintain the database.
14     """
15
16     @staticmethod
17     def add_args(parser):
18         group = parser.add_argument_group('Admin task arguments')
19         group.add_argument('--warm', action='store_true',
20                            help='Warm database caches for search and reverse queries.')
21         group.add_argument('--check-database', action='store_true',
22                            help='Check that the database is complete and operational.')
23         group = parser.add_argument_group('Arguments for cache warming')
24         group.add_argument('--search-only', action='store_const', dest='target',
25                            const='search',
26                            help="Only pre-warm tables for search queries")
27         group.add_argument('--reverse-only', action='store_const', dest='target',
28                            const='reverse',
29                            help="Only pre-warm tables for reverse queries")
30
31     @staticmethod
32     def run(args):
33         if args.warm:
34             AdminFuncs._warm(args)
35
36         if args.check_database:
37             run_legacy_script('check_import_finished.php', nominatim_env=args)
38
39         return 0
40
41
42     @staticmethod
43     def _warm(args):
44         params = ['warm.php']
45         if args.target == 'reverse':
46             params.append('--reverse-only')
47         if args.target == 'search':
48             params.append('--search-only')
49         return run_legacy_script(*params, nominatim_env=args)