From 341fe4c44fada601109ae5d21fb1cbdd906a73ff Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Thu, 26 Oct 2023 08:47:28 -0600 Subject: [PATCH] Handle juju config dirs with pathlib --- juju/utils.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/juju/utils.py b/juju/utils.py index ba365b42..bda80971 100644 --- a/juju/utils.py +++ b/juju/utils.py @@ -46,19 +46,17 @@ def juju_config_dir(): """ # Check $JUJU_DATA first - config_dir = os.environ.get('JUJU_DATA', None) + config_dir = Path(os.environ.get('JUJU_DATA', None)) # Second option: $XDG_DATA_HOME for ~/.local/share - if not config_dir: - base_dir = os.environ.get('XDG_DATA_HOME', None) - if base_dir is not None: - config_dir = base_dir + '/juju' + if not config_dir.exists(): + config_dir = Path(os.environ.get('XDG_DATA_HOME', '')) / 'juju' # Third option: just set it to ~/.local/share/juju - if not config_dir: - config_dir = '~/.local/share/juju' + if not config_dir.exists(): + config_dir = Path('~/.local/share/juju') - return os.path.abspath(os.path.expanduser(config_dir)) + return str(config_dir.expanduser().resolve()) def juju_ssh_key_paths():