X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/35efe3b41ceb525565c230b42d953b794d03fe5e..4e94e661b3657f8ab4e6d839729ef4346438b9f5:/nominatim/tools/tiger_data.py?ds=sidebyside diff --git a/nominatim/tools/tiger_data.py b/nominatim/tools/tiger_data.py index ffb55886..19a12682 100644 --- a/nominatim/tools/tiger_data.py +++ b/nominatim/tools/tiger_data.py @@ -7,12 +7,11 @@ import logging import os import tarfile -import psycopg2.extras - from nominatim.db.connection import connect from nominatim.db.async_connection import WorkerPool from nominatim.db.sql_preprocessor import SQLPreprocessor - +from nominatim.errors import UsageError +from nominatim.indexer.place_info import PlaceInfo LOG = logging.getLogger() @@ -23,7 +22,12 @@ def handle_tarfile_or_directory(data_dir): tar = None if data_dir.endswith('.tar.gz'): - tar = tarfile.open(data_dir) + try: + tar = tarfile.open(data_dir) + except tarfile.ReadError as err: + LOG.fatal("Cannot open '%s'. Is this a tar file?", data_dir) + raise UsageError("Cannot open Tiger data file.") from err + csv_files = [i for i in tar.getmembers() if i.name.endswith('.csv')] LOG.warning("Found %d CSV files in tarfile with path %s", len(csv_files), data_dir) if not csv_files: @@ -53,7 +57,7 @@ def handle_threaded_sql_statements(pool, fd, analyzer): address = dict(street=row['street'], postcode=row['postcode']) args = ('SRID=4326;' + row['geometry'], int(row['from']), int(row['to']), row['interpolation'], - psycopg2.extras.Json(analyzer.process_place(dict(address=address))), + PlaceInfo({'address': address}).analyze(analyzer), analyzer.normalize_postcode(row['postcode'])) except ValueError: continue