config: add DCOS_DIR env var (#939)

This commit is contained in:
tamarrow
2017-03-16 14:54:16 -07:00
committed by GitHub
parent 525300bedb
commit 965c888dc4
4 changed files with 25 additions and 11 deletions

View File

@@ -25,10 +25,13 @@ Options:
Environment Variables:
DCOS_CONFIG
Set the path to the DC/OS configuration file. By default, this variable
is set to ~/.dcos/dcos.toml.
is set to $DCOS_DIR/dcos.toml.
DCOS_DEBUG
Indicates whether to print additional debug messages to stdout. By
default this is set to false.
DCOS_DIR
Set the data directory for DC/OS configuration. By default, this
variable is set to ~/.dcos
DCOS_LOG_LEVEL
Prints log messages to stderr at or above the level indicated. This is
equivalent to the --log-level command-line option.

View File

@@ -22,6 +22,17 @@ def get_config_path():
return os.environ.get(constants.DCOS_CONFIG_ENV, get_default_config_path())
def get_config_dir_path():
"""
:returns: path to the DC/OS data directory
:rtype: str
"""
config_dir = os.environ.get(constants.DCOS_DIR_ENV) or \
os.path.join("~", constants.DCOS_DIR)
return os.path.expanduser(config_dir)
def get_default_config_path():
"""Returns the default path to the DCOS config file.
@@ -29,10 +40,7 @@ def get_default_config_path():
:rtype: str
"""
return os.path.expanduser(
os.path.join("~",
constants.DCOS_DIR,
'dcos.toml'))
return os.path.join(get_config_dir_path(), 'dcos.toml')
def get_config(mutable=False):

View File

@@ -1,5 +1,8 @@
DCOS_DIR = ".dcos"
"""DC/OS data directory. Can store subcommands and the config file."""
"""DC/OS data directory. Can store subcommands and the config file."""
DCOS_DIR_ENV = 'DCOS_DIR'
"""Name of the environment variable pointing to the DC/OS data directory"""
DCOS_SUBCOMMAND_ENV_SUBDIR = 'env'
"""In a package's directory, this is the cli contents subdirectory."""

View File

@@ -13,7 +13,7 @@ from distutils.version import LooseVersion
import requests
from dcos import constants, util
from dcos import config, constants, util
from dcos.errors import DCOSException
from dcos.subprocess import Subproc
@@ -358,10 +358,10 @@ def install(pkg):
def _subcommand_dir():
""" Returns ~/.dcos/subcommands """
return os.path.expanduser(os.path.join("~",
constants.DCOS_DIR,
constants.DCOS_SUBCOMMAND_SUBDIR))
""" Returns subcommand dir. defaults to ~/.dcos/subcommands """
return os.path.join(config.get_config_dir_path(),
constants.DCOS_SUBCOMMAND_SUBDIR)
def _package_dir(name):