From acfd711399efbaea0bd2966392a7be1b654db02f Mon Sep 17 00:00:00 2001 From: ArndalAndersen Date: Tue, 23 Apr 2019 15:37:54 +0200 Subject: [PATCH] BF: Handle non-existent configuration path When checking for available pump configurations pyqmix assumes that their default location is: 'C:/Users/Public/Documents/QmixElements/Projects/default_project/Configurations/'. If this directory does not exist pyqmix will now raise an error. --- CHANGES.md | 4 ++++ pyqmix/config.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 9efb89b..8a2c4dc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,7 @@ +Version 2019.1 +------------------ +* Handle non-existent configuration directory + Version 2018.12.13 ------------------ * Update installation instructions diff --git a/pyqmix/config.py b/pyqmix/config.py index 693c4b3..2f0a7e0 100644 --- a/pyqmix/config.py +++ b/pyqmix/config.py @@ -92,6 +92,11 @@ def get_available_qmix_configs(configs_dir=None): list of strings Names of available Qmix configurations. + Raises + ------ + ValueError + If the configuration directory does not exist. + """ if configs_dir is None: configs_dir = DEFAULT_CONFIGS_DIR @@ -100,6 +105,10 @@ def get_immediate_subdirectories(a_dir): return [name for name in os.listdir(a_dir) if os.path.isdir(os.path.join(a_dir, name))] + if not os.path.exists(configs_dir): + msg = 'The configuration directory does not exist: %s' % configs_dir + raise ValueError(msg) + return get_immediate_subdirectories(configs_dir)