示例#1
0
def test_entrypoint(ap_cls_mock, add_commands_mock, dispatch_mock):

    entrypoint = argh.EntryPoint('my cool app')

    # no commands

    with pytest.raises(argh.exceptions.DispatchingError) as excinfo:
        entrypoint()
    assert excinfo.exconly().endswith(
        'DispatchingError: no commands for entry point "my cool app"')

    mocked_parser = Mock()
    ap_cls_mock.return_value = mocked_parser

    # a single command

    @entrypoint
    def greet():
        return 'hello'

    entrypoint()

    assert add_commands_mock.called
    add_commands_mock.assert_called_with(mocked_parser, [greet])
    assert dispatch_mock.called
    dispatch_mock.assert_called_with(mocked_parser)

    # multiple commands

    add_commands_mock.reset_mock()
    dispatch_mock.reset_mock()

    @entrypoint
    def hit():
        return 'knight with a chicken'

    entrypoint()

    assert add_commands_mock.called
    add_commands_mock.assert_called_with(mocked_parser, [greet, hit])
    assert dispatch_mock.called
    dispatch_mock.assert_called_with(mocked_parser)
示例#2
0
INIT_EXISTS = argh.CommandError('Configuration already exists. Use --reset'
                                ' to overwrite.')
NO_INIT = argh.CommandError('Not initialized')
ALREADY_INITIALIZED = argh.CommandError('Already initialized')
NO_BOOTSTRAP = argh.CommandError('Not bootstrapped')
NO_SUCH_CONFIGURATION = argh.CommandError('No such configuration')
STOP_DEPLOYMENT_ENVIRONMENT = '_stop_deployment_environment'


def bake(cmd):
    return cmd.bake(_out=lambda line: sys.stdout.write(line),
                    _err=lambda line: sys.stderr.write(line))


app = argh.EntryPoint('claw')
command = app
cfy = bake(sh.cfy)


@command
def init(suites_yaml=None, claw_home=None, reset=False):
    """Initialize a claw environment."""
    if settings.settings_path.exists() and not reset:
        raise INIT_EXISTS
    if not suites_yaml:
        system_tests_dir = os.path.dirname(
            os.path.dirname(cosmo_tester.__file__))
        suites_yaml = os.path.join(system_tests_dir, 'suites', 'suites',
                                   'suites.yaml')
    suites_yaml = os.path.expanduser(suites_yaml)
示例#3
0
import sys

import yaml
import colors
import argh
from argh.decorators import arg
from path import path

from je.jenkins import jenkins
from je.cache import cache
from je.configuration import configuration
from je.completion import completion
from je.work import work


app = argh.EntryPoint('je')
command = app


@command
@arg('--jenkins-username', required=True)
@arg('--jenkins-password', required=True)
@arg('--jenkins-base-url', required=True)
def init(jenkins_username=None,
         jenkins_password=None,
         jenkins_base_url=None,
         jenkins_system_tests_base=None,
         workdir=None,
         reset=False):
    configuration.save(jenkins_username=jenkins_username,
                       jenkins_password=jenkins_password,
示例#4
0
from docl import constants
from docl import resources
from docl import install_rpm_server
from docl import files
from docl.configuration import configuration
from docl.work import work
from docl.subprocess import docker
from docl.subprocess import quiet_docker
from docl.subprocess import ssh as _ssh
from docl.subprocess import ssh_keygen
from docl.subprocess import ssh_keyscan
from docl.subprocess import cfy
from docl.subprocess import gzip
from docl.logs import logger

app = argh.EntryPoint('docl')
command = app


@command
@argh.arg(
    '-u',
    '--manager-image-url',
    help="Manager image URL. If specified, `docl pull-image` will download an "
    "image from this URL.")
@argh.arg(
    '-m',
    '--manager-image-docker-tag',
    help="Default Docker image tag to use (for example `docl run` with no "
    "parameters will use this value to run a local image with this tag).")
@argh.arg(
示例#5
0
文件: clad.py 项目: mcouthon/clapp
#!/usr/bin/env python

import sh
import argh
from colorama import Fore
from threading import Thread

from .logs import logger
from .git import Git
from .repos import Repos
from .constants import MASTER
from .utils import get_repo_path

command = argh.EntryPoint(
    'clad',
    dict(description='Custom commands that run on several cloudify repos'))


@command
def status(hide_tags=False):
    logger.header('Status')
    repos = Repos()
    for repo, _ in repos.repos:
        git = Git(repo)
        output = git.validate_repo()
        if output:
            logger.log(repo, output)
            continue

        branch = git.get_current_branch_or_tag(hide_tags=hide_tags)
        logger.log(repo, branch)