blob: ff47f7196352c4e17a328401d1d621ce23374eed [file]
#!/usr/bin/env python
# coding=utf-8
# Copyright [2020] [Apache Software Foundation]
#
# Licensed 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.
import os
import click
from marvin_python_toolbox.utils.misc import package_to_name, create_tmp_marvin_folder
from marvin_python_toolbox.utils.misc import retrieve_tmp_info
from marvin_python_toolbox.utils.config import parse_ini
from marvin_python_toolbox.utils.config import read_cli_conf, generate_default_conf
from marvin_python_toolbox.utils.docker import search_engine_container
from marvin_python_toolbox.utils.docker import search_engine_images
from marvin_python_toolbox.utils.docker import create_engine_image
from marvin_python_toolbox.utils.docker import create_daemon_container
from marvin_python_toolbox.management.engine import cli as cli_engine
from marvin_python_toolbox.management.notebook import cli as cli_notebook
from marvin_python_toolbox.management.edit import cli as cli_edit
from marvin_python_toolbox.management.test import cli as cli_test
from marvin_python_toolbox.management.generate import cli as cli_generate
EXCLUDE_BY_TYPE = {
'toolbox': ['engine-dryrun', 'engine-grpcserver', 'engine-httpserver', 'notebook',
'lab', 'project-export', 'engine-logs', 'edit-metadata', 'test', 'test-tdd',
'test-tox', 'engine-bumpversion', 'benchmark', 'benchmark-plot', 'engine',
'data', 'push', 'stop', 'clone', 'kube-deployment'],
'engine': ['project-import', 'setup']
}
ENVIRONMENT_VARIABLES = {
'MARVIN_HOME': "{0}/marvin".format(os.environ['HOME']),
'MARVIN_DATA_PATH': "{0}/marvin/data".format(os.environ['HOME'])
}
def _define_environ():
for var in ENVIRONMENT_VARIABLES.keys():
if os.environ.get(var) is None:
os.environ[var] = ENVIRONMENT_VARIABLES[var]
def _create_folders():
_conf_folder = os.path.join(os.environ['MARVIN_DATA_PATH'], '.conf')
_artifacts_folder = os.path.join(os.environ['MARVIN_DATA_PATH'], '.artifacts')
_exports_folder = os.path.join(os.environ['MARVIN_DATA_PATH'], 'exports')
_paths_list = [os.environ['MARVIN_HOME'], os.environ['MARVIN_DATA_PATH'],
_exports_folder, _conf_folder, _artifacts_folder]
for path in _paths_list:
if not os.path.exists(path):
os.makedirs(path)
def _read_config():
filepath = os.path.join(os.environ['MARVIN_DATA_PATH'], '.conf', 'cli_conf.json')
if not os.path.isfile(filepath):
conf = generate_default_conf()
else:
conf = read_cli_conf()
return conf
sigh = """___ ___ _ _____ _ _____
| \/ | (_) / __ \| | |_ _|
| . . | __ _ _ ____ ___ _ __ | / \/| | | |
| |\/| |/ _` | '__\ \ / / | '_ \ | | | | | |
| | | | (_| | | \ V /| | | | | | \__/\| |_____| |_
\_| |_/\__,_|_| \_/ |_|_| |_| \____/\_____/\___/\n\n"""
engine_name = None
exclude = None
print(sigh)
_define_environ()
_create_folders()
create_tmp_marvin_folder()
engine = retrieve_tmp_info('engine')
if engine is not None:
exclude = EXCLUDE_BY_TYPE['engine']
engine_name = engine
print("[+] engine mode - {}".format(engine_name))
print("\n")
else:
exclude = EXCLUDE_BY_TYPE['toolbox']
print("[+] toolbox mode\n")
config = _read_config()
@click.group('main')
@click.pass_context
def cli(ctx):
ctx.obj = {
'engine_name': engine_name,
'editor': config['editor'],
'default_host': config['default_host'],
'executor_url': config['executor_url']
}
commands = {}
commands.update(cli_engine.commands)
commands.update(cli_notebook.commands)
commands.update(cli_edit.commands)
commands.update(cli_test.commands)
commands.update(cli_generate.commands)
for name, command in commands.items():
if name not in exclude:
cli.add_command(command, name=name)
cli()