From 2928c151e3d3170eba3489cf5d40bdbaa755701b Mon Sep 17 00:00:00 2001 From: Tamar Ben-Shachar Date: Thu, 10 Mar 2016 16:35:16 -0800 Subject: [PATCH] create config toml at `DCOS_CONFIG` if doesn't exist --- dcos/util.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/dcos/util.py b/dcos/util.py index fab9ca8..2c5716f 100644 --- a/dcos/util.py +++ b/dcos/util.py @@ -157,16 +157,25 @@ def get_config_path(): :rtype: str """ - default = os.path.expanduser( + return os.environ.get(constants.DCOS_CONFIG_ENV, get_default_config_path()) + + +def get_default_config_path(): + """Returns the default path to the DCOS config file. + + :returns: path to the DCOS config file + :rtype: str + """ + + return os.path.expanduser( os.path.join("~", constants.DCOS_DIR, 'dcos.toml')) - return os.environ.get(constants.DCOS_CONFIG_ENV, default) - def get_config(mutable=False): - """ Returns the DCOS configuration object + """Returns the DCOS configuration object and creates config file is none + found and `DCOS_CONFIG` set to default value :param mutable: True if the returned Toml object should be mutable :type mutable: boolean @@ -178,7 +187,10 @@ def get_config(mutable=False): from dcos import config path = get_config_path() + default = get_default_config_path() + if path == default: + ensure_dir_exists(os.path.dirname(default)) return config.load_from_path(path, mutable)