create dirs explicitly to deal with older versions of platformdirs
All checks were successful
Test / Test (push) Successful in 1m28s

This commit is contained in:
John Burwell 2023-05-12 16:37:22 -05:00
parent db940aa983
commit 6a8188f873
2 changed files with 12 additions and 8 deletions

View File

@ -32,10 +32,11 @@ class Config():
self._load_config() self._load_config()
# Put the messages db file in the system's user data directory # 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( self._config['db_path'] = os.path.join(
platformdirs.user_data_dir( db_dir,
appname=self.app_name,
ensure_exists=True),
'messages.db') 'messages.db')
# Grab some config from the command line for convenience # Grab some config from the command line for convenience
@ -64,10 +65,11 @@ class Config():
@property @property
def config_file(self): def config_file(self):
# Use either the specified file or a file in a system config location # 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( config_file = self._argv_config_file or os.path.join(
platformdirs.user_config_dir( config_dir,
appname=self.app_name,
ensure_exists=True),
'config.yaml' 'config.yaml'
) )
return config_file return config_file

View File

@ -48,10 +48,12 @@ class Logger(logging.Logger):
logger.removeHandler(handler) logger.removeHandler(handler)
# Log to a file in the system user log directory # Log to a file in the system user log directory
log_dir = platformdirs.user_log_dir(appname=self.name, log_dir = platformdirs.user_log_dir(appname=self.name)
ensure_exists=True)
log_filepath = os.path.join(log_dir, 'activity.log') 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) handler = logging.FileHandler(filename=log_filepath)
# Add the calling station to the log messages # Add the calling station to the log messages