From c1d873abafdcdf7f5d4eea721a5180372c79780c Mon Sep 17 00:00:00 2001 From: Rohit Hill Date: Sat, 26 Dec 2020 14:03:10 +0530 Subject: [PATCH] Fast load_config --- bpytop.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/bpytop.py b/bpytop.py index 1c5acd6..532a647 100755 --- a/bpytop.py +++ b/bpytop.py @@ -462,23 +462,25 @@ class Config: line = line.strip() if line.startswith("#? Config"): new_config["version"] = line[line.find("v. ") + 3:] - for key in self.keys: - if line.startswith(key): - line = line.replace(key + "=", "") - if line.startswith('"'): - line = line.strip('"') - if type(getattr(self, key)) == int: - try: - new_config[key] = int(line) - except ValueError: - self.warnings.append(f'Config key "{key}" should be an integer!') - if type(getattr(self, key)) == bool: - try: - new_config[key] = bool(strtobool(line)) - except ValueError: - self.warnings.append(f'Config key "{key}" can only be True or False!') - if type(getattr(self, key)) == str: - new_config[key] = str(line) + continue + if not '=' in line: + continue + key, line = line.split('=', maxsplit=1) + if not key in self.keys: + continue + line = line.strip('"') + if type(getattr(self, key)) == int: + try: + new_config[key] = int(line) + except ValueError: + self.warnings.append(f'Config key "{key}" should be an integer!') + if type(getattr(self, key)) == bool: + try: + new_config[key] = bool(strtobool(line)) + except ValueError: + 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: errlog.exception(str(e)) if "proc_sorting" in new_config and not new_config["proc_sorting"] in self.sorting_options: