Move modules from dcos.api to dcos

This commit is contained in:
José Armando García Sancio
2015-04-29 21:44:53 -07:00
parent 2de5c353e3
commit 5a340cba96
33 changed files with 137 additions and 111 deletions

View File

@@ -6,7 +6,7 @@ import uuid
import dcoscli import dcoscli
import requests import requests
import rollbar import rollbar
from dcos.api import util from dcos import util
from dcoscli.constants import (ROLLBAR_SERVER_POST_KEY, from dcoscli.constants import (ROLLBAR_SERVER_POST_KEY,
SEGMENT_IO_CLI_ERROR_EVENT, SEGMENT_IO_CLI_ERROR_EVENT,
SEGMENT_IO_CLI_EVENT, SEGMENT_IO_WRITE_KEY_DEV, SEGMENT_IO_CLI_EVENT, SEGMENT_IO_WRITE_KEY_DEV,

View File

@@ -31,8 +31,8 @@ import docopt
import pkg_resources import pkg_resources
import six import six
import toml import toml
from dcos.api import (cmds, config, constants, emitting, errors, http, from dcos import (cmds, config, constants, emitting, errors, http, jsonitem,
jsonitem, options, subcommand, util) options, subcommand, util)
from dcoscli.analytics import segment_identify from dcoscli.analytics import segment_identify
emitter = emitting.FlatEmitter() emitter = emitting.FlatEmitter()
@@ -92,7 +92,7 @@ def compare_validations(toml_config_pre, toml_config_post):
def _cmds(): def _cmds():
""" """
:returns: all the supported commands :returns: all the supported commands
:rtype: list of dcos.api.cmds.Command :rtype: list of dcos.cmds.Command
""" """
return [ return [
@@ -360,9 +360,9 @@ def _generate_choice_msg(name, value):
:param name: name of the property :param name: name of the property
:type name: str :type name: str
:param value: dictionary for the value :param value: dictionary for the value
:type value: dcos.api.config.Toml :type value: dcos.config.Toml
:returns: an error message for top level properties :returns: an error message for top level properties
:rtype: dcos.api.errors.Error :rtype: dcos.errors.Error
""" """
message = ("Property {!r} doesn't fully specify a value - " message = ("Property {!r} doesn't fully specify a value - "
@@ -401,7 +401,7 @@ def _get_config_schema(command):
:param command: the subcommand name :param command: the subcommand name
:type command: str :type command: str
:returns: the subcommand's configuration schema :returns: the subcommand's configuration schema
:rtype: (dict, dcos.api.errors.Error) :rtype: (dict, dcos.errors.Error)
""" """
# core.* config variables are special. They're valid, but don't # core.* config variables are special. They're valid, but don't
@@ -448,7 +448,7 @@ def _parse_array_item(name, value):
:param value: the value to parse :param value: the value to parse
:type value: str :type value: str
:returns: the parsed value as an array with one element :returns: the parsed value as an array with one element
:rtype: (list of any, dcos.api.errors.Error) where any is string, int, :rtype: (list of any, dcos.errors.Error) where any is string, int,
float, bool, array or dict float, bool, array or dict
""" """

View File

@@ -12,7 +12,7 @@ Options:
import dcoscli import dcoscli
import docopt import docopt
import futures import futures
from dcos.api import cmds, emitting, options, subcommand, util from dcos import cmds, emitting, options, subcommand, util
emitter = emitting.FlatEmitter() emitter = emitting.FlatEmitter()
logger = util.get_logger(__name__) logger = util.get_logger(__name__)
@@ -40,7 +40,7 @@ def main():
def _cmds(): def _cmds():
""" """
:returns: All of the supported commands :returns: All of the supported commands
:rtype: list of dcos.api.cmds.Command :rtype: list of dcos.cmds.Command
""" """
return [ return [

View File

@@ -37,7 +37,7 @@ from subprocess import PIPE, Popen
import dcoscli import dcoscli
import docopt import docopt
from dcos.api import auth, constants, emitting, errors, http, subcommand, util from dcos import auth, constants, emitting, errors, http, subcommand, util
from dcoscli import analytics from dcoscli import analytics
emitter = emitting.FlatEmitter() emitter = emitting.FlatEmitter()

View File

@@ -60,7 +60,7 @@ import time
import dcoscli import dcoscli
import docopt import docopt
import pkg_resources import pkg_resources
from dcos.api import cmds, emitting, errors, jsonitem, marathon, options, util from dcos import cmds, emitting, errors, jsonitem, marathon, options, util
logger = util.get_logger(__name__) logger = util.get_logger(__name__)
emitter = emitting.FlatEmitter() emitter = emitting.FlatEmitter()
@@ -88,7 +88,7 @@ def main():
def _cmds(): def _cmds():
""" """
:returns: all the supported commands :returns: all the supported commands
:rtype: dcos.api.cmds.Command :rtype: dcos.cmds.Command
""" """
return [ return [
@@ -752,7 +752,7 @@ def _update_from_stdin(app_id, force):
def _calculate_version(client, app_id, version): def _calculate_version(client, app_id, version):
""" """
:param client: Marathon client :param client: Marathon client
:type client: dcos.api.marathon.Client :type client: dcos.marathon.Client
:param app_id: The ID of the application :param app_id: The ID of the application
:type app_id: str :type app_id: str
:param version: Relative or absolute version or None :param version: Relative or absolute version or None

View File

@@ -50,7 +50,7 @@ import json
import dcoscli import dcoscli
import docopt import docopt
import pkg_resources import pkg_resources
from dcos.api import (cmds, emitting, errors, marathon, options, package, from dcos import (cmds, emitting, errors, marathon, options, package,
subcommand, util) subcommand, util)
logger = util.get_logger(__name__) logger = util.get_logger(__name__)
@@ -80,7 +80,7 @@ def main():
def _cmds(): def _cmds():
""" """
:returns: All of the supported commands :returns: All of the supported commands
:rtype: dcos.api.cmds.Command :rtype: dcos.cmds.Command
""" """
return [ return [

View File

@@ -4,7 +4,7 @@ from functools import wraps
import dcoscli.analytics import dcoscli.analytics
import requests import requests
import rollbar import rollbar
from dcos.api import constants, util from dcos import constants, util
from dcoscli.analytics import _base_properties from dcoscli.analytics import _base_properties
from dcoscli.config.main import main as config_main from dcoscli.config.main import main as config_main
from dcoscli.constants import (ROLLBAR_SERVER_POST_KEY, from dcoscli.constants import (ROLLBAR_SERVER_POST_KEY,

View File

@@ -1,7 +1,7 @@
import os import os
import webbrowser import webbrowser
from dcos.api import auth, constants, util from dcos import auth, constants, util
from dcoscli.main import main from dcoscli.main import main
from mock import Mock, patch from mock import Mock, patch
@@ -15,7 +15,7 @@ def test_no_browser_auth():
def test_when_authenticated(): def test_when_authenticated():
with patch('dcos.api.auth.force_auth'): with patch('dcos.auth.force_auth'):
_mock_dcos_run([util.which('dcos')], True) _mock_dcos_run([util.which('dcos')], True)
assert auth.force_auth.call_count == 0 assert auth.force_auth.call_count == 0

View File

@@ -3,7 +3,7 @@ import os
import dcoscli.constants as cli_constants import dcoscli.constants as cli_constants
import six import six
from dcos.api import constants from dcos import constants
import pytest import pytest
from common import assert_command, exec_command from common import assert_command, exec_command

View File

@@ -1,6 +1,6 @@
import os import os
from dcos.api import constants from dcos import constants
from common import assert_command, exec_command from common import assert_command, exec_command

View File

@@ -2,7 +2,7 @@ import json
import os import os
import six import six
from dcos.api import subcommand from dcos import subcommand
from common import assert_command, exec_command from common import assert_command, exec_command

View File

View File

@@ -4,7 +4,7 @@ import uuid
import pkg_resources import pkg_resources
import toml import toml
from dcos.api import config, constants, emitting, errors, http, jsonitem, util from dcos import config, constants, emitting, errors, http, jsonitem, util
from six import iteritems, moves from six import iteritems, moves
from oauth2client import client from oauth2client import client
@@ -23,7 +23,7 @@ def _authorize():
"""Create OAuth flow and authorize user """Create OAuth flow and authorize user
:return: Tuple of credentials dict end Error :return: Tuple of credentials dict end Error
:rtype: (dict, dcos.api.errors.Error) :rtype: (dict, dcos.errors.Error)
""" """
try: try:
flow = client.OAuth2WebServerFlow( flow = client.OAuth2WebServerFlow(

View File

@@ -1,6 +1,6 @@
import collections import collections
from dcos.api import errors from dcos import errors
Command = collections.namedtuple( Command = collections.namedtuple(
'Command', 'Command',

View File

@@ -11,7 +11,7 @@ import sys
import pager import pager
import pygments import pygments
import six import six
from dcos.api import constants, errors, util from dcos import constants, errors, util
from pygments.formatters import Terminal256Formatter from pygments.formatters import Terminal256Formatter
from pygments.lexers import JsonLexer from pygments.lexers import JsonLexer
@@ -67,7 +67,7 @@ def print_handler(event):
"""Default handler for printing event to stdout. """Default handler for printing event to stdout.
:param event: event to emit to stdout :param event: event to emit to stdout
:type event: str, dict, list, or dcos.api.errors.Error :type event: str, dict, list, or dcos.errors.Error
""" """
pager_command = os.environ.get(constants.DCOS_PAGER_COMMAND_ENV) pager_command = os.environ.get(constants.DCOS_PAGER_COMMAND_ENV)
@@ -98,7 +98,7 @@ def _process_json(event, pager_command):
"""Conditionally highlights the supplied JSON value. """Conditionally highlights the supplied JSON value.
:param event: event to emit to stdout :param event: event to emit to stdout
:type event: str, dict, list, or dcos.api.errors.Error :type event: str, dict, list, or dcos.errors.Error
:returns: String representation of the supplied JSON value, :returns: String representation of the supplied JSON value,
possibly syntax-highlighted. possibly syntax-highlighted.
:rtype: str :rtype: str

View File

@@ -1,6 +1,6 @@
import requests import requests
from dcos.api import util from dcos import util
from dcos.api.errors import DefaultError, Error from dcos.errors import DefaultError, Error
logger = util.get_logger(__name__) logger = util.get_logger(__name__)

View File

@@ -1,7 +1,7 @@
import collections import collections
import json import json
from dcos.api import errors from dcos import errors
def parse_json_item(json_item, schema): def parse_json_item(json_item, schema):

View File

@@ -1,7 +1,7 @@
import json import json
from dcos.api import http, util from dcos import http, util
from dcos.api.errors import DefaultError, Error from dcos.errors import DefaultError, Error
try: try:
from urllib import quote from urllib import quote
@@ -17,7 +17,7 @@ def create_client(config=None):
:param config: configuration dictionary :param config: configuration dictionary
:type config: config.Toml :type config: config.Toml
:returns: Marathon client :returns: Marathon client
:rtype: dcos.api.marathon.Client :rtype: dcos.marathon.Client
""" """
if config is None: if config is None:
config = util.get_config() config = util.get_config()
@@ -435,7 +435,7 @@ class Client(object):
:param app_id: the id of the application to restart :param app_id: the id of the application to restart
:type app_id: str :type app_id: str
:returns: a list of tasks :returns: a list of tasks
:rtype: (list of dict, dcos.api.errors.Error) :rtype: (list of dict, dcos.errors.Error)
""" """
url = self._create_url('v2/tasks') url = self._create_url('v2/tasks')
@@ -461,7 +461,7 @@ class Client(object):
:param task_id: the id of the task :param task_id: the id of the task
:type task_id: str :type task_id: str
:returns: a tasks :returns: a tasks
:rtype: (dict, dcos.api.errors.Error) :rtype: (dict, dcos.errors.Error)
""" """
url = self._create_url('v2/tasks') url = self._create_url('v2/tasks')

View File

@@ -14,7 +14,7 @@ import git
import portalocker import portalocker
import pystache import pystache
import six import six
from dcos.api import constants, emitting, errors, marathon, subcommand, util from dcos import constants, emitting, errors, marathon, subcommand, util
from six.moves import urllib from six.moves import urllib
@@ -452,7 +452,7 @@ def search(query, cfg):
:param query: The search term :param query: The search term
:type query: str :type query: str
:param cfg: Configuration dictionary :param cfg: Configuration dictionary
:type cfg: dcos.api.config.Toml :type cfg: dcos.config.Toml
:rtype: (list of IndexEntries, Error) :rtype: (list of IndexEntries, Error)
""" """
@@ -567,7 +567,7 @@ def resolve_package(package_name, config):
:param package_name: The name of the package to resolve :param package_name: The name of the package to resolve
:type package_name: str :type package_name: str
:param config: Configuration dictionary :param config: Configuration dictionary
:type config: dcos.api.config.Toml :type config: dcos.config.Toml
:returns: The named package, if found :returns: The named package, if found
:rtype: (Package, Error) :rtype: (Package, Error)
""" """
@@ -588,7 +588,7 @@ def registries(config):
"""Returns configured cached package registries. """Returns configured cached package registries.
:param config: Configuration dictionary :param config: Configuration dictionary
:type config: dcos.api.config.Toml :type config: dcos.config.Toml
:returns: The list of registries, in resolution order :returns: The list of registries, in resolution order
:rtype: ([Registry], Error) :rtype: ([Registry], Error)
""" """
@@ -605,7 +605,7 @@ def list_sources(config):
"""List configured package sources. """List configured package sources.
:param config: Configuration dictionary :param config: Configuration dictionary
:type config: dcos.api.config.Toml :type config: dcos.config.Toml
:returns: The list of sources, in resolution order :returns: The list of sources, in resolution order
:rtype: (list of Source, Error) :rtype: (list of Source, Error)
""" """
@@ -677,7 +677,7 @@ def update_sources(config, validate=False):
"""Overwrites the local package cache with the latest source data. """Overwrites the local package cache with the latest source data.
:param config: Configuration dictionary :param config: Configuration dictionary
:type config: dcos.api.config.Toml :type config: dcos.config.Toml
:returns: Error, if any. :returns: Error, if any.
:rtype: list of Error :rtype: list of Error
""" """
@@ -783,7 +783,7 @@ class Source:
"""Returns the file system path to this source's local cache. """Returns the file system path to this source's local cache.
:param config: Configuration dictionary :param config: Configuration dictionary
:type config: dcos.api.config.Toml :type config: dcos.config.Toml
:returns: Path to this source's local cache on disk :returns: Path to this source's local cache on disk
:rtype: str or None :rtype: str or None
""" """
@@ -1145,7 +1145,7 @@ class Package():
:param user_options: package parameters :param user_options: package parameters
:type user_options: dict :type user_options: dict
:returns: a dictionary with the user supplied options :returns: a dictionary with the user supplied options
:rtype: (dict, dcos.api.errors.Error) :rtype: (dict, dcos.errors.Error)
""" """
if user_options is None: if user_options is None:

View File

@@ -5,7 +5,7 @@ import os
import shutil import shutil
import subprocess import subprocess
from dcos.api import constants, errors, util from dcos import constants, errors, util
logger = util.get_logger(__name__) logger = util.get_logger(__name__)
@@ -18,7 +18,7 @@ def command_executables(subcommand, dcos_path):
:param dcos_path: path to the dcos cli directory :param dcos_path: path to the dcos cli directory
:type dcos_path: str :type dcos_path: str
:returns: the dcos program path :returns: the dcos program path
:rtype: (str, dcos.api.errors.Error) :rtype: (str, dcos.errors.Error)
""" """
executables = [ executables = [
@@ -235,7 +235,7 @@ def _install_env(pkg, version, options):
:param options: package parameters :param options: package parameters
:type options: dict :type options: dict
:returns: an error if the subcommand failed; None otherwise :returns: an error if the subcommand failed; None otherwise
:rtype: dcos.api.errors.Error :rtype: dcos.errors.Error
""" """
pkg_dir = package_dir(pkg.name()) pkg_dir = package_dir(pkg.name())
@@ -268,7 +268,7 @@ def install(pkg, version, options):
:param options: package parameters :param options: package parameters
:type options: dict :type options: dict
:returns: an error if the subcommand failed; None otherwise :returns: an error if the subcommand failed; None otherwise
:rtype: dcos.api.errors.Error :rtype: dcos.errors.Error
""" """
pkg_dir = package_dir(pkg.name()) pkg_dir = package_dir(pkg.name())
@@ -338,7 +338,7 @@ def install_with_pip(
:param requirements: the list of pip requirements :param requirements: the list of pip requirements
:type requirements: list of str :type requirements: list of str
:returns: an Error if it failed to install the package; None otherwise :returns: an Error if it failed to install the package; None otherwise
:rtype: dcos.api.errors.Error :rtype: dcos.errors.Error
""" """
bin_directory = os.path.join(util.dcos_path(), BIN_DIRECTORY) bin_directory = os.path.join(util.dcos_path(), BIN_DIRECTORY)
@@ -408,7 +408,7 @@ def _generic_error(package_name):
:param package: package name :param package: package name
:type: str :type: str
:returns: generic error when installing package :returns: generic error when installing package
:rtype: dcos.api.errors.Error :rtype: dcos.errors.Error
""" """
return errors.DefaultError( return errors.DefaultError(

View File

@@ -11,7 +11,7 @@ import tempfile
import jsonschema import jsonschema
import pystache import pystache
import six import six
from dcos.api import config, constants, errors from dcos import config, constants, errors
@contextlib.contextmanager @contextlib.contextmanager
@@ -141,7 +141,7 @@ def configure_logger_from_environ():
:returns: An Error if we were unable to configure logging from the :returns: An Error if we were unable to configure logging from the
environment; None otherwise environment; None otherwise
:rtype: dcos.api.errors.DefaultError :rtype: dcos.errors.DefaultError
""" """
return configure_logger(os.environ.get(constants.DCOS_LOG_LEVEL_ENV)) return configure_logger(os.environ.get(constants.DCOS_LOG_LEVEL_ENV))
@@ -153,7 +153,7 @@ def configure_logger(log_level):
:param log_level: Log level for configuring logging :param log_level: Log level for configuring logging
:type log_level: str :type log_level: str
:returns: An Error if we were unable to configure logging; None otherwise :returns: An Error if we were unable to configure logging; None otherwise
:rtype: dcos.api.errors.DefaultError :rtype: dcos.errors.DefaultError
""" """
if log_level is None: if log_level is None:
logging.disable(logging.CRITICAL) logging.disable(logging.CRITICAL)

View File

@@ -1,86 +1,112 @@
API Documentation API Documentation
================= =================
The :mod:`dcos.api.cmds` Module The :mod:`dcos.auth` Module
--------------------------------- ---------------------------
.. automodule:: dcos.api.cmds .. automodule:: dcos.auth
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
:inherited-members: :inherited-members:
The :mod:`dcos.api.config` Module The :mod:`dcos.cmds` Module
--------------------------------- ---------------------------
.. automodule:: dcos.api.config .. automodule:: dcos.cmds
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
:inherited-members: :inherited-members:
The :mod:`dcos.api.constants` Module The :mod:`dcos.config` Module
------------------------------------ -----------------------------
.. automodule:: dcos.api.constants .. automodule:: dcos.config
:members:
:undoc-members:
:show-inheritance:
The :mod:`dcos.api.emitting` Module
------------------------------------
.. automodule:: dcos.api.emitting
:members:
:undoc-members:
:show-inheritance:
The :mod:`dcos.api.errors` Module
------------------------------------
.. automodule:: dcos.api.errors
:members:
:undoc-members:
:show-inheritance:
The :mod:`dcos.api.jsonitem` Module
------------------------------------
.. automodule:: dcos.api.jsonitem
:members:
:undoc-members:
:show-inheritance:
The :mod:`dcos.api.marathon` Module
------------------------------------
.. automodule:: dcos.api.marathon
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
:inherited-members: :inherited-members:
The :mod:`dcos.api.options` Module The :mod:`dcos.constants` Module
------------------------------------ --------------------------------
.. automodule:: dcos.api.options .. automodule:: dcos.constants
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
The :mod:`dcos.api.package` Module The :mod:`dcos.emitting` Module
------------------------------------ -------------------------------
.. automodule:: dcos.api.package .. automodule:: dcos.emitting
:members:
:undoc-members:
:show-inheritance:
The :mod:`dcos.errors` Module
-----------------------------
.. automodule:: dcos.errors
:members:
:undoc-members:
:show-inheritance:
The :mod:`dcos.http` Module
-----------------------------
.. automodule:: dcos.http
:members:
:undoc-members:
:show-inheritance:
The :mod:`dcos.jsonitem` Module
-------------------------------
.. automodule:: dcos.jsonitem
:members:
:undoc-members:
:show-inheritance:
The :mod:`dcos.marathon` Module
-------------------------------
.. automodule:: dcos.marathon
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:
:inherited-members: :inherited-members:
The :mod:`dcos.api.util` Module The :mod:`dcos.options` Module
------------------------------------ ------------------------------
.. automodule:: dcos.api.util .. automodule:: dcos.options
:members:
:undoc-members:
:show-inheritance:
The :mod:`dcos.package` Module
------------------------------
.. automodule:: dcos.package
:members:
:undoc-members:
:show-inheritance:
:inherited-members:
The :mod:`dcos.subcommand` Module
------------------------------
.. automodule:: dcos.subcommand
:members:
:undoc-members:
:show-inheritance:
:inherited-members:
The :mod:`dcos.util` Module
---------------------------
.. automodule:: dcos.util
:members: :members:
:undoc-members: :undoc-members:
:show-inheritance: :show-inheritance:

View File

@@ -1,4 +1,4 @@
from dcos.api import cmds, errors from dcos import cmds, errors
import pytest import pytest

View File

@@ -1,4 +1,4 @@
from dcos.api import config from dcos import config
import pytest import pytest

View File

@@ -1,4 +1,4 @@
from dcos.api import errors, jsonitem from dcos import errors, jsonitem
import pytest import pytest

View File

@@ -1,4 +1,4 @@
from dcos.api import options from dcos import options
def test_extend_usage_docopt(): def test_extend_usage_docopt():

View File

@@ -1,6 +1,6 @@
import collections import collections
from dcos.api import package from dcos import package
import pytest import pytest

View File

@@ -1,4 +1,4 @@
from dcos.api import subcommand from dcos import subcommand
def test_noun(): def test_noun():

View File

@@ -1,4 +1,4 @@
from dcos.api import util from dcos import util
def test_render_mustache_json(): def test_render_mustache_json():