2 Implementation of the 'transition' subcommand.
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.
9 from pathlib import Path
11 from ..db.connection import connect
12 from ..errors import UsageError
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
19 LOG = logging.getLogger()
21 class AdminTransition:
23 Internal functions for code transition. Do not use.
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)')
47 from ..tools import database_import
50 LOG.warning('Create DB')
51 database_import.create_db(args.config.get_libpq_dsn())
54 LOG.warning('Setup DB')
55 mpath = database_import.install_module(args.module_dir, args.project_dir,
56 args.config.DATABASE_MODULE_PATH)
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)
62 database_import.import_base_data(args.config.get_libpq_dsn(),
63 args.data_dir, args.no_partitions)
66 LOG.warning('Import data')
68 raise UsageError('Missing required --osm-file argument')
69 database_import.import_osm_data(Path(args.osm_file),
70 args.osm2pgsql_options(0, 1),