diff --git a/LDP/lampadas/pylib/Config.py b/LDP/lampadas/pylib/Config.py index 0ba56d2f..51c124ce 100755 --- a/LDP/lampadas/pylib/Config.py +++ b/LDP/lampadas/pylib/Config.py @@ -9,6 +9,11 @@ This module provides configuration information from lampadas.conf. # Modules ################################################################## +# Globals + +CONF_FILE = '../conf/lampadas.conf' + + # BaseConfig ############################################################### class ConfigFileReadErrorException(Exception) : @@ -22,24 +27,37 @@ class Config: DBType = "" DBName = "" + Logfile = "" def __init__(self) : import ConfigParser self.config = ConfigParser.ConfigParser() - self.config.readfp(open('../conf/lampadas.conf')) - if not self.config.has_section('DB') : - raise ConfigFileReadErrorException("File 'lampadas.conf' is missing or does not contain a '[DB]' section") - - if not self.config.has_option('DB', 'dbtype') : - raise ConfigFileReadErrorException("Can't read option 'dbtype' from lampadas.conf") - self.DBType = self.config.get('DB', 'dbtype') - - if not self.config.has_option('DB', 'dbname') : - raise ConfigFileReadErrorException("Can't read option 'dbname' from lampadas.conf") - self.DBName = self.config.get('DB', 'dbname') - + self.config.readfp(open(CONF_FILE)) + self.DBType = self.ReadVar('DB', 'dbtype') + self.DBName = self.ReadVar('DB', 'dbname') + self.Logfile = self.ReadVar('LOG', 'logfile') + + + def ReadVar(self, section, name): + if not self.config.has_section(section) : + raise ConfigFileReadErrorException("File '" + CONF_FILE + "' is missing or does not contain a '" + section + "' section") + + if not self.config.has_option(section, name): + raise ConfigFileReadErrorException("Can't read option '" + name + "' from " + CONF_FILE) + + return self.config.get(section, name) + + # main if __name__ == '__main__' : - print "This module cannot be run from the command line" + print "Running unit tests..." + Config = Config() + assert Config.DBType > '' + print "DBType= " + Config.DBType + assert Config.DBName > '' + print "DBName= " + Config.DBName + assert Config.Logfile > '' + print "Logfile=" + Config.Logfile + print "Unit tests complete." diff --git a/LDP/lampadas/pylib/Log.py b/LDP/lampadas/pylib/Log.py index 066b682e..0b5d1fca 100755 --- a/LDP/lampadas/pylib/Log.py +++ b/LDP/lampadas/pylib/Log.py @@ -8,11 +8,10 @@ This module generates the system log for Lampadas. # Modules ################################################################## +import Config +Config = Config.Config() -# Constants - -LOG_FILE = 'lampadas.log' class Log: """ @@ -20,7 +19,7 @@ class Log: """ def __init__(self): - self.log = open(LOG_FILE, 'a+') + self.log = open(Config.Logfile, 'a+') def __del__(self): self.log.close @@ -33,4 +32,4 @@ class Log: def Truncate(self): self.log.close - self.log = open(LOG_FILE, 'w+') + self.log = open(Config.Logfile, 'w+')