python::GBSConfig::GBSConfig Class Reference

List of all members.

Public Member Functions

def __init__
def GetValue

Private Member Functions

def __ReadConfigFile

Private Attributes

 __config


Detailed Description

The class responsible for loading configuration data at program start

It first reads it's internal configuration file and then looks for external ones.
After that it's just a dictionary

Definition at line 3 of file GBSConfig.py.


Member Function Documentation

def python::GBSConfig::GBSConfig::__init__ (   self  ) 

Search for the configuration files (internal and external) and assemble a dictionary

Definition at line 9 of file GBSConfig.py.

00009                       :
00010         """ Search for the configuration files (internal and external) and assemble a dictionary"""
00011 
00012         self.__config = {}
00013 
00014         import os
00015 
00016         #  Read its own internal configuration
00017         rcFile = os.path.expandvars("$GBS_HOME/python/.gbsrc")
00018         if os.path.isfile(rcFile):
00019             self.__ReadConfigFile(rcFile)
00020         else :
00021             print "ERROR: Unable to locate configuration file " + str(rcFile)
00022             raise ConfigurationMissingError
00023 
00024         #  Read external configuration
00025         rcFile = os.path.expanduser("~/.gbsrc")
00026         if os.path.isfile(rcFile):
00027             self.__ReadConfigFile(rcFile)
00028 
00029         rcFile = os.path.expandvars("$GBS_CONFIG_PATH")
00030         if os.path.isfile(rcFile):
00031             self.__ReadConfigFile(rcFile)
00032 
00033         #  Set logger threshold
00034         SetLoggerThreshold(int(self.__config["LoggerThreshold"]))
00035 
    def GetValue(self,key):

def python::GBSConfig::GBSConfig::GetValue (   self,
  key 
)

Definition at line 36 of file GBSConfig.py.

00036                           :
00037         if self.__config.has_key(key): return self.__config[key]
00038         Log(logger.WARNING,"Attempting to access undefined configuration key '" + str(key) + "'")
00039         return None
00040     
    def __ReadConfigFile(self,rcFile):

def python::GBSConfig::GBSConfig::__ReadConfigFile (   self,
  rcFile 
) [private]

Read configuration files into dictionary.  

Definition at line 41 of file GBSConfig.py.

00041                                      :
00042         """ Read configuration files into dictionary.  """
00043 
00044 
00045         print "GBSConfig: Reading configuration from " + str(rcFile) + " ... ",
00046         f=open(rcFile)
00047 
00048         import re
00049         num_line = 0
00050         for line in f:
00051             num_line = num_line + 1
00052             # Skip blank lines and comments
00053             if re.search(r"^\s*$",line): continue
00054             if re.search(r"^\s*#",line): continue
00055             # Look for key vaule pairs
00056             mo = re.search(r"(\S+)\s+(\S+)",line)
00057             if mo :
00058                 (key,value) = mo.groups()
00059                 self.__config[key] = value
00060             else :
00061                 print "Bad data on line " + str(num_line) + " of file " + str(rcFile),
00062                 print ":" + str(line)
00063         print str(num_line) + " lines" 
00064 
00065 #  Singleton object with getter.
00066 
__config = GBSConfig()


Member Data Documentation

python::GBSConfig::GBSConfig::__config [private]

Definition at line 12 of file GBSConfig.py.


The documentation for this class was generated from the following file:
Generated on Mon Feb 18 14:42:02 2008 for gbs by  doxygen 1.5.4