]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/clicmd/args.py
Merge pull request #2472 from lonvia/word-count-computation
[nominatim.git] / nominatim / clicmd / args.py
index ee1941875d56b8c1007cf6bea1d222672080fd22..694e6fc5d9c045aff8b3c12473b3dc3436d67ac7 100644 (file)
@@ -1,7 +1,12 @@
 """
 Provides custom functions over command-line arguments.
 """
 """
 Provides custom functions over command-line arguments.
 """
+import logging
+from pathlib import Path
 
 
+from nominatim.errors import UsageError
+
+LOG = logging.getLogger()
 
 class NominatimArgs:
     """ Customized namespace class for the nominatim command line tool
 
 class NominatimArgs:
     """ Customized namespace class for the nominatim command line tool
@@ -24,4 +29,21 @@ class NominatimArgs:
                                      main_data=self.config.TABLESPACE_PLACE_DATA,
                                      main_index=self.config.TABLESPACE_PLACE_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