]> git.openstreetmap.org Git - nominatim.git/blobdiff - src/nominatim_db/clicmd/add_data.py
work round typing bug in pyosmium 4.0
[nominatim.git] / src / nominatim_db / clicmd / add_data.py
index eced99070ba0c42aa2322111d310b103a3876f8e..e2058b74099e4ad69a26945341c6eb35815eeded 100644 (file)
@@ -10,10 +10,13 @@ Implementation of the 'add-data' subcommand.
 from typing import cast
 import argparse
 import logging
+import asyncio
 
 import psutil
 
 from .args import NominatimArgs
+from ..db.connection import connect
+from ..tools.freeze import is_frozen
 
 # Do not repeat documentation of subcommand classes.
 # pylint: disable=C0111
@@ -35,7 +38,7 @@ class UpdateAddData:
     The command can also be used to add external non-OSM data to the
     database. At the moment the only supported format is TIGER housenumber
     data. See the online documentation at
-    https://nominatim.org/release-docs/latest/admin/Import/#installing-tiger-housenumber-data-for-the-us
+    https://nominatim.org/release-docs/latest/customize/Tiger/
     for more information.
     """
 
@@ -64,15 +67,15 @@ class UpdateAddData:
 
 
     def run(self, args: NominatimArgs) -> int:
-        from ..tokenizer import factory as tokenizer_factory
-        from ..tools import tiger_data, add_osm_data
+        from ..tools import add_osm_data
+
+        with connect(args.config.get_libpq_dsn()) as conn:
+            if is_frozen(conn):
+                print('Database is marked frozen. New data can\'t be added.')
+                return 1
 
         if args.tiger_data:
-            tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
-            return tiger_data.add_tiger_data(args.tiger_data,
-                                             args.config,
-                                             args.threads or psutil.cpu_count()  or 1,
-                                             tokenizer)
+            return asyncio.run(self._add_tiger_data(args))
 
         osm2pgsql_params = args.osm2pgsql_options(default_cache=1000, default_threads=1)
         if args.file or args.diff:
@@ -99,3 +102,16 @@ class UpdateAddData:
                                                osm2pgsql_params)
 
         return 0
+
+
+    async def _add_tiger_data(self, args: NominatimArgs) -> int:
+        from ..tokenizer import factory as tokenizer_factory
+        from ..tools import tiger_data
+
+        assert args.tiger_data
+
+        tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
+        return await tiger_data.add_tiger_data(args.tiger_data,
+                                               args.config,
+                                               args.threads or psutil.cpu_count()  or 1,
+                                               tokenizer)