Merge pull request #132 from mesosphere/subcommand_install
~/.dcos/subcommands
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
DCOS_DIR = ".dcos"
|
||||
"""DCOS data directory. Can store subcommands and the config file."""
|
||||
|
||||
DCOS_SUBCOMMAND_SUBDIR = 'subcommands'
|
||||
"""Name of the subdirectory that contains all of the subcommands. This is
|
||||
relative to the location of the executable."""
|
||||
|
||||
@@ -41,6 +41,18 @@ def command_executables(subcommand, dcos_path):
|
||||
BIN_DIRECTORY = 'Scripts' if util.is_windows_platform() else 'bin'
|
||||
|
||||
|
||||
def _subcommand_dir():
|
||||
"""Returns path to the subcommand directory. This directory contains
|
||||
a virtualenv for each installed subcommand.
|
||||
|
||||
:returns: path to the subcommand directory
|
||||
:rtype: str
|
||||
"""
|
||||
return os.path.expanduser(os.path.join("~",
|
||||
constants.DCOS_DIR,
|
||||
constants.DCOS_SUBCOMMAND_SUBDIR))
|
||||
|
||||
|
||||
def list_paths(dcos_path):
|
||||
"""List the real path to executable dcos subcommand programs.
|
||||
|
||||
@@ -59,9 +71,7 @@ def list_paths(dcos_path):
|
||||
os.access(os.path.join(binpath, filename), os.X_OK))
|
||||
]
|
||||
|
||||
subcommand_directory = os.path.join(
|
||||
dcos_path,
|
||||
constants.DCOS_SUBCOMMAND_SUBDIR)
|
||||
subcommand_directory = _subcommand_dir()
|
||||
|
||||
subcommands = [
|
||||
os.path.join(subcommand_directory, package, BIN_DIRECTORY, filename)
|
||||
@@ -93,9 +103,7 @@ def distributions(dcos_path):
|
||||
:rtype: list of str
|
||||
"""
|
||||
|
||||
subcommand_directory = os.path.join(
|
||||
dcos_path,
|
||||
constants.DCOS_SUBCOMMAND_SUBDIR)
|
||||
subcommand_directory = _subcommand_dir()
|
||||
|
||||
if os.path.isdir(subcommand_directory):
|
||||
return os.listdir(subcommand_directory)
|
||||
@@ -176,12 +184,11 @@ def install(distribution_name, install_operation, dcos_path):
|
||||
:rtype: dcos.api.errors.Error
|
||||
"""
|
||||
|
||||
subcommand_directory = os.path.join(
|
||||
dcos_path,
|
||||
constants.DCOS_SUBCOMMAND_SUBDIR)
|
||||
subcommand_directory = _subcommand_dir()
|
||||
|
||||
if not os.path.exists(subcommand_directory):
|
||||
logger.info('Creating directory: %r', subcommand_directory)
|
||||
os.mkdir(subcommand_directory, 0o775)
|
||||
os.makedirs(subcommand_directory, 0o775)
|
||||
|
||||
package_directory = os.path.join(subcommand_directory, distribution_name)
|
||||
|
||||
@@ -206,10 +213,7 @@ def uninstall(distribution_name, dcos_path):
|
||||
:type dcos_path: str
|
||||
"""
|
||||
|
||||
subcommand_directory = os.path.join(
|
||||
dcos_path,
|
||||
constants.DCOS_SUBCOMMAND_SUBDIR,
|
||||
distribution_name)
|
||||
subcommand_directory = os.path.join(_subcommand_dir(), distribution_name)
|
||||
|
||||
if os.path.isdir(subcommand_directory):
|
||||
shutil.rmtree(subcommand_directory)
|
||||
|
||||
Reference in New Issue
Block a user