Added "get_connection_from_settings" function
authorThierry Florac <thierry.florac@onf.fr>
Wed, 11 Mar 2015 12:22:50 +0100
changeset 17 c5a19fddac05
parent 16 0edbf38973ce
child 18 51a503276de9
Added "get_connection_from_settings" function
src/pyams_utils/zodb.py
--- a/src/pyams_utils/zodb.py	Wed Mar 11 12:22:22 2015 +0100
+++ b/src/pyams_utils/zodb.py	Wed Mar 11 12:22:50 2015 +0100
@@ -29,6 +29,7 @@
 from persistent import Persistent
 from pyams_utils.adapter import adapter_config
 from pyramid.events import subscriber
+from pyramid_zodbconn import get_uris, db_from_uri
 from ZEO import ClientStorage
 from ZODB import DB
 from zope.componentvocabulary.vocabulary import UtilityVocabulary
@@ -156,3 +157,10 @@
     nameOnly = True
 
 getVocabularyRegistry().register('PyAMS ZEO connections', ZEOConnectionVocabulary)
+
+
+def get_connection_from_settings(settings):
+    """Load connection matching registry settings"""
+    for name, uri in get_uris(settings):
+        db = db_from_uri(uri, name, {})
+        return db.open()