forked from hans/Nominatim
move import-data option to native python
This adds a new dependecy to the Python psutil package.
This commit is contained in:
@@ -3,7 +3,7 @@ Provides custom functions over command-line arguments.
|
||||
"""
|
||||
|
||||
|
||||
class NominatimArgs:
|
||||
class NominatimArgs: # pylint: disable=too-few-public-methods
|
||||
""" Customized namespace class for the nominatim command line tool
|
||||
to receive the command-line arguments.
|
||||
"""
|
||||
@@ -18,5 +18,10 @@ class NominatimArgs:
|
||||
osm2pgsql_style=self.config.get_import_style_file(),
|
||||
threads=self.threads or default_threads,
|
||||
dsn=self.config.get_libpq_dsn(),
|
||||
flatnode_file=self.config.FLATNODE_FILE)
|
||||
|
||||
flatnode_file=self.config.FLATNODE_FILE,
|
||||
tablespaces=dict(slim_data=self.config.TABLESPACE_OSM_DATA,
|
||||
slim_index=self.config.TABLESPACE_OSM_INDEX,
|
||||
main_data=self.config.TABLESPACE_PLACE_DATA,
|
||||
main_index=self.config.TABLESPACE_PLACE_INDEX
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Implementation of the 'index' subcommand.
|
||||
"""
|
||||
import os
|
||||
import psutil
|
||||
|
||||
from ..db import status
|
||||
from ..db.connection import connect
|
||||
@@ -11,14 +11,6 @@ from ..db.connection import connect
|
||||
# Using non-top-level imports to avoid eventually unused imports.
|
||||
# pylint: disable=E0012,C0415
|
||||
|
||||
def _num_system_cpus():
|
||||
try:
|
||||
cpus = len(os.sched_getaffinity(0))
|
||||
except NotImplementedError:
|
||||
cpus = None
|
||||
|
||||
return cpus or os.cpu_count()
|
||||
|
||||
|
||||
class UpdateIndex:
|
||||
"""\
|
||||
@@ -42,7 +34,7 @@ class UpdateIndex:
|
||||
from ..indexer.indexer import Indexer
|
||||
|
||||
indexer = Indexer(args.config.get_libpq_dsn(),
|
||||
args.threads or _num_system_cpus() or 1)
|
||||
args.threads or psutil.cpu_count() or 1)
|
||||
|
||||
if not args.no_boundaries:
|
||||
indexer.index_boundaries(args.minrank, args.maxrank)
|
||||
|
||||
@@ -6,8 +6,10 @@ through the PHP scripts but are now no longer directly accessible.
|
||||
This module will be removed as soon as the transition phase is over.
|
||||
"""
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from ..db.connection import connect
|
||||
from ..errors import UsageError
|
||||
|
||||
# Do not repeat documentation of subcommand classes.
|
||||
# pylint: disable=C0111
|
||||
@@ -28,9 +30,17 @@ class AdminTransition:
|
||||
help='Create nominatim db')
|
||||
group.add_argument('--setup-db', action='store_true',
|
||||
help='Build a blank nominatim db')
|
||||
group.add_argument('--import-data', action='store_true',
|
||||
help='Import a osm file')
|
||||
group = parser.add_argument_group('Options')
|
||||
group.add_argument('--no-partitions', action='store_true',
|
||||
help='Do not partition search indices')
|
||||
group.add_argument('--osm-file', metavar='FILE',
|
||||
help='File to import')
|
||||
group.add_argument('--drop', action='store_true',
|
||||
help='Drop tables needed for updates, making the database readonly')
|
||||
group.add_argument('--osm2pgsql-cache', metavar='SIZE', type=int,
|
||||
help='Size of cache to be used by osm2pgsql (in MB)')
|
||||
|
||||
@staticmethod
|
||||
def run(args):
|
||||
@@ -51,3 +61,11 @@ class AdminTransition:
|
||||
|
||||
database_import.import_base_data(args.config.get_libpq_dsn(),
|
||||
args.data_dir, args.no_partitions)
|
||||
|
||||
if args.import_data:
|
||||
LOG.warning('Import data')
|
||||
if not args.osm_file:
|
||||
raise UsageError('Missing required --osm-file argument')
|
||||
database_import.import_osm_data(Path(args.osm_file),
|
||||
args.osm2pgsql_options(0, 1),
|
||||
drop=args.drop)
|
||||
|
||||
Reference in New Issue
Block a user