mirror of
https://github.com/osm-search/Nominatim.git
synced 2026-02-16 15:47:58 +00:00
add a function to return a formatted version
Replaces the various repeated format strings throughout the code.
This commit is contained in:
@@ -11,6 +11,6 @@ ignored-modules=icu,datrie
|
|||||||
# 'with' statements.
|
# 'with' statements.
|
||||||
ignored-classes=NominatimArgs,closing
|
ignored-classes=NominatimArgs,closing
|
||||||
# 'too-many-ancestors' is triggered already by deriving from UserDict
|
# 'too-many-ancestors' is triggered already by deriving from UserDict
|
||||||
disable=too-few-public-methods,duplicate-code,too-many-ancestors
|
disable=too-few-public-methods,duplicate-code,too-many-ancestors,bad-option-value
|
||||||
|
|
||||||
good-names=i,x,y,fd,db
|
good-names=i,x,y,fd,db
|
||||||
|
|||||||
@@ -60,9 +60,9 @@ class CommandlineParser:
|
|||||||
def nominatim_version_text():
|
def nominatim_version_text():
|
||||||
""" Program name and version number as string
|
""" Program name and version number as string
|
||||||
"""
|
"""
|
||||||
text = 'Nominatim version %s.%s.%s.%s' % version.NOMINATIM_VERSION
|
text = f'Nominatim version {version.version_str()}'
|
||||||
if version.GIT_COMMIT_HASH is not None:
|
if version.GIT_COMMIT_HASH is not None:
|
||||||
text += ' (%s)' % version.GIT_COMMIT_HASH
|
text += f' ({version.GIT_COMMIT_HASH})'
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def add_subcommand(self, name, cmd):
|
def add_subcommand(self, name, cmd):
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import psutil
|
|||||||
|
|
||||||
from nominatim.db.connection import connect
|
from nominatim.db.connection import connect
|
||||||
from nominatim.db import status, properties
|
from nominatim.db import status, properties
|
||||||
from nominatim.version import NOMINATIM_VERSION
|
from nominatim.version import version_str
|
||||||
|
|
||||||
# Do not repeat documentation of subcommand classes.
|
# Do not repeat documentation of subcommand classes.
|
||||||
# pylint: disable=C0111
|
# pylint: disable=C0111
|
||||||
@@ -213,5 +213,4 @@ class SetupAll:
|
|||||||
except Exception as exc: # pylint: disable=broad-except
|
except Exception as exc: # pylint: disable=broad-except
|
||||||
LOG.error('Cannot determine date of database: %s', exc)
|
LOG.error('Cannot determine date of database: %s', exc)
|
||||||
|
|
||||||
properties.set_property(conn, 'database_version',
|
properties.set_property(conn, 'database_version', version_str())
|
||||||
'{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(NOMINATIM_VERSION))
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import subprocess
|
|||||||
import urllib.request as urlrequest
|
import urllib.request as urlrequest
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
from nominatim.version import NOMINATIM_VERSION
|
from nominatim.version import version_str
|
||||||
from nominatim.db.connection import get_pg_env
|
from nominatim.db.connection import get_pg_env
|
||||||
|
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
@@ -150,7 +150,7 @@ def run_osm2pgsql(options):
|
|||||||
def get_url(url):
|
def get_url(url):
|
||||||
""" Get the contents from the given URL and return it as a UTF-8 string.
|
""" Get the contents from the given URL and return it as a UTF-8 string.
|
||||||
"""
|
"""
|
||||||
headers = {"User-Agent": "Nominatim/{0[0]}.{0[1]}.{0[2]}-{0[3]}".format(NOMINATIM_VERSION)}
|
headers = {"User-Agent": f"Nominatim/{version_str()}"}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with urlrequest.urlopen(urlrequest.Request(url, headers=headers)) as response:
|
with urlrequest.urlopen(urlrequest.Request(url, headers=headers)) as response:
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import logging
|
|||||||
|
|
||||||
from nominatim.db import properties
|
from nominatim.db import properties
|
||||||
from nominatim.db.connection import connect
|
from nominatim.db.connection import connect
|
||||||
from nominatim.version import NOMINATIM_VERSION
|
from nominatim.version import NOMINATIM_VERSION, version_str
|
||||||
from nominatim.tools import refresh
|
from nominatim.tools import refresh
|
||||||
from nominatim.tokenizer import factory as tokenizer_factory
|
from nominatim.tokenizer import factory as tokenizer_factory
|
||||||
from nominatim.errors import UsageError
|
from nominatim.errors import UsageError
|
||||||
@@ -47,7 +47,7 @@ def migrate(config, paths):
|
|||||||
for version, func in _MIGRATION_FUNCTIONS:
|
for version, func in _MIGRATION_FUNCTIONS:
|
||||||
if db_version <= version:
|
if db_version <= version:
|
||||||
LOG.warning("Runnning: %s (%s)", func.__doc__.split('\n', 1)[0],
|
LOG.warning("Runnning: %s (%s)", func.__doc__.split('\n', 1)[0],
|
||||||
'{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(version))
|
'{}.{}.{}-{}'.format(*version))
|
||||||
kwargs = dict(conn=conn, config=config, paths=paths)
|
kwargs = dict(conn=conn, config=config, paths=paths)
|
||||||
func(**kwargs)
|
func(**kwargs)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@@ -59,8 +59,7 @@ def migrate(config, paths):
|
|||||||
tokenizer = tokenizer_factory.get_tokenizer_for_db(config)
|
tokenizer = tokenizer_factory.get_tokenizer_for_db(config)
|
||||||
tokenizer.update_sql_functions(config)
|
tokenizer.update_sql_functions(config)
|
||||||
|
|
||||||
properties.set_property(conn, 'database_version',
|
properties.set_property(conn, 'database_version', version_str())
|
||||||
'{0[0]}.{0[1]}.{0[2]}-{0[3]}'.format(NOMINATIM_VERSION))
|
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from psycopg2 import sql as pysql
|
|||||||
|
|
||||||
from nominatim.db.utils import execute_file
|
from nominatim.db.utils import execute_file
|
||||||
from nominatim.db.sql_preprocessor import SQLPreprocessor
|
from nominatim.db.sql_preprocessor import SQLPreprocessor
|
||||||
from nominatim.version import NOMINATIM_VERSION
|
from nominatim.version import version_str
|
||||||
|
|
||||||
LOG = logging.getLogger()
|
LOG = logging.getLogger()
|
||||||
|
|
||||||
@@ -186,16 +186,15 @@ def setup_website(basedir, config, conn):
|
|||||||
LOG.info('Creating website directory.')
|
LOG.info('Creating website directory.')
|
||||||
basedir.mkdir()
|
basedir.mkdir()
|
||||||
|
|
||||||
template = dedent("""\
|
template = dedent(f"""\
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
@define('CONST_Debug', $_GET['debug'] ?? false);
|
@define('CONST_Debug', $_GET['debug'] ?? false);
|
||||||
@define('CONST_LibDir', '{0}');
|
@define('CONST_LibDir', '{config.lib_dir.php}');
|
||||||
@define('CONST_TokenizerDir', '{2}');
|
@define('CONST_TokenizerDir', '{config.project_dir / 'tokenizer'}');
|
||||||
@define('CONST_NominatimVersion', '{1[0]}.{1[1]}.{1[2]}-{1[3]}');
|
@define('CONST_NominatimVersion', '{version_str()}');
|
||||||
|
|
||||||
""".format(config.lib_dir.php, NOMINATIM_VERSION,
|
""")
|
||||||
config.project_dir / 'tokenizer'))
|
|
||||||
|
|
||||||
for php_name, conf_name, var_type in PHP_CONST_DEFS:
|
for php_name, conf_name, var_type in PHP_CONST_DEFS:
|
||||||
varout = _quote_php_variable(var_type, config, conf_name)
|
varout = _quote_php_variable(var_type, config, conf_name)
|
||||||
|
|||||||
@@ -34,3 +34,11 @@ POSTGIS_REQUIRED_VERSION = (2, 2)
|
|||||||
# cmake/tool-installed.tmpl is used to build the binary 'nominatim'. Inside
|
# cmake/tool-installed.tmpl is used to build the binary 'nominatim'. Inside
|
||||||
# there is a call to set the variable value below.
|
# there is a call to set the variable value below.
|
||||||
GIT_COMMIT_HASH = None
|
GIT_COMMIT_HASH = None
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=consider-using-f-string
|
||||||
|
def version_str():
|
||||||
|
"""
|
||||||
|
Return a human-readable string of the version.
|
||||||
|
"""
|
||||||
|
return '{}.{}.{}-{}'.format(*NOMINATIM_VERSION)
|
||||||
|
|||||||
Reference in New Issue
Block a user