X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/104722a56a4773eae275b25987b4d340f19d35bb..e53eb79923517a44060464d86d0803e8f0a80238:/nominatim/clicmd/args.py diff --git a/nominatim/clicmd/args.py b/nominatim/clicmd/args.py index 9be20b20..433435bc 100644 --- a/nominatim/clicmd/args.py +++ b/nominatim/clicmd/args.py @@ -10,11 +10,13 @@ Provides custom functions over command-line arguments. from typing import Optional, List, Dict, Any, Sequence, Tuple import argparse import logging +from functools import reduce from pathlib import Path from nominatim.errors import UsageError from nominatim.config import Configuration from nominatim.typing import Protocol +import nominatim.api as napi LOG = logging.getLogger() @@ -42,7 +44,6 @@ class NominatimArgs: # Basic environment set by root program. config: Configuration project_dir: Path - phpcgi_path: Path # Global switches version: bool @@ -71,6 +72,7 @@ class NominatimArgs: check_database: bool migrate: bool collect_os_info: bool + clean_deleted: str analyse_indexing: bool target: Optional[str] osm_id: Optional[str] @@ -85,6 +87,7 @@ class NominatimArgs: offline: bool ignore_errors: bool index_noanalyse: bool + prepare_database: bool # Arguments to 'index' boundaries_only: bool @@ -98,9 +101,9 @@ class NominatimArgs: 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 'convert' + output: Path # Arguments to 'refresh' postcodes: bool @@ -145,6 +148,7 @@ class NominatimArgs: # Arguments to 'search' query: Optional[str] + amenity: Optional[str] street: Optional[str] city: Optional[str] county: Optional[str] @@ -153,7 +157,7 @@ class NominatimArgs: postalcode: Optional[str] countrycodes: Optional[str] exclude_place_ids: Optional[str] - limit: Optional[int] + limit: int viewbox: Optional[str] bounded: bool dedupe: bool @@ -162,6 +166,7 @@ class NominatimArgs: lat: float lon: float zoom: Optional[int] + layers: Optional[Sequence[str]] # Arguments to 'lookup' ids: Sequence[str] @@ -211,3 +216,45 @@ class NominatimArgs: 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))