--- a/src/ztfy/utils/zodb.py Thu Sep 13 10:56:25 2012 +0200
+++ b/src/ztfy/utils/zodb.py Thu Sep 20 17:06:22 2012 +0200
@@ -16,6 +16,7 @@
__docformat__ = "restructuredtext"
# import standard packages
+from persistent import Persistent
# import Zope3 interfaces
from persistent.interfaces import IPersistent
@@ -23,14 +24,48 @@
from ZODB.interfaces import IConnection
# import local interfaces
+from ztfy.utils.interfaces import IZEOConnection
# import Zope3 packages
+from ZEO import ClientStorage
+from ZODB import DB
from zope.component import adapter
-from zope.interface import implementer
+from zope.container.contained import Contained
+from zope.interface import implementer, implements
+from zope.schema.fieldproperty import FieldProperty
# import local packages
+class ZEOConnectionInfo(object):
+ """ZEO connection info"""
+
+ implements(IZEOConnection)
+
+ server_name = FieldProperty(IZEOConnection['server_name'])
+ server_port = FieldProperty(IZEOConnection['server_port'])
+ storage = FieldProperty(IZEOConnection['storage'])
+ username = FieldProperty(IZEOConnection['username'])
+ password = FieldProperty(IZEOConnection['password'])
+ server_realm = FieldProperty(IZEOConnection['server_realm'])
+
+ 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.server_storage,
+ username=self.server_username or '',
+ password=self.server_password or '',
+ realm=self.server_realm,
+ wait=wait)
+ db = DB(storage)
+ return (storage, db) if get_storage else db
+
+
+class ZEOConnectionUtility(ZEOConnectionInfo, Persistent, Contained):
+ """Persistent ZEO connection settings utility"""
+
+
+
# IPersistent adapters copied from zc.twist package
# also register this for adapting from IConnection
@adapter(IPersistent)