python::GBSConfig::GBSConfig Class Reference

List of all members.

Public Member Functions

def __init__
def GetValue

Private Member Functions

def __ReadConfigFile

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 2 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 5 of file GBSConfig.py.

00008                       :
00009         """ Search for the configuration files (internal and external) and assemble a dictionary"""
00010 
00011         self.__config = {}
00012 
00013         import os
00014 
00015         #  Read its own internal configuration
00016         rcFile = os.path.expandvars("$GBS_HOME/python/.gbsrc")
00017         if os.path.isfile(rcFile):
00018             self.__ReadConfigFile(rcFile)
00019         else :
00020             print "ERROR: Unable to locate configuration file " + str(rcFile)
00021             raise ConfigurationMissingError
00022 
00023         #  Read external configuration
00024         rcFile = os.path.expanduser("~/.gbsrc")
00025         if os.path.isfile(rcFile):
00026             self.__ReadConfigFile(rcFile)
00027 
00028         rcFile = os.path.expandvars("$GBS_CONFIG_PATH")
        if os.path.isfile(rcFile):

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

Read configuration files into dictionary.  

Definition at line 33 of file GBSConfig.py.

00033                                      : return self.__config[key]
00034         return ""
00035     
00036     def __ReadConfigFile(self,rcFile):
00037         """ Read configuration files into dictionary.  """
00038 
00039 
00040         print "GBSConfig: Reading configuration from " + str(rcFile) + " ... ",
00041         f=open(rcFile)
00042 
00043         import re
00044         num_line = 0
00045         for line in f:
00046             num_line = num_line + 1
00047             # Skip blank lines and comments
00048             if re.search(r"^\s*$",line): continue
00049             if re.search(r"^\s*#",line): continue
00050             # Look for key vaule pairs
00051             mo = re.search(r"^(\S+)\s+(.+?)\s*$",line)
00052             if mo :
00053                 (key,value) = mo.groups()
00054                 self.__config[key] = value
00055             else :
00056                 print "Bad data on line " + str(num_line) + " of file " + str(rcFile),
00057                 print ":" + str(line)
00058         print str(num_line) + " lines" 

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

Definition at line 29 of file GBSConfig.py.

00029                                  :
00030             self.__ReadConfigFile(rcFile)
00031 
00032     def GetValue(self,key):
        if self.__config.has_key(key): return self.__config[key]


The documentation for this class was generated from the following file:
Generated on Fri Mar 5 09:25:41 2010 for gbs by  doxygen 1.4.7