From 6e52afa26d8c50d07988376e43a641c70370b9c5 Mon Sep 17 00:00:00 2001 From: Louie S Date: Sat, 16 Sep 2023 09:36:14 -0400 Subject: Create preferences dialog to control config file --- config.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'config.py') diff --git a/config.py b/config.py index 557de0e..da40ed4 100644 --- a/config.py +++ b/config.py @@ -23,20 +23,20 @@ class Config(): self.loadConfig() def loadConfig(self): - config = configparser.ConfigParser() + self.config = configparser.ConfigParser() try: - config.read(self.config_path) + self.config.read(self.config_path) except: print("Could not parse config file '{}'".format(self.config_path)) - if "paths" in config: - if config["paths"]["db_path"]: - Globals.db_path = config["paths"]["db_path"] + if "paths" in self.config: + if self.config["paths"]["db_path"]: + Globals.db_path = self.config["paths"]["db_path"] def createConfig(self): - config = configparser.ConfigParser() - config["paths"] = { + self.config = configparser.ConfigParser() + self.config["paths"] = { "db_path": os.path.join( os.path.expanduser("~"), ".local", @@ -46,6 +46,12 @@ class Config(): ) } + self.updateConfig() + + def updateConfig(self): + """ + Update the configuration file with values from self.config + """ # Attempt to create directory if necessary if not os.path.exists(os.path.dirname(self.config_path)): try: @@ -54,10 +60,10 @@ class Config(): print("Error: Could not create config directory '{}'".format(os.path.dirname(self.config_path))) sys.exit(1) - # Attempt to create file + # Attempt to write to file try: with open(self.config_path, 'w') as configfile: - config.write(configfile) + self.config.write(configfile) except: print("Error: Could not open config file '{}'".format(self.config_path)) sys.exit(1) -- cgit