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 or (at your
     8  # option) any later version as published by 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=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
    47 -    def opendb(self):
    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
    56 -    def syncdb(self):
    57          self.connection.sync()
    58
    59
    60 -    def closedb(self):
    61          self.connection.close()
    62          self.db.close()
    63          self.app = None
    64          self.dmd = None
    65