X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c314a3092c5b51c7782015f6fa9ac093b46fa174..57598a048e9124b905572ed8dc4fa9465b5d38a6:/src/nominatim_db/tools/replication.py diff --git a/src/nominatim_db/tools/replication.py b/src/nominatim_db/tools/replication.py index bf1189df..e50eedee 100644 --- a/src/nominatim_db/tools/replication.py +++ b/src/nominatim_db/tools/replication.py @@ -16,8 +16,6 @@ import time import types import urllib.request as urlrequest -import requests - from ..errors import UsageError from ..db import status from ..db.connection import Connection, connect @@ -27,13 +25,15 @@ try: from osmium.replication.server import ReplicationServer from osmium import WriteHandler from osmium import version as pyo_version -except ImportError as exc: + import requests +except ModuleNotFoundError as exc: logging.getLogger().critical("pyosmium not installed. Replication functions not available.\n" - "To install pyosmium via pip: pip3 install osmium") + "To install pyosmium via pip: pip install osmium") raise UsageError("replication tools not available") from exc LOG = logging.getLogger() + def init_replication(conn: Connection, base_url: str, socket_timeout: int = 60) -> None: """ Set up replication for the server at the given base URL. @@ -84,6 +84,7 @@ def check_for_updates(conn: Connection, base_url: str, LOG.warning("New data available (%i => %i).", seq, state.sequence) return 0 + class UpdateState(Enum): """ Possible states after an update has run. """ @@ -155,7 +156,7 @@ def run_osm2pgsql_updates(conn: Connection, options: MutableMapping[str, Any]) - # Consume updates with osm2pgsql. options['append'] = True - options['disable_jit'] = conn.server_version_tuple() >= (11, 0) + options['disable_jit'] = True run_osm2pgsql(options) # Handle deletions @@ -177,12 +178,12 @@ def _make_replication_server(url: str, timeout: int) -> ContextManager[Replicati """ Download a resource from the given URL and return a byte sequence of the content. """ - headers = {"User-Agent" : f"Nominatim (pyosmium/{pyo_version.pyosmium_release})"} + headers = {"User-Agent": f"Nominatim (pyosmium/{pyo_version.pyosmium_release})"} if self.session is not None: return self.session.get(url.get_full_url(), - headers=headers, timeout=timeout or None, - stream=True) + headers=headers, timeout=timeout or None, + stream=True) @contextmanager def _get_url_with_session() -> Iterator[requests.Response]: