X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/e14e7c6235a40dbec451146bcb3aaec013d659c9..507fdd4f40ea9a7fe77b90847d8e6e90a3cbbbd0:/nominatim/clicmd/args.py?ds=sidebyside diff --git a/nominatim/clicmd/args.py b/nominatim/clicmd/args.py index 47007579..694e6fc5 100644 --- a/nominatim/clicmd/args.py +++ b/nominatim/clicmd/args.py @@ -1,9 +1,14 @@ """ 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. """ @@ -24,4 +29,21 @@ class NominatimArgs: # pylint: disable=too-few-public-methods 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