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

Source Code for Module 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   
15 -class ZeoConn(object):
16
17 - def __init__(self, host="localhost", port=8100):
18 from ZEO import ClientStorage 19 from ZODB import DB 20 addr = (host, port) 21 storage=ClientStorage.ClientStorage(addr) 22 self.db=DB(storage) 23 self.app = None 24 self.dmd = None 25 self.opendb()
26 27
28 - def opendb(self):
29 if self.app: return 30 self.connection=self.db.open() 31 root=self.connection.root() 32 self.app=root['Application'] 33 self._getContext(self.app) 34 self.dmd = self.app.zport.dmd
35 36
37 - def syncdb(self):
38 self.connection.sync()
39 40
41 - def closedb(self):
42 self.connection.close() 43 self.db.close() 44 self.app = None 45 self.dmd = None
46 47
48 - def _getContext(self, app):
49 from ZPublisher.HTTPRequest import HTTPRequest 50 from ZPublisher.HTTPResponse import HTTPResponse 51 from ZPublisher.BaseRequest import RequestContainer 52 resp = HTTPResponse(stdout=None) 53 env = { 54 'SERVER_NAME':'localhost', 55 'SERVER_PORT':'8080', 56 'REQUEST_METHOD':'GET' 57 } 58 req = HTTPRequest(None, env, resp) 59 return app.__of__(RequestContainer(REQUEST = req))
60