Init confobj before using it

only read config file once
This commit is contained in:
Marcus Stoegbauer 2013-01-13 21:30:48 +00:00
parent 79452ebf10
commit 748fef4403

View File

@ -10,15 +10,16 @@ cfgfile.py
Created by Marcus Stoegbauer on 2013-01-12.
Copyright (c) 2013 __MyCompanyName__. All rights reserved.
"""
from ConfigParser import ConfigParser
import ConfigParser
class Conf(object):
confobj = ConfigParser()
confobj = ConfigParser.RawConfigParser()
cfgfile = ''
def __init__(self, filename = None):
"""if filename is set, open config file and initialize the ConfigParser
"""
self.confobj = ConfigParser.RawConfigParser()
if filename:
self.setfilename(filename)
# if filename
@ -27,7 +28,8 @@ class Conf(object):
def setfilename(self, filename):
"""initialize the ConfigParser
"""
if len(self.confobj.read(filename)) == 0 or self.confobj.read(filename)[0] != filename:
ret = self.confobj.read(filename)
if len(ret) == 0 or ret[0] != filename:
raise Exception('Cannot read config file ' + filename)
# if cannot read
self.cfgfile = filename