]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/clicmd/args.py
Vagrant and CI tests for Ubuntu 22.04
[nominatim.git] / nominatim / clicmd / args.py
index 47007579f6f69cf1a97edac668c8646ed2046d40..d1f47ba00b4a41eb34aaa852d23cbbc5e9b4aca7 100644 (file)
@@ -1,9 +1,20 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# This file is part of Nominatim. (https://nominatim.org)
+#
+# Copyright (C) 2022 by the Nominatim developer community.
+# For a full list of authors see the git log.
 """
 Provides custom functions over command-line arguments.
 """
+import logging
+from pathlib import Path
 
+from nominatim.errors import UsageError
 
-class NominatimArgs: # pylint: disable=too-few-public-methods
+LOG = logging.getLogger()
+
+class NominatimArgs:
     """ Customized namespace class for the nominatim command line tool
         to receive the command-line arguments.
     """
@@ -18,10 +29,27 @@ class NominatimArgs: # pylint: disable=too-few-public-methods
                     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=str(self.config.get_path('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
                                     )
-                    )
+                   )
+
+
+    def get_osm_file_list(self):
+        """ Return the --osm-file argument as a list of Paths or None
+            if no argument was given. The function also checks if the files
+            exist and raises a UsageError if one cannot be found.
+        """
+        if not self.osm_file:
+            return None
+
+        files = [Path(f) for f in self.osm_file]
+        for fname in files:
+            if not fname.is_file():
+                LOG.fatal("OSM file '%s' does not exist.", fname)
+                raise UsageError('Cannot access file.')
+
+        return files