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.add_argument('--index', action='store_true',
36 help='Index the data')
37 group = parser.add_argument_group('Options')
38 group.add_argument('--no-partitions', action='store_true',
39 help='Do not partition search indices')
40 group.add_argument('--osm-file', metavar='FILE',
41 help='File to import')
42 group.add_argument('--drop', action='store_true',
43 help='Drop tables needed for updates, making the database readonly')
44 group.add_argument('--osm2pgsql-cache', metavar='SIZE', type=int,
45 help='Size of cache to be used by osm2pgsql (in MB)')
46 group.add_argument('--no-analyse', action='store_true',
47 help='Do not perform analyse operations during index')
51 from ..tools import database_import
54 LOG.warning('Create DB')
55 database_import.create_db(args.config.get_libpq_dsn())
58 LOG.warning('Setup DB')
59 mpath = database_import.install_module(args.module_dir, args.project_dir,
60 args.config.DATABASE_MODULE_PATH)
62 with connect(args.config.get_libpq_dsn()) as conn:
63 database_import.setup_extensions(conn)
64 database_import.check_module_dir_path(conn, mpath)
66 database_import.import_base_data(args.config.get_libpq_dsn(),
67 args.data_dir, args.no_partitions)
70 LOG.warning('Import data')
72 raise UsageError('Missing required --osm-file argument')
73 database_import.import_osm_data(Path(args.osm_file),
74 args.osm2pgsql_options(0, 1),
78 LOG.warning('Indexing')
79 from ..indexer.indexer import Indexer
80 indexer = Indexer(args.config.get_libpq_dsn(), args.threads or 1)