28 from ztfy.utils.interfaces import IZEOConnection |
28 from ztfy.utils.interfaces import IZEOConnection |
29 |
29 |
30 # import Zope3 packages |
30 # import Zope3 packages |
31 from ZEO import ClientStorage |
31 from ZEO import ClientStorage |
32 from ZODB import DB |
32 from ZODB import DB |
|
33 from ZODB.config import databaseFromURL |
33 from zope.component import adapter |
34 from zope.component import adapter |
34 from zope.componentvocabulary.vocabulary import UtilityVocabulary |
35 from zope.componentvocabulary.vocabulary import UtilityVocabulary |
35 from zope.container.contained import Contained |
36 from zope.container.contained import Contained |
36 from zope.interface import implementer, implements, classProvides |
37 from zope.interface import implementer, implements, classProvides |
37 from zope.schema import getFieldNames |
38 from zope.schema import getFieldNames |
53 |
54 |
54 _storage = None |
55 _storage = None |
55 _db = None |
56 _db = None |
56 _connection = None |
57 _connection = None |
57 |
58 |
|
59 config_path = FieldProperty(IZEOConnection['config_path']) |
58 server_name = FieldProperty(IZEOConnection['server_name']) |
60 server_name = FieldProperty(IZEOConnection['server_name']) |
59 server_port = FieldProperty(IZEOConnection['server_port']) |
61 server_port = FieldProperty(IZEOConnection['server_port']) |
60 storage = FieldProperty(IZEOConnection['storage']) |
62 storage = FieldProperty(IZEOConnection['storage']) |
61 username = FieldProperty(IZEOConnection['username']) |
63 username = FieldProperty(IZEOConnection['username']) |
62 password = FieldProperty(IZEOConnection['password']) |
64 password = FieldProperty(IZEOConnection['password']) |
76 if k in names: |
78 if k in names: |
77 setattr(self, k, unicode(v) if isinstance(v, str) else v) |
79 setattr(self, k, unicode(v) if isinstance(v, str) else v) |
78 |
80 |
79 def getConnection(self, wait=False, get_storage=False): |
81 def getConnection(self, wait=False, get_storage=False): |
80 """Get a tuple made of storage and DB connection for given settings""" |
82 """Get a tuple made of storage and DB connection for given settings""" |
81 storage = ClientStorage.ClientStorage((str(self.server_name), self.server_port), |
83 if self.config_path: |
82 storage=self.storage, |
84 db = databaseFromURL(self.config_path) |
83 username=self.username or '', |
85 storage = db.storage |
84 password=self.password or '', |
86 else: |
85 realm=self.server_realm, |
87 storage = ClientStorage.ClientStorage((str(self.server_name), self.server_port), |
86 blob_dir=self.blob_dir, |
88 storage=self.storage, |
87 shared_blob_dir=self.shared_blob_dir, |
89 username=self.username or '', |
88 wait=wait) |
90 password=self.password or '', |
89 db = DB(storage) |
91 realm=self.server_realm, |
|
92 blob_dir=self.blob_dir, |
|
93 shared_blob_dir=self.shared_blob_dir, |
|
94 wait=wait) |
|
95 db = DB(storage) |
90 return (storage, db) if get_storage else db |
96 return (storage, db) if get_storage else db |
91 |
97 |
92 @property |
98 @property |
93 def connection(self): |
99 def connection(self): |
94 return self._connection |
100 return self._connection |