From 6a8188f8739d7e0aebc0bf16ae4c1827f33431fc Mon Sep 17 00:00:00 2001 From: John Burwell Date: Fri, 12 May 2023 16:37:22 -0500 Subject: [PATCH] create dirs explicitly to deal with older versions of platformdirs --- rsbbs/config.py | 14 ++++++++------ rsbbs/logger.py | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/rsbbs/config.py b/rsbbs/config.py index 58b8cdf..a2b6b92 100644 --- a/rsbbs/config.py +++ b/rsbbs/config.py @@ -32,10 +32,11 @@ class Config(): self._load_config() # Put the messages db file in the system's user data directory + db_dir = platformdirs.user_data_dir(appname=self.app_name) + if not os.path.exists(db_dir): + os.makedirs(db_dir) self._config['db_path'] = os.path.join( - platformdirs.user_data_dir( - appname=self.app_name, - ensure_exists=True), + db_dir, 'messages.db') # Grab some config from the command line for convenience @@ -64,10 +65,11 @@ class Config(): @property def config_file(self): # Use either the specified file or a file in a system config location + config_dir = platformdirs.user_config_dir(appname=self.app_name) + if not os.path.exists(config_dir): + os.makedirs(config_dir) config_file = self._argv_config_file or os.path.join( - platformdirs.user_config_dir( - appname=self.app_name, - ensure_exists=True), + config_dir, 'config.yaml' ) return config_file diff --git a/rsbbs/logger.py b/rsbbs/logger.py index 575b925..a1ec332 100644 --- a/rsbbs/logger.py +++ b/rsbbs/logger.py @@ -48,10 +48,12 @@ class Logger(logging.Logger): logger.removeHandler(handler) # Log to a file in the system user log directory - log_dir = platformdirs.user_log_dir(appname=self.name, - ensure_exists=True) + log_dir = platformdirs.user_log_dir(appname=self.name) log_filepath = os.path.join(log_dir, 'activity.log') + if not os.path.exists(log_dir): + os.makedirs(log_dir) + handler = logging.FileHandler(filename=log_filepath) # Add the calling station to the log messages