Rewrite config in case of missing vars
This commit is contained in:
parent
f8c699f5af
commit
1dfaaa59e3
1 changed files with 11 additions and 1 deletions
|
@ -36,6 +36,16 @@ class Config:
|
||||||
def read_from_file(self, file):
|
def read_from_file(self, file):
|
||||||
if isfile(file):
|
if isfile(file):
|
||||||
config = load_source("config", file)
|
config = load_source("config", file)
|
||||||
|
for option in self.options:
|
||||||
|
found = False
|
||||||
|
for attr in dir(config):
|
||||||
|
if not attr.startswith("__"):
|
||||||
|
if option.name == attr:
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
if not found:
|
||||||
|
self.write_to_file(file)
|
||||||
|
return self.read_from_file(file)
|
||||||
return config
|
return config
|
||||||
else:
|
else:
|
||||||
raise FileNotFoundError()
|
raise FileNotFoundError()
|
||||||
|
@ -64,4 +74,4 @@ class Config:
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return self.get()
|
return self.get()
|
||||||
|
|
Reference in a new issue