]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/clicmd/args.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / nominatim / clicmd / args.py
1 """
2 Provides custom functions over command-line arguments.
3 """
4 import logging
5 from pathlib import Path
6
7 from nominatim.errors import UsageError
8
9 LOG = logging.getLogger()
10
11 class NominatimArgs:
12     """ Customized namespace class for the nominatim command line tool
13         to receive the command-line arguments.
14     """
15
16     def osm2pgsql_options(self, default_cache, default_threads):
17         """ Return the standard osm2pgsql options that can be derived
18             from the command line arguments. The resulting dict can be
19             further customized and then used in `run_osm2pgsql()`.
20         """
21         return dict(osm2pgsql=self.config.OSM2PGSQL_BINARY or self.osm2pgsql_path,
22                     osm2pgsql_cache=self.osm2pgsql_cache or default_cache,
23                     osm2pgsql_style=self.config.get_import_style_file(),
24                     threads=self.threads or default_threads,
25                     dsn=self.config.get_libpq_dsn(),
26                     flatnode_file=str(self.config.get_path('FLATNODE_FILE')),
27                     tablespaces=dict(slim_data=self.config.TABLESPACE_OSM_DATA,
28                                      slim_index=self.config.TABLESPACE_OSM_INDEX,
29                                      main_data=self.config.TABLESPACE_PLACE_DATA,
30                                      main_index=self.config.TABLESPACE_PLACE_INDEX
31                                     )
32                    )
33
34
35     def get_osm_file_list(self):
36         """ Return the --osm-file argument as a list of Paths or None
37             if no argument was given. The function also checks if the files
38             exist and raises a UsageError if one cannot be found.
39         """
40         if not self.osm_file:
41             return None
42
43         files = [Path(f) for f in self.osm_file]
44         for fname in files:
45             if not fname.is_file():
46                 LOG.fatal("OSM file '%s' does not exist.", fname)
47                 raise UsageError('Cannot access file.')
48
49         return files