Rewrite config in case of missing vars

This commit is contained in:
PhilipTrauner 2016-03-08 08:46:30 +01:00
parent f8c699f5af
commit 1dfaaa59e3

View file

@ -36,6 +36,16 @@ class Config:
def read_from_file(self, file):
if isfile(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
else:
raise FileNotFoundError()
@ -64,4 +74,4 @@ class Config:
def __repr__(self):
return self.get()
return self.get()