Commit 8c0b7471 authored by Kirill Smelkov's avatar Kirill Smelkov

lib/zodb: Add zmajor - way to know under which ZODB 3, 4 or 5 we are running

This will be needed in the following patches to know how to inject
zconn_at or zconn resync functionality into particular ZODB version.
parent c671aaea
......@@ -26,6 +26,8 @@ from persistent import Persistent
from weakref import WeakSet
import gc
import pkg_resources
# open db storage by uri
def dbstoropen(uri):
......@@ -135,6 +137,36 @@ def _deactivate_bucket(bucket):
bucket._p_deactivate()
# _zversion returns ZODB version object
def _zversion():
dzodb3 = pkg_resources.working_set.find(pkg_resources.Requirement.parse('ZODB3'))
dzodb = pkg_resources.working_set.find(pkg_resources.Requirement.parse('ZODB'))
v311 = pkg_resources.parse_version('3.11dev')
if dzodb3 is None and dzodb is None:
raise RuntimeError('ZODB is not installed')
if dzodb3 is not None:
if dzodb3.parsed_version >= v311:
vzodb = dzodb.parsed_version # ZODB 3.11 just requires latest ZODB & ZEO
else:
vzodb = dzodb3.parsed_version
else:
vzodb = dzodb.parsed_version
assert vzodb is not None
return vzodb
# _zmajor returns major ZODB version.
def _zmajor():
vzodb = _zversion()
# XXX hack - packaging.version.Version provides no way to extract major?
return int(vzodb.public.split('.')[0]) # 3.11.dev0 -> 3
# zmajor is set to major ZODB version.
zmajor = _zmajor()
# patch for ZODB.Connection to support callback on .open()
# NOTE on-open callbacks are setup once and fire many times on every open
# on-close callbacks are setup once and fire only once on next close
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment