]> git.openstreetmap.org Git - nominatim.git/blobdiff - nominatim/clicmd/args.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / nominatim / clicmd / args.py
index f5f1b98eb26c0a29a3a32712ee7e63a0e2224cad..8b805496fffd750bec95f9e25303e17c5eca6305 100644 (file)
@@ -10,12 +10,13 @@ Provides custom functions over command-line arguments.
 from typing import Optional, List, Dict, Any, Sequence, Tuple
 import argparse
 import logging
 from typing import Optional, List, Dict, Any, Sequence, Tuple
 import argparse
 import logging
+from functools import reduce
 from pathlib import Path
 
 from pathlib import Path
 
-from typing_extensions import Protocol
-
 from nominatim.errors import UsageError
 from nominatim.config import Configuration
 from nominatim.errors import UsageError
 from nominatim.config import Configuration
+from nominatim.typing import Protocol
+import nominatim.api as napi
 
 LOG = logging.getLogger()
 
 
 LOG = logging.getLogger()
 
@@ -43,13 +44,6 @@ class NominatimArgs:
     # Basic environment set by root program.
     config: Configuration
     project_dir: Path
     # Basic environment set by root program.
     config: Configuration
     project_dir: Path
-    module_dir: Path
-    osm2pgsql_path: Path
-    phplib_dir: Path
-    sqllib_dir: Path
-    data_dir: Path
-    config_dir: Path
-    phpcgi_path: Path
 
     # Global switches
     version: bool
 
     # Global switches
     version: bool
@@ -77,6 +71,7 @@ class NominatimArgs:
     warm: bool
     check_database: bool
     migrate: bool
     warm: bool
     check_database: bool
     migrate: bool
+    collect_os_info: bool
     analyse_indexing: bool
     target: Optional[str]
     osm_id: Optional[str]
     analyse_indexing: bool
     target: Optional[str]
     osm_id: Optional[str]
@@ -104,9 +99,6 @@ class NominatimArgs:
     output_all_postcodes: bool
     language: Optional[str]
     restrict_to_country: Optional[str]
     output_all_postcodes: bool
     language: Optional[str]
     restrict_to_country: Optional[str]
-    restrict_to_osm_node: Optional[int]
-    restrict_to_osm_way: Optional[int]
-    restrict_to_osm_relation: Optional[int]
 
     # Arguments to 'refresh'
     postcodes: bool
 
     # Arguments to 'refresh'
     postcodes: bool
@@ -115,6 +107,7 @@ class NominatimArgs:
     address_levels: bool
     functions: bool
     wiki_data: bool
     address_levels: bool
     functions: bool
     wiki_data: bool
+    secondary_importance: bool
     importance: bool
     website: bool
     diffs: bool
     importance: bool
     website: bool
     diffs: bool
@@ -132,6 +125,7 @@ class NominatimArgs:
 
     # Arguments to 'serve'
     server: str
 
     # Arguments to 'serve'
     server: str
+    engine: str
 
     # Arguments to 'special-phrases
     import_from_wiki: bool
 
     # Arguments to 'special-phrases
     import_from_wiki: bool
@@ -149,6 +143,7 @@ class NominatimArgs:
 
     # Arguments to 'search'
     query: Optional[str]
 
     # Arguments to 'search'
     query: Optional[str]
+    amenity: Optional[str]
     street: Optional[str]
     city: Optional[str]
     county: Optional[str]
     street: Optional[str]
     city: Optional[str]
     county: Optional[str]
@@ -157,7 +152,7 @@ class NominatimArgs:
     postalcode: Optional[str]
     countrycodes: Optional[str]
     exclude_place_ids: Optional[str]
     postalcode: Optional[str]
     countrycodes: Optional[str]
     exclude_place_ids: Optional[str]
-    limit: Optional[int]
+    limit: int
     viewbox: Optional[str]
     bounded: bool
     dedupe: bool
     viewbox: Optional[str]
     bounded: bool
     dedupe: bool
@@ -166,12 +161,18 @@ class NominatimArgs:
     lat: float
     lon: float
     zoom: Optional[int]
     lat: float
     lon: float
     zoom: Optional[int]
+    layers: Optional[Sequence[str]]
 
     # Arguments to 'lookup'
     ids: Sequence[str]
 
     # Arguments to 'details'
     object_class: Optional[str]
 
     # Arguments to 'lookup'
     ids: Sequence[str]
 
     # Arguments to 'details'
     object_class: Optional[str]
+    linkedplaces: bool
+    hierarchy: bool
+    keywords: bool
+    polygon_geojson: bool
+    group_hierarchy: bool
 
 
     def osm2pgsql_options(self, default_cache: int,
 
 
     def osm2pgsql_options(self, default_cache: int,
@@ -180,9 +181,10 @@ class NominatimArgs:
             from the command line arguments. The resulting dict can be
             further customized and then used in `run_osm2pgsql()`.
         """
             from the command line arguments. The resulting dict can be
             further customized and then used in `run_osm2pgsql()`.
         """
-        return dict(osm2pgsql=self.config.OSM2PGSQL_BINARY or self.osm2pgsql_path,
+        return dict(osm2pgsql=self.config.OSM2PGSQL_BINARY or self.config.lib_dir.osm2pgsql,
                     osm2pgsql_cache=self.osm2pgsql_cache or default_cache,
                     osm2pgsql_style=self.config.get_import_style_file(),
                     osm2pgsql_cache=self.osm2pgsql_cache or default_cache,
                     osm2pgsql_style=self.config.get_import_style_file(),
+                    osm2pgsql_style_path=self.config.config_dir,
                     threads=self.threads or default_threads,
                     dsn=self.config.get_libpq_dsn(),
                     flatnode_file=str(self.config.get_path('FLATNODE_FILE') or ''),
                     threads=self.threads or default_threads,
                     dsn=self.config.get_libpq_dsn(),
                     flatnode_file=str(self.config.get_path('FLATNODE_FILE') or ''),
@@ -209,3 +211,45 @@ class NominatimArgs:
                 raise UsageError('Cannot access file.')
 
         return files
                 raise UsageError('Cannot access file.')
 
         return files
+
+
+    def get_geometry_output(self) -> napi.GeometryFormat:
+        """ Get the requested geometry output format in a API-compatible
+            format.
+        """
+        if not self.polygon_output:
+            return napi.GeometryFormat.NONE
+        if self.polygon_output == 'geojson':
+            return napi.GeometryFormat.GEOJSON
+        if self.polygon_output == 'kml':
+            return napi.GeometryFormat.KML
+        if self.polygon_output == 'svg':
+            return napi.GeometryFormat.SVG
+        if self.polygon_output == 'text':
+            return napi.GeometryFormat.TEXT
+
+        try:
+            return napi.GeometryFormat[self.polygon_output.upper()]
+        except KeyError as exp:
+            raise UsageError(f"Unknown polygon output format '{self.polygon_output}'.") from exp
+
+
+    def get_locales(self, default: Optional[str]) -> napi.Locales:
+        """ Get the locales from the language parameter.
+        """
+        if self.lang:
+            return napi.Locales.from_accept_languages(self.lang)
+        if default:
+            return napi.Locales.from_accept_languages(default)
+
+        return napi.Locales()
+
+
+    def get_layers(self, default: napi.DataLayer) -> Optional[napi.DataLayer]:
+        """ Get the list of selected layers as a DataLayer enum.
+        """
+        if not self.layers:
+            return default
+
+        return reduce(napi.DataLayer.__or__,
+                      (napi.DataLayer[s.upper()] for s in self.layers))