Exemplo n.º 1
0
def test_warnask_no(mock_confirm):
    mock_confirm.return_value = False
    mock_app = mock.MagicMock()
    with pytest.raises(SystemExit):
        main.warnask(mock_app)
    mock_confirm.assert_has_calls([
        mock.call(colors.teal('Attempt to upgrade before continuing?')),
        mock.call(colors.teal('Continue without upgrading?'))
    ])
    mock_app.repo.pull.assert_not_called()
Exemplo n.º 2
0
def test_warnask_yes(mock_confirm):
    mock_confirm.return_value = True
    mock_app = mock.MagicMock()
    main.warnask(mock_app)
    mock_confirm.assert_called_once_with(
        colors.teal('Attempt to upgrade before continuing?'))
    mock_app.repo.pull.assert_called_once_with()
Exemplo n.º 3
0
def dip_list():
    """ List installed CLIs. """
    with settings.load() as cfg:
        if any(cfg):
            click.echo()
            homes = [utils.contractuser(cfg[x].home) for x in cfg]
            maxname = max(len(x) for x in cfg)
            maxhome = max(len(x) for x in homes)
            for key in sorted(cfg):
                app = cfg[key]
                name = colors.teal(app.name.ljust(maxname))
                home = colors.blue(utils.contractuser(app.home).ljust(maxhome))
                remote = branch = None
                tpl = "{name} {home}"
                if app.repo:
                    try:
                        remote = app.repo.remotename
                        branch = app.repo.branch
                        tpl += " {remote}/{branch}"
                    except Exception:  # pylint:  disable=broad-except
                        tpl += colors.red(' [git error]')
                click.echo(
                    tpl.format(name=name,
                               home=home,
                               remote=remote,
                               branch=branch))
            click.echo()
Exemplo n.º 4
0
def warnupgrade(app):
    """ Warn about app divergence and do upgrade. """
    # Warn about divergence
    warn = '\nLocal service has diverged from remote or is inaccessible.'
    click.echo(colors.amber(warn), err=True)

    # Ask to upgrade
    click.echo(colors.teal('Attempting to auto-upgrade'), err=True)
    app.repo.pull()
Exemplo n.º 5
0
def warnask(app):
    """ Warn about app divergence and ask to upgrade. """
    # Warn about divergence
    warn = '\nLocal service has diverged from remote or is inaccessible.'
    click.echo(colors.amber(warn), err=True)

    # Ask to upgrade
    upgrade = colors.teal('Attempt to upgrade before continuing?')
    if click.confirm(upgrade):
        # Upgrade
        app.repo.pull()
        click.echo(err=True)
    else:
        override = colors.teal('Continue without upgrading?')
        if not click.confirm(override):
            goodbye = 'Please resolve these changes before re-attempting.\n'
            click.echo(goodbye, err=True)
            raise SystemExit(1)
Exemplo n.º 6
0
def warnsleep(app):
    """ Warn about app divergence and sleep. """
    # Warn about divergence
    warn = '\n'\
        'Local service has diverged from remote or is inaccessible.\n'\
        'Sleeping for {}s\n'\
        'CTRL-C to exit\n'.format(app.repo.sleeptime)
    click.echo(colors.amber(warn), err=True)

    # Give hint to upgrade
    upgrade = 'dip upgrade {}'.format(app.name)
    hint = 'Run `{}` to git-pull updates from remote\n'\
        .format(colors.teal(upgrade))
    click.echo(hint, err=True)

    # Sleep
    app.repo.sleep()
Exemplo n.º 7
0
def dip_install(name, home, path, remote, dotenv, env, secret, sleep,
                auto_upgrade, no_exe):
    """ Install CLI by name.

        \b
        dip install fizz .                   # Relative path
        dip install fizz /path/to/dir        # Absolute path
        dip install fizz . -r origin/master  # Tracking git remote/branch
    """
    # pylint: disable=too-many-arguments
    with settings.saveonexit() as cfg:
        # Interactively set ENV
        for sec in secret:
            env[sec] = click.prompt(sec, hide_input=True)  # pragma: no cover

        # Parse git config
        remote, branch = remote
        git = {
            'remote': remote,
            'branch': branch,
            'sleep': sleep,
            'auto_upgrade': auto_upgrade
        }

        # Install
        if no_exe:
            app = cfg[name] = settings.Dip(name, home, path, env, git, dotenv)
        else:
            app = cfg.install(name, home, path, env, git, dotenv)

        # Validate configuration
        app.validate()

        # Finish
        click.echo("Installed {name} to {path}".format(
            name=colors.teal(app.name), path=colors.blue(app.path)))
Exemplo n.º 8
0
def test_teal(mock_style):
    """ Shortcut for colored.stylize(). """
    colors.teal('TEST')
    mock_style.assert_called_once_with('TEST', colors.TEAL)