summaryrefslogtreecommitdiff
path: root/config.py
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2023-09-16 09:36:14 -0400
committerLouie S <louie@example.com>2023-09-16 09:36:14 -0400
commit6e52afa26d8c50d07988376e43a641c70370b9c5 (patch)
tree3b9cc7f01aa8a64fa4dea6ee4547fc50423f6725 /config.py
parent76a1b6384301a9a8e37b1176f83f55b2827b2d16 (diff)
Create preferences dialog to control config file
Diffstat (limited to 'config.py')
-rw-r--r--config.py24
1 files changed, 15 insertions, 9 deletions
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)