diff --git a/cli/dcoscli/data/config-schema/subcommand.json b/cli/dcoscli/data/config-schema/subcommand.json deleted file mode 100644 index d751b9a..0000000 --- a/cli/dcoscli/data/config-schema/subcommand.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "$schema": "http://json-schema.org/schema#", - "type": "object", - "properties": { - "pip_find_links": { - "type": "string", - "title": "Location for finding packages", - "description": "If a url or path to an html file, then parse for links to archives. If a local path or file:// url that’s a directory, then look for archives in the directory listing." - } - }, - "additionalProperties": false -} diff --git a/cli/dcoscli/subcommand/__init__.py b/cli/dcoscli/subcommand/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/cli/dcoscli/subcommand/main.py b/cli/dcoscli/subcommand/main.py deleted file mode 100644 index 5e35ddc..0000000 --- a/cli/dcoscli/subcommand/main.py +++ /dev/null @@ -1,183 +0,0 @@ -"""Install and manage DCOS CLI subcommands - -Usage: - dcos subcommand --config-schema - dcos subcommand --info - dcos subcommand info - dcos subcommand install - dcos subcommand list - dcos subcommand uninstall - -Options: - --help Show this screen - --info Show a short description of this subcommand - --version Show version - -Positional arguments: - The subcommand package wheel - The name of the subcommand package -""" -import json -import os - -import dcoscli -import docopt -import pkg_resources -import pkginfo -from dcos.api import (cmds, config, constants, emitting, errors, options, - subcommand, util) - -logger = util.get_logger(__name__) -emitter = emitting.FlatEmitter() - - -def main(): - err = util.configure_logger_from_environ() - if err is not None: - emitter.publish(err) - return 1 - - args = docopt.docopt( - __doc__, - version='dcos-subcommand version {}'.format(dcoscli.version)) - - returncode, err = cmds.execute(_cmds(), args) - if err is not None: - emitter.publish(err) - emitter.publish(options.make_generic_usage_message(__doc__)) - return 1 - - return returncode - - -def _cmds(): - """ - :returns: all the supported commands - :rtype: dcos.api.cmds.Command - """ - - return [ - cmds.Command( - hierarchy=['subcommand', 'install'], - arg_keys=[''], - function=_install), - - cmds.Command( - hierarchy=['subcommand', 'uninstall'], - arg_keys=[''], - function=_uninstall), - - cmds.Command( - hierarchy=['subcommand', 'list'], - arg_keys=[], - function=_list), - - cmds.Command( - hierarchy=['subcommand'], - arg_keys=['--config-schema', '--info'], - function=_subcommand), - ] - - -def _subcommand(config_schema, info): - """ - :returns: Process status - :rtype: int - """ - - if config_schema: - schema = json.loads( - pkg_resources.resource_string( - 'dcoscli', - 'data/config-schema/subcommand.json').decode('utf-8')) - emitter.publish(schema) - elif info: - _info() - else: - emitter.publish(options.make_generic_usage_message(__doc__)) - return 1 - - return 0 - - -def _info(): - """ - :returns: the process return code - :rtype: int - """ - - emitter.publish(__doc__.split('\n')[0]) - return 0 - - -def _list(): - """ - :returns: the process return code - :rtype: int - """ - - emitter.publish(subcommand.distributions(util.dcos_path())) - - return 0 - - -def _install(package): - """ - :returns: the process return code - :rtype: int - """ - - dcos_config = config.load_from_path(os.environ[constants.DCOS_CONFIG_ENV]) - - pip_operation = [package] - if 'subcommand.pip_find_links' in dcos_config: - pip_operation.append( - '--find-links {}'.format(dcos_config['subcommand.pip_find_links'])) - - distribution_name, err = _distribution_name(package) - if err is not None: - emitter.publish(err) - emitter.publish(errors.DefaultError("Note: To install only the \ -subcommand for a package, run `dcos package install --cli` instead")) - return 1 - - env_dir = os.path.join(subcommand.package_dir(distribution_name), - constants.DCOS_SUBCOMMAND_VIRTUALENV_SUBDIR) - - err = subcommand.install_with_pip( - distribution_name, - env_dir, - pip_operation) - if err is not None: - emitter.publish(err) - return 1 - - return 0 - - -def _uninstall(package_name): - """ - :returns: the process return code - :rtype: int - """ - - subcommand.uninstall(package_name) - - return 0 - - -def _distribution_name(package_path): - """ - :returns: the distribution's name - :rtype: (str, dcos.api.errors.Error) - """ - - try: - return (pkginfo.Wheel(package_path).name, None) - except ValueError as error: - logger.error('Failed to read wheel (%s): %r', package_path, error) - return ( - None, - errors.DefaultError( - 'Failed to read file: {}'.format(error)) - ) diff --git a/cli/setup.py b/cli/setup.py index 8564c03..6419e8b 100644 --- a/cli/setup.py +++ b/cli/setup.py @@ -92,7 +92,6 @@ setup( 'dcos-config=dcoscli.config.main:main', 'dcos-marathon=dcoscli.marathon.main:main', 'dcos-package=dcoscli.package.main:main', - 'dcos-subcommand=dcoscli.subcommand.main:main', ], }, diff --git a/cli/tests/data/dcos.toml b/cli/tests/data/dcos.toml index 9e4e8e5..b6217bf 100644 --- a/cli/tests/data/dcos.toml +++ b/cli/tests/data/dcos.toml @@ -1,8 +1,6 @@ [core] reporting = false email = "test@mail.com" -[subcommand] -pip_find_links = "../dist" [marathon] host = "localhost" port = 8080 diff --git a/cli/tests/integrations/cli/test_config.py b/cli/tests/integrations/cli/test_config.py index 9b4cc9c..225439d 100644 --- a/cli/tests/integrations/cli/test_config.py +++ b/cli/tests/integrations/cli/test_config.py @@ -65,7 +65,6 @@ marathon.port=8080 package.cache=tmp/cache package.sources=['git://github.com/mesosphere/universe.git', \ 'https://github.com/mesosphere/universe/archive/master.zip'] -subcommand.pip_find_links=../dist """ assert_command(['dcos', 'config', 'show'], stdout=stdout, diff --git a/cli/tests/integrations/cli/test_dcos.py b/cli/tests/integrations/cli/test_dcos.py index 3fca50f..db25795 100644 --- a/cli/tests/integrations/cli/test_dcos.py +++ b/cli/tests/integrations/cli/test_dcos.py @@ -21,7 +21,6 @@ Available DCOS commands: \thelp \tDisplay command line usage information \tmarathon \tDeploy and manage applications on the DCOS \tpackage \tInstall and manage DCOS software packages -\tsubcommand \tInstall and manage DCOS CLI subcommands Get detailed command description with 'dcos --help'. """.encode('utf-8') diff --git a/cli/tests/integrations/cli/test_help.py b/cli/tests/integrations/cli/test_help.py index 91eae05..040a108 100644 --- a/cli/tests/integrations/cli/test_help.py +++ b/cli/tests/integrations/cli/test_help.py @@ -40,7 +40,6 @@ Available DCOS commands: \thelp \tDisplay command line usage information \tmarathon \tDeploy and manage applications on the DCOS \tpackage \tInstall and manage DCOS software packages -\tsubcommand \tInstall and manage DCOS CLI subcommands Get detailed command description with 'dcos --help'. """.encode('utf-8') diff --git a/cli/tests/integrations/cli/test_package.py b/cli/tests/integrations/cli/test_package.py index 1f2cf13..05d40e4 100644 --- a/cli/tests/integrations/cli/test_package.py +++ b/cli/tests/integrations/cli/test_package.py @@ -258,8 +258,7 @@ def test_uninstall_subcommand(): _install_helloworld() _uninstall_helloworld() - assert_command(['dcos', 'subcommand', 'list'], - stdout=b'[]\n') + assert_command(['dcos', 'package', 'list-installed'], stdout=b'[]\n') def test_uninstall_cli(): diff --git a/cli/tests/integrations/cli/test_subcommand.py b/cli/tests/integrations/cli/test_subcommand.py deleted file mode 100644 index 503972b..0000000 --- a/cli/tests/integrations/cli/test_subcommand.py +++ /dev/null @@ -1,120 +0,0 @@ -import json -import os - -import pytest -from common import exec_command - - -@pytest.fixture -def package(): - return os.environ['DCOS_TEST_WHEEL'] - - -def test_help(): - returncode, stdout, stderr = exec_command(['dcos', 'subcommand', '--help']) - - assert returncode == 0 - assert stdout == b"""Install and manage DCOS CLI subcommands - -Usage: - dcos subcommand --config-schema - dcos subcommand --info - dcos subcommand info - dcos subcommand install - dcos subcommand list - dcos subcommand uninstall - -Options: - --help Show this screen - --info Show a short description of this subcommand - --version Show version - -Positional arguments: - The subcommand package wheel - The name of the subcommand package -""" - assert stderr == b'' - - -def test_info(): - returncode, stdout, stderr = exec_command(['dcos', 'subcommand', '--info']) - - assert returncode == 0 - assert stdout == b'Install and manage DCOS CLI subcommands\n' - assert stderr == b'' - - -def test_list_empty_subcommand(): - _list_subcommands(0) - - -def test_install_package(package): - _install_subcommand(package) - _list_subcommands(1) - _uninstall_subcommand('dcos-helloworld') - - -def test_install_existing_package(package): - _install_subcommand(package) - _install_subcommand(package) - _list_subcommands(1) - _uninstall_subcommand('dcos-helloworld') - - -def test_list_subcommand(package): - _install_subcommand(package) - _list_subcommands(1) - _uninstall_subcommand('dcos-helloworld') - - -def test_uninstall_missing_subcommand(package): - _uninstall_subcommand('missing-package') - - -def test_uninstall_helloworld(package): - _install_subcommand(package) - _list_subcommands(1) - _uninstall_subcommand('dcos-helloworld') - _list_subcommands(0) - - -def test_missing_wheel(): - returncode, stdout, stderr = exec_command( - ['dcos', 'subcommand', 'install', 'missing_file.whl']) - - assert returncode == 1 - assert stdout == b'' - assert stderr.decode('utf-8').startswith( - 'Failed to read file: No such file: ') - - _list_subcommands(0) - - -def _list_subcommands(size): - returncode, stdout, stderr = exec_command(['dcos', 'subcommand', 'list']) - - result = json.loads(stdout.decode('utf-8')) - - assert returncode == 0 - assert len(result) == size - assert stderr == b'' - - return result - - -def _install_subcommand(package): - returncode, stdout, stderr = exec_command( - ['dcos', 'subcommand', 'install', package]) - - assert returncode == 0 - assert stdout == b'' - assert stderr == b'' - - -def _uninstall_subcommand(package): - returncode, stdout, stderr = exec_command( - ['dcos', 'subcommand', 'uninstall', package]) - - assert returncode == 0 - assert stdout == b'' - assert stderr == b''