1 # SPDX-License-Identifier: GPL-2.0-only
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2022 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Provides custom functions over command-line arguments.
 
  11 from pathlib import Path
 
  13 from nominatim.errors import UsageError
 
  15 LOG = logging.getLogger()
 
  18     """ Customized namespace class for the nominatim command line tool
 
  19         to receive the command-line arguments.
 
  22     def osm2pgsql_options(self, default_cache, default_threads):
 
  23         """ Return the standard osm2pgsql options that can be derived
 
  24             from the command line arguments. The resulting dict can be
 
  25             further customized and then used in `run_osm2pgsql()`.
 
  27         return dict(osm2pgsql=self.config.OSM2PGSQL_BINARY or self.osm2pgsql_path,
 
  28                     osm2pgsql_cache=self.osm2pgsql_cache or default_cache,
 
  29                     osm2pgsql_style=self.config.get_import_style_file(),
 
  30                     threads=self.threads or default_threads,
 
  31                     dsn=self.config.get_libpq_dsn(),
 
  32                     flatnode_file=str(self.config.get_path('FLATNODE_FILE')),
 
  33                     tablespaces=dict(slim_data=self.config.TABLESPACE_OSM_DATA,
 
  34                                      slim_index=self.config.TABLESPACE_OSM_INDEX,
 
  35                                      main_data=self.config.TABLESPACE_PLACE_DATA,
 
  36                                      main_index=self.config.TABLESPACE_PLACE_INDEX
 
  41     def get_osm_file_list(self):
 
  42         """ Return the --osm-file argument as a list of Paths or None
 
  43             if no argument was given. The function also checks if the files
 
  44             exist and raises a UsageError if one cannot be found.
 
  49         files = [Path(f) for f in self.osm_file]
 
  51             if not fname.is_file():
 
  52                 LOG.fatal("OSM file '%s' does not exist.", fname)
 
  53                 raise UsageError('Cannot access file.')