From 9e18638dbd378db5737c9ddd9ef5c16a7e8ca4c7 Mon Sep 17 00:00:00 2001 From: Louie S Date: Sat, 16 Sep 2023 09:36:14 -0400 Subject: Set default paths for db based on os --- src/config.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/config.py b/src/config.py index 468718a..0fa034e 100644 --- a/src/config.py +++ b/src/config.py @@ -19,10 +19,12 @@ class Config(): self.loadConfig() def getConfigPath(self): + # Windows config path is "$LOCALAPPDATA/assignment-list-pyqt5/config" if sys.platform.startswith("win32"): - return os.path.join(os.path.expandvars("$APPDATA"), + return os.path.join(os.path.expandvars("$LOCALAPPDATA"), "assignment-list-pyqt5", "config") + # Unix config path is "$HOME/.config/assignment-list-pyqt5/config" else: return os.path.join( os.path.expanduser("~"), @@ -44,15 +46,26 @@ class Config(): def createConfig(self): self.config = configparser.ConfigParser() - self.config["paths"] = { - "db_path": os.path.join( - os.path.expanduser("~"), - ".local", - "share", - "assignment-list-pyqt5", - "data.db" - ) - } + if sys.platform.startswith("win32"): + self.config["paths"] = { + # Windows default DB path is "$APPDATA/assignment-list-pyqt5/data.db" + "db_path": os.path.join( + os.path.expandvars("$APPDATA"), + "assignment-list-pyqt5", + "data.db" + ) + } + else: + self.config["paths"] = { + # Unix default DB path is "$HOME/.local/share/assignment-list-pyqt5/data.db" + "db_path": os.path.join( + os.path.expanduser("~"), + ".local", + "share", + "assignment-list-pyqt5", + "data.db" + ) + } self.updateConfig() -- cgit