]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/clicmd/transition.py
2f351be2be34bbaa2eb3910606d882f560777929
[nominatim.git] / nominatim / clicmd / transition.py
1 """
2 Implementation of the 'transition' subcommand.
3
4 This subcommand provides standins for functions that were available
5 through the PHP scripts but are now no longer directly accessible.
6 This module will be removed as soon as the transition phase is over.
7 """
8 import logging
9
10 from ..db.connection import connect
11
12 # Do not repeat documentation of subcommand classes.
13 # pylint: disable=C0111
14 # Using non-top-level imports to avoid eventually unused imports.
15 # pylint: disable=E0012,C0415
16
17 LOG = logging.getLogger()
18
19 class AdminTransition:
20     """\
21     Internal functions for code transition. Do not use.
22     """
23
24     @staticmethod
25     def add_args(parser):
26         group = parser.add_argument_group('Sub-functions')
27         group.add_argument('--create-db', action='store_true',
28                            help='Create nominatim db')
29         group.add_argument('--setup-db', action='store_true',
30                            help='Build a blank nominatim db')
31         group = parser.add_argument_group('Options')
32         group.add_argument('--no-partitions', action='store_true',
33                            help='Do not partition search indices')
34
35     @staticmethod
36     def run(args):
37         from ..tools import database_import
38
39         if args.create_db:
40             LOG.warning('Create DB')
41             database_import.create_db(args.config.get_libpq_dsn())
42
43         if args.setup_db:
44             LOG.warning('Setup DB')
45             mpath = database_import.install_module(args.module_dir, args.project_dir,
46                                                    args.config.DATABASE_MODULE_PATH)
47
48             with connect(args.config.get_libpq_dsn()) as conn:
49                 database_import.setup_extensions(conn)
50                 database_import.check_module_dir_path(conn, mpath)
51
52             database_import.import_base_data(args.config.get_libpq_dsn(),
53                                              args.data_dir, args.no_partitions)