Package Products :: Package ZenUtils :: Module ZeoConn
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenUtils.ZeoConn

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  from Products.ZenUtils.Utils import set_context 
15   
16 -class ZeoConn(object):
17
18 - def __init__(self, host="localhost", port=8100):
19 from ZEO import ClientStorage 20 from ZODB import DB 21 addr = (host, port) 22 storage=ClientStorage.ClientStorage(addr) 23 self.db=DB(storage) 24 self.app = None 25 self.dmd = None 26 self.opendb()
27 28
29 - def opendb(self):
30 if self.app: return 31 self.connection=self.db.open() 32 root=self.connection.root() 33 app = root['Application'] 34 self.app = set_context(app) 35 self.dmd = self.app.zport.dmd
36 37
38 - def syncdb(self):
39 self.connection.sync()
40 41
42 - def closedb(self):
43 self.connection.close() 44 self.db.close() 45 self.app = None 46 self.dmd = None
47