mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-03-09 11:34:07 +00:00
bdd: use python library where possible
Replace calls to PHP scripts with direct calls into the nominatim Python library where possible. This speed up tests quite a bit.
This commit is contained in:
@@ -75,12 +75,14 @@ class CommandlineParser:
|
||||
setattr(args, arg, Path(kwargs[arg]))
|
||||
args.project_dir = Path(args.project_dir).resolve()
|
||||
|
||||
logging.basicConfig(stream=sys.stderr,
|
||||
format='%(asctime)s: %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
level=max(4 - args.verbose, 1) * 10)
|
||||
if 'cli_args' not in kwargs:
|
||||
logging.basicConfig(stream=sys.stderr,
|
||||
format='%(asctime)s: %(message)s',
|
||||
datefmt='%Y-%m-%d %H:%M:%S',
|
||||
level=max(4 - args.verbose, 1) * 10)
|
||||
|
||||
args.config = Configuration(args.project_dir, args.config_dir)
|
||||
args.config = Configuration(args.project_dir, args.config_dir,
|
||||
environ=kwargs.get('environ', os.environ))
|
||||
|
||||
log = logging.getLogger()
|
||||
log.warning('Using project directory: %s', str(args.project_dir))
|
||||
|
||||
@@ -75,7 +75,8 @@ class SetupAll:
|
||||
LOG.warning('Importing OSM data file')
|
||||
database_import.import_osm_data(Path(args.osm_file),
|
||||
args.osm2pgsql_options(0, 1),
|
||||
drop=args.no_updates)
|
||||
drop=args.no_updates,
|
||||
ignore_errors=args.ignore_errors)
|
||||
|
||||
LOG.warning('Create functions (1st pass)')
|
||||
with connect(args.config.get_libpq_dsn()) as conn:
|
||||
|
||||
@@ -48,6 +48,8 @@ class AdminTransition:
|
||||
help='Size of cache to be used by osm2pgsql (in MB)')
|
||||
group.add_argument('--no-analyse', action='store_true',
|
||||
help='Do not perform analyse operations during index')
|
||||
group.add_argument('--ignore-errors', action='store_true',
|
||||
help="Ignore certain erros on import.")
|
||||
|
||||
@staticmethod
|
||||
def run(args):
|
||||
@@ -75,7 +77,8 @@ class AdminTransition:
|
||||
raise UsageError('Missing required --osm-file argument')
|
||||
database_import.import_osm_data(Path(args.osm_file),
|
||||
args.osm2pgsql_options(0, 1),
|
||||
drop=args.drop)
|
||||
drop=args.drop,
|
||||
ignore_errors=args.ignore_errors)
|
||||
|
||||
if args.load_data:
|
||||
LOG.warning('Load data')
|
||||
|
||||
@@ -145,7 +145,7 @@ def import_base_data(dsn, sql_dir, ignore_partitions=False):
|
||||
conn.commit()
|
||||
|
||||
|
||||
def import_osm_data(osm_file, options, drop=False):
|
||||
def import_osm_data(osm_file, options, drop=False, ignore_errors=False):
|
||||
""" Import the given OSM file. 'options' contains the list of
|
||||
default settings for osm2pgsql.
|
||||
"""
|
||||
@@ -164,10 +164,11 @@ def import_osm_data(osm_file, options, drop=False):
|
||||
run_osm2pgsql(options)
|
||||
|
||||
with connect(options['dsn']) as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute('SELECT * FROM place LIMIT 1')
|
||||
if cur.rowcount == 0:
|
||||
raise UsageError('No data imported by osm2pgsql.')
|
||||
if not ignore_errors:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute('SELECT * FROM place LIMIT 1')
|
||||
if cur.rowcount == 0:
|
||||
raise UsageError('No data imported by osm2pgsql.')
|
||||
|
||||
if drop:
|
||||
conn.drop_table('planet_osm_nodes')
|
||||
|
||||
Reference in New Issue
Block a user