You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/04/14 01:47:54 UTC
[3/4] mesos git commit: CLI: Moved settings into a user-defined TOML
file.
CLI: Moved settings into a user-defined TOML file.
These settings were previously defined and set in settings.py.
We now use a TOML file containing the configuration,
this format has been chosen because:
* It supports comments.
* It is well-specified and readable.
* It allows logical grouping.
* It supports common data types.
The config file environment variable, previously
`MESOS_CLI_CONFIG_PATH`, is now `MESOS_CLI_CONFIG`.
This change follows the design doc about the new CLI.
Also, the environment variable `MESOS_CLI_PLUGINS` is not used
anymore as plugins can be added using the TOML file instead.
Review: https://reviews.apache.org/r/57951/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8f13ad86
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8f13ad86
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8f13ad86
Branch: refs/heads/master
Commit: 8f13ad8688f13fcbdfde08f36428bf4db266d94e
Parents: 12e4812
Author: Armand Grillet <ag...@mesosphere.io>
Authored: Thu Apr 13 18:34:57 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Thu Apr 13 18:34:57 2017 -0700
----------------------------------------------------------------------
src/cli_new/README.md | 20 +++++++++++++
src/cli_new/bin/settings.py | 55 +++++++++++++++++++----------------
src/cli_new/pip-requirements.txt | 1 +
3 files changed, 51 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/8f13ad86/src/cli_new/README.md
----------------------------------------------------------------------
diff --git a/src/cli_new/README.md b/src/cli_new/README.md
index aa11813..c5475c7 100644
--- a/src/cli_new/README.md
+++ b/src/cli_new/README.md
@@ -61,3 +61,23 @@ Running the Mesos CLI unit tests
OK
```
+
+
+## Setting up your configuration
+
+In order to use this tool, you will need to create a
+configuration file in your home directory under
+`~/.mesos/config.toml`. A template for this config can be
+seen below:
+
+```
+# The `plugins` is an array listing the absolute paths of the
+# plugins you want to add to the CLI.
+plugins = [
+ "</absolute/path/to/plugin-1/directory>",
+ "</absolute/path/to/plugin-2/directory>"
+]
+```
+
+You can override the location of this configuration file using
+the environment variable `MESOS_CLI_CONFIG`.
http://git-wip-us.apache.org/repos/asf/mesos/blob/8f13ad86/src/cli_new/bin/settings.py
----------------------------------------------------------------------
diff --git a/src/cli_new/bin/settings.py b/src/cli_new/bin/settings.py
index 2f6162e..8dbb160 100644
--- a/src/cli_new/bin/settings.py
+++ b/src/cli_new/bin/settings.py
@@ -20,9 +20,8 @@ of updating the default configuration from reading environment variables or
parsing a configuration file.
"""
-import json
import os
-import sys
+import toml
from cli.exceptions import CLIException
@@ -37,35 +36,41 @@ try:
except Exception:
VERSION = "Development"
+# The top-level directory of this project.
+PROJECT_DIR = os.path.join(os.path.dirname(__file__), os.pardir)
# The builtin plugins.
PLUGINS = []
+MESOS_CLI_DEFAULT_CONFIG_PATH = os.path.join(
+ os.path.expanduser("~"), ".mesos/config.toml")
-# Allow extra plugins to be pulled in from a configuration file.
-if os.environ.get("MESOS_CLI_CONFIG_FILE"):
- try:
- CONFIG_FILE = open(os.environ["MESOS_CLI_CONFIG_FILE"])
- except Exception as exception:
- sys.exit("Unable to open configuration file '{config}': {error}"
- .format(config=os.environ.get("MESOS_CLI_CONFIG_FILE"),
- error=str(exception)))
+# Load the configuration file path for the CLI.
+if os.environ.get("MESOS_CLI_CONFIG"):
+ MESOS_CLI_CONFIG_PATH = os.environ["MESOS_CLI_CONFIG"]
+else:
+ MESOS_CLI_CONFIG_PATH = MESOS_CLI_DEFAULT_CONFIG_PATH
- try:
- CONFIG_DATA = json.load(CONFIG_FILE)
- except Exception as exception:
- raise CLIException("Error loading config file as JSON: {error}"
+# Load the configuration file as a TOML file.
+try:
+ CONFIG_DATA = toml.load(MESOS_CLI_CONFIG_PATH)
+except Exception as exception:
+ if MESOS_CLI_CONFIG_PATH is not MESOS_CLI_DEFAULT_CONFIG_PATH:
+ raise CLIException("Error loading config file as TOML: {error}"
.format(error=exception))
+ else:
+ CONFIG_DATA = {}
- if "plugins" in CONFIG_DATA:
- if not isinstance(CONFIG_DATA["plugins"], list):
- raise CLIException("'plugins' field must be a list")
-
- PLUGINS.extend(CONFIG_DATA["plugins"])
-
+# Allow extra plugins to be pulled in from the configuration file.
+if "plugins" in CONFIG_DATA:
+ if not isinstance(CONFIG_DATA["plugins"], list):
+ raise CLIException("Unable to parse config file '{path}': 'plugins' "
+ "field must be a list"
+ .format(path=MESOS_CLI_CONFIG_PATH))
-# Allow extra plugins to be pulled in from the environment.
-# The `MESOS_CLI_PLUGINS` environment variable is a ":" separated
-# list of paths to each plugin. All paths must be absolute.
-if os.environ.get("MESOS_CLI_PLUGINS"):
- PLUGINS += filter(None, os.environ.get("MESOS_CLI_PLUGINS").split(":"))
+ for plugin in CONFIG_DATA["plugins"]:
+ if os.path.exists(plugin):
+ PLUGINS.append(plugin)
+ else:
+ raise CLIException("Plugin path not found: {path}"
+ .format(path=plugin))
http://git-wip-us.apache.org/repos/asf/mesos/blob/8f13ad86/src/cli_new/pip-requirements.txt
----------------------------------------------------------------------
diff --git a/src/cli_new/pip-requirements.txt b/src/cli_new/pip-requirements.txt
index e73bbfd..28613e5 100644
--- a/src/cli_new/pip-requirements.txt
+++ b/src/cli_new/pip-requirements.txt
@@ -10,4 +10,5 @@ PyInstaller==3.1.1
pylint==1.6.4
six==1.10.0
termcolor==1.1.0
+toml==0.9.2
wrapt==1.10.8