Init confobj before using it
only read config file once
This commit is contained in:
parent
79452ebf10
commit
748fef4403
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user