src/ztfy/utils/zodb.py
branchZTK-1.1
changeset 277 35f11f1758e9
parent 242 ffa98c18e909
--- a/src/ztfy/utils/zodb.py	Thu Jun 04 15:50:36 2020 +0200
+++ b/src/ztfy/utils/zodb.py	Sat Jan 15 00:23:22 2022 +0100
@@ -30,6 +30,7 @@
 # import Zope3 packages
 from ZEO import ClientStorage
 from ZODB import DB
+from ZODB.config import databaseFromURL
 from zope.component import adapter
 from zope.componentvocabulary.vocabulary import UtilityVocabulary
 from zope.container.contained import Contained
@@ -55,6 +56,7 @@
     _db = None
     _connection = None
 
+    config_path = FieldProperty(IZEOConnection['config_path'])
     server_name = FieldProperty(IZEOConnection['server_name'])
     server_port = FieldProperty(IZEOConnection['server_port'])
     storage = FieldProperty(IZEOConnection['storage'])
@@ -78,15 +80,19 @@
 
     def getConnection(self, wait=False, get_storage=False):
         """Get a tuple made of storage and DB connection for given settings"""
-        storage = ClientStorage.ClientStorage((str(self.server_name), self.server_port),
-                                              storage=self.storage,
-                                              username=self.username or '',
-                                              password=self.password or '',
-                                              realm=self.server_realm,
-                                              blob_dir=self.blob_dir,
-                                              shared_blob_dir=self.shared_blob_dir,
-                                              wait=wait)
-        db = DB(storage)
+        if self.config_path:
+            db = databaseFromURL(self.config_path)
+            storage = db.storage
+        else:
+            storage = ClientStorage.ClientStorage((str(self.server_name), self.server_port),
+                                                  storage=self.storage,
+                                                  username=self.username or '',
+                                                  password=self.password or '',
+                                                  realm=self.server_realm,
+                                                  blob_dir=self.blob_dir,
+                                                  shared_blob_dir=self.shared_blob_dir,
+                                                  wait=wait)
+            db = DB(storage)
         return (storage, db) if get_storage else db
 
     @property