From 1dfaaa59e341f79b3f537a9f0e196393b146ff15 Mon Sep 17 00:00:00 2001 From: PhilipTrauner Date: Tue, 8 Mar 2016 08:46:30 +0100 Subject: [PATCH] Rewrite config in case of missing vars --- Shared/Config.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Shared/Config.py b/Shared/Config.py index bcc139c..de65b63 100644 --- a/Shared/Config.py +++ b/Shared/Config.py @@ -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() \ No newline at end of file + return self.get()