1
2
3
4
5
6
7
8
9
10
11
12
13
14 from Products.ZenUtils.Utils import set_context
15
17
18 - def __init__(self, host="localhost", port=3306, user="zenoss",
19 passwd="zenoss", db="zodb", unix_socket=None):
20 from relstorage.storage import RelStorage
21 from relstorage.adapters.mysql import MySQLAdapter
22 connectionParams = {}
23 if unix_socket:
24 connectionParams['unix_socket'] = unix_socket
25 kwargs = {
26 'keep_history': False,
27 }
28 from relstorage.options import Options
29 adapter = MySQLAdapter(
30 host=host,
31 port=port,
32 user=user,
33 passwd=passwd,
34 db=db,
35 options=Options(**kwargs),
36 **connectionParams
37 )
38
39 storage = RelStorage(adapter, **kwargs)
40 from ZODB import DB
41 self.db=DB(storage)
42 self.app = None
43 self.dmd = None
44 self.opendb()
45
46
48 if self.app: return
49 self.connection=self.db.open()
50 root=self.connection.root()
51 app = root['Application']
52 self.app = set_context(app)
53 self.dmd = self.app.zport.dmd
54
55
57 self.connection.sync()
58
59
61 self.connection.close()
62 self.db.close()
63 self.app = None
64 self.dmd = None
65