# Created by Leo from: C:\Development\Python22\Lib\site-packages\vb2py\vb2py.leo
from utils import rootPath
import ConfigParser
import os
class VB2PYConfigObject(dict):
"""A dictionary of configuration options
Options are accessed via a tuple
c[section, key]
"""
def __init__(self, *args, **kw):
"""Initialize the dictionary"""
self.initConfig(*args, **kw)
def __getitem__(self, key):
"""Get an item"""
try:
return self._local_overide["%s.%s" % key]
except KeyError:
return self._config.get(*key)
def initConfig(self, filename="vb2py.ini", path=None):
"""Read the values"""
if path is None:
path = rootPath()
self._config = ConfigParser.ConfigParser()
self._config.read(os.path.join(path, filename))
self._local_overide = {}
def setLocalOveride(self, section, name, value):
"""Set a local overide for a value"""
self.checkValue(section, name)
self._local_overide["%s.%s" % (section, name)] = value
def removeLocalOveride(self, section, name,):
"""Remove a local overide"""
self.checkValue(section, name)
del(self._local_overide["%s.%s" % (section, name)])
def checkValue(self, section, name):
"""Make sure we have this section and name"""
dummy = self[section, name]
#
# We always want people to use the same one
_VB2PYConfig = VB2PYConfigObject()
def VB2PYConfig(init=0):
ret = _VB2PYConfig
if init:
ret.initConfig()
return ret
|