X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/49f889bf09f78f7f475cf64ed4b06be9e00247ca..a234d606c9dcd76db1d69909bb78940d3dbcd862:/nominatim/tools/collect_os_info.py diff --git a/nominatim/tools/collect_os_info.py b/nominatim/tools/collect_os_info.py index 9d76f229..779c55c7 100644 --- a/nominatim/tools/collect_os_info.py +++ b/nominatim/tools/collect_os_info.py @@ -12,15 +12,14 @@ import os import subprocess import sys from pathlib import Path -from typing import List, Optional, Tuple, Union, cast +from typing import List, Optional, Tuple, Union import psutil from psycopg2.extensions import make_dsn, parse_dsn from nominatim.config import Configuration from nominatim.db.connection import connect -from nominatim.typing import DictCursorResults -from nominatim.version import version_str +from nominatim.version import NOMINATIM_VERSION def convert_version(ver_tup: Tuple[int, int]) -> str: @@ -79,7 +78,7 @@ def from_file_find_line_portion( filename: str, start: str, sep: str, fieldnum: int = 1 ) -> Optional[str]: """open filename, finds the line starting with the 'start' string. - Splits the line using seperator and returns a "fieldnum" from the split.""" + Splits the line using separator and returns a "fieldnum" from the split.""" with open(filename, encoding='utf8') as file: result = "" for line in file: @@ -107,15 +106,15 @@ def report_system_information(config: Configuration) -> None: postgresql_ver: str = convert_version(conn.server_version_tuple()) with conn.cursor() as cur: - cur.execute(f""" - SELECT datname FROM pg_catalog.pg_database - WHERE datname='{parse_dsn(config.get_libpq_dsn())['dbname']}'""") - nominatim_db_exists = cast(Optional[DictCursorResults], cur.fetchall()) - if nominatim_db_exists: - with connect(config.get_libpq_dsn()) as conn: - postgis_ver: str = convert_version(conn.postgis_version_tuple()) - else: - postgis_ver = "Unable to connect to database" + num = cur.scalar("SELECT count(*) FROM pg_catalog.pg_database WHERE datname=%s", + (parse_dsn(config.get_libpq_dsn())['dbname'], )) + nominatim_db_exists = num == 1 if isinstance(num, int) else False + + if nominatim_db_exists: + with connect(config.get_libpq_dsn()) as conn: + postgis_ver: str = convert_version(conn.postgis_version_tuple()) + else: + postgis_ver = "Unable to connect to database" postgresql_config: str = get_postgresql_config(int(float(postgresql_ver))) @@ -135,8 +134,8 @@ def report_system_information(config: Configuration) -> None: **Software Environment:** - Python version: {sys.version} - - Nominatim version: {version_str()} - - PostgreSQL version: {postgresql_ver} + - Nominatim version: {NOMINATIM_VERSION!s} + - PostgreSQL version: {postgresql_ver} - PostGIS version: {postgis_ver} - OS: {os_name_info()}