]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/clicmd/transition.py
move import-data option to native python
[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 from pathlib import Path
10
11 from ..db.connection import connect
12 from ..errors import UsageError
13
14 # Do not repeat documentation of subcommand classes.
15 # pylint: disable=C0111
16 # Using non-top-level imports to avoid eventually unused imports.
17 # pylint: disable=E0012,C0415
18
19 LOG = logging.getLogger()
20
21 class AdminTransition:
22     """\
23     Internal functions for code transition. Do not use.
24     """
25
26     @staticmethod
27     def add_args(parser):
28         group = parser.add_argument_group('Sub-functions')
29         group.add_argument('--create-db', action='store_true',
30                            help='Create nominatim db')
31         group.add_argument('--setup-db', action='store_true',
32                            help='Build a blank nominatim db')
33         group.add_argument('--import-data', action='store_true',
34                            help='Import a osm file')
35         group = parser.add_argument_group('Options')
36         group.add_argument('--no-partitions', action='store_true',
37                            help='Do not partition search indices')
38         group.add_argument('--osm-file', metavar='FILE',
39                            help='File to import')
40         group.add_argument('--drop', action='store_true',
41                            help='Drop tables needed for updates, making the database readonly')
42         group.add_argument('--osm2pgsql-cache', metavar='SIZE', type=int,
43                            help='Size of cache to be used by osm2pgsql (in MB)')
44
45     @staticmethod
46     def run(args):
47         from ..tools import database_import
48
49         if args.create_db:
50             LOG.warning('Create DB')
51             database_import.create_db(args.config.get_libpq_dsn())
52
53         if args.setup_db:
54             LOG.warning('Setup DB')
55             mpath = database_import.install_module(args.module_dir, args.project_dir,
56                                                    args.config.DATABASE_MODULE_PATH)
57
58             with connect(args.config.get_libpq_dsn()) as conn:
59                 database_import.setup_extensions(conn)
60                 database_import.check_module_dir_path(conn, mpath)
61
62             database_import.import_base_data(args.config.get_libpq_dsn(),
63                                              args.data_dir, args.no_partitions)
64
65         if args.import_data:
66             LOG.warning('Import data')
67             if not args.osm_file:
68                 raise UsageError('Missing required --osm-file argument')
69             database_import.import_osm_data(Path(args.osm_file),
70                                             args.osm2pgsql_options(0, 1),
71                                             drop=args.drop)