Fast load_config

pull/221/head
Rohit Hill 2020-12-26 14:03:10 +05:30
parent 09e639cc04
commit c1d873abaf
1 changed files with 19 additions and 17 deletions

View File

@ -462,23 +462,25 @@ class Config:
line = line.strip() line = line.strip()
if line.startswith("#? Config"): if line.startswith("#? Config"):
new_config["version"] = line[line.find("v. ") + 3:] new_config["version"] = line[line.find("v. ") + 3:]
for key in self.keys: continue
if line.startswith(key): if not '=' in line:
line = line.replace(key + "=", "") continue
if line.startswith('"'): key, line = line.split('=', maxsplit=1)
line = line.strip('"') if not key in self.keys:
if type(getattr(self, key)) == int: continue
try: line = line.strip('"')
new_config[key] = int(line) if type(getattr(self, key)) == int:
except ValueError: try:
self.warnings.append(f'Config key "{key}" should be an integer!') new_config[key] = int(line)
if type(getattr(self, key)) == bool: except ValueError:
try: self.warnings.append(f'Config key "{key}" should be an integer!')
new_config[key] = bool(strtobool(line)) if type(getattr(self, key)) == bool:
except ValueError: try:
self.warnings.append(f'Config key "{key}" can only be True or False!') new_config[key] = bool(strtobool(line))
if type(getattr(self, key)) == str: except ValueError:
new_config[key] = str(line) self.warnings.append(f'Config key "{key}" can only be True or False!')
if type(getattr(self, key)) == str:
new_config[key] = str(line)
except Exception as e: except Exception as e:
errlog.exception(str(e)) errlog.exception(str(e))
if "proc_sorting" in new_config and not new_config["proc_sorting"] in self.sorting_options: if "proc_sorting" in new_config and not new_config["proc_sorting"] in self.sorting_options: