CLI: Renamed config.py to settings.py. This is being renamed due to the upcoming introduction of a "config" plugin for the new CLI.
Review: https://reviews.apache.org/r/57896/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/1cdd962b Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/1cdd962b Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/1cdd962b Branch: refs/heads/master Commit: 1cdd962bc0251f6afbf0bda86055a2f206474811 Parents: f130a56 Author: Armand Grillet <[email protected]> Authored: Thu Apr 6 13:05:34 2017 -0700 Committer: Joseph Wu <[email protected]> Committed: Thu Apr 6 17:56:49 2017 -0700 ---------------------------------------------------------------------- src/cli_new/bin/config.py | 71 ---------------------------------------- src/cli_new/bin/main.py | 14 ++++---- src/cli_new/bin/settings.py | 71 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 78 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/1cdd962b/src/cli_new/bin/config.py ---------------------------------------------------------------------- diff --git a/src/cli_new/bin/config.py b/src/cli_new/bin/config.py deleted file mode 100644 index 2f77dc4..0000000 --- a/src/cli_new/bin/config.py +++ /dev/null @@ -1,71 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -""" -This file defines the default configuration of the mesos-cli. It also takes -care of updating the default configuration from reading environment variables -or parsing a configuration file. -""" - -import json -import os -import sys - -from cli.exceptions import CLIException - - -# There is no version module included in this package. However, -# when creating an executable using pyinstaller, a version.py -# file will be autogenerated and inserted into the PYTHONPATH. -# When this happens we import it to set the VERSION. -try: - # pylint: disable=F0401,W0611 - from version import VERSION -except Exception: - VERSION = "Development" - - -# The builtin plugins. -PLUGINS = [] - - -# 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))) - - try: - CONFIG_DATA = json.load(CONFIG_FILE) - except Exception as exception: - raise CLIException("Error loading config file as JSON: {error}" - .format(error=exception)) - - 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 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(":")) http://git-wip-us.apache.org/repos/asf/mesos/blob/1cdd962b/src/cli_new/bin/main.py ---------------------------------------------------------------------- diff --git a/src/cli_new/bin/main.py b/src/cli_new/bin/main.py index efeca6e..397c120 100644 --- a/src/cli_new/bin/main.py +++ b/src/cli_new/bin/main.py @@ -20,14 +20,14 @@ This is the main executable of the mesos-cli. import sys -import config -import cli +import settings +import cli from cli.docopt import docopt from cli.exceptions import CLIException -VERSION = "Mesos " + config.VERSION + " CLI" +VERSION = "Mesos " + settings.VERSION + " CLI" SHORT_HELP = "Perform operations on a running Mesos cluster." @@ -70,7 +70,7 @@ def autocomplete(cmds, plugins, current_word, argv): plugin = cli.util.get_module(plugins, argv[0]) plugin_class = getattr(plugin, plugin.PLUGIN_CLASS) - return plugin_class(config).__autocomplete_base__(current_word, argv[1:]) + return plugin_class(settings).__autocomplete_base__(current_word, argv[1:]) def main(argv): @@ -79,7 +79,7 @@ def main(argv): """ # Initialize the various plugins. - plugins = cli.util.import_modules(config.PLUGINS, "plugins") + plugins = cli.util.import_modules(settings.PLUGINS, "plugins") cmds = { cli.util.get_module(plugins, plugin).PLUGIN_NAME: @@ -125,7 +125,7 @@ def main(argv): if len(argv) > 0 and argv[0] in cmds: plugin = cli.util.get_module(plugins, argv[0]) plugin_class = getattr(plugin, plugin.PLUGIN_CLASS) - plugin_class(config).main(argv[1:] + ["--help"]) + plugin_class(settings).main(argv[1:] + ["--help"]) else: main(["--help"]) @@ -133,7 +133,7 @@ def main(argv): elif cmd in cmds.keys(): plugin = cli.util.get_module(plugins, cmd) plugin_class = getattr(plugin, plugin.PLUGIN_CLASS) - plugin_class(config).main(argv) + plugin_class(settings).main(argv) # Print help information if no commands match. else: http://git-wip-us.apache.org/repos/asf/mesos/blob/1cdd962b/src/cli_new/bin/settings.py ---------------------------------------------------------------------- diff --git a/src/cli_new/bin/settings.py b/src/cli_new/bin/settings.py new file mode 100644 index 0000000..2f6162e --- /dev/null +++ b/src/cli_new/bin/settings.py @@ -0,0 +1,71 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +This file defines the default settings of the mesos-cli. It also takes care +of updating the default configuration from reading environment variables or +parsing a configuration file. +""" + +import json +import os +import sys + +from cli.exceptions import CLIException + + +# There is no version module included in this package. However, +# when creating an executable using pyinstaller, a version.py +# file will be autogenerated and inserted into the PYTHONPATH. +# When this happens we import it to set the VERSION. +try: + # pylint: disable=F0401,W0611 + from version import VERSION +except Exception: + VERSION = "Development" + + +# The builtin plugins. +PLUGINS = [] + + +# 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))) + + try: + CONFIG_DATA = json.load(CONFIG_FILE) + except Exception as exception: + raise CLIException("Error loading config file as JSON: {error}" + .format(error=exception)) + + 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 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(":"))
