Config.get() method
This commit is contained in:
parent
2aa2e01bc5
commit
283a5360ad
1 changed files with 19 additions and 0 deletions
|
|
@ -43,6 +43,25 @@ class Config:
|
||||||
self.path = path
|
self.path = path
|
||||||
self.sections = {}
|
self.sections = {}
|
||||||
|
|
||||||
|
def get(self, *args):
|
||||||
|
s = None
|
||||||
|
path = ''
|
||||||
|
for a in args:
|
||||||
|
if path: path += '.'
|
||||||
|
path += a
|
||||||
|
if not s:
|
||||||
|
try:
|
||||||
|
s = self.sections[a]
|
||||||
|
except KeyError:
|
||||||
|
s = self.sections[a] = Section(path)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
s = s.values[a]
|
||||||
|
except KeyError:
|
||||||
|
s = s.values[a] = Section(path)
|
||||||
|
|
||||||
|
return s
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
parser = SafeConfigParser()
|
parser = SafeConfigParser()
|
||||||
parser.read(self.path)
|
parser.read(self.path)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue