Run the buildout bootstrap dance (python bootstrap.py).

    directory
        directory to execute in

    config
        alternative buildout configuration file to use

    runas
        User used to run buildout as

    env
        environment variables to set when running

    buildout_ver
        force a specific buildout version (1 | 2)

    test_release
        buildout accept test release

    offline
        are we executing buildout in offline mode

    distribute
        Forcing use of distribute

    new_st
        Forcing use of setuptools >= 0.7

    python
        path to a python executable to use in place of default (salt one)

    onlyif
        Only execute cmd if statement on the host return 0

    unless
        Do not execute cmd if statement on the host return 0

    use_vt
        Use the new salt VT to stream output [experimental]

    CLI Example:

    .. code-block:: bash

        salt '*' buildout.bootstrap /srv/mybuildout

def bootstrap(directory='.',
              config='buildout.cfg',
              python=sys.executable,
              onlyif=None,
              unless=None,
              runas=None,
              env=(),
              distribute=None,
              buildout_ver=None,
              test_release=False,
              offline=False,
              new_st=None,
              use_vt=False,
              loglevel=None):
    '''
    Run the buildout bootstrap dance (python bootstrap.py).

    directory
        directory to execute in

    config
        alternative buildout configuration file to use

    runas
        User used to run buildout as

    env
        environment variables to set when running

    buildout_ver
        force a specific buildout version (1 | 2)

    test_release
        buildout accept test release

    offline
        are we executing buildout in offline mode

    distribute
        Forcing use of distribute

    new_st
        Forcing use of setuptools >= 0.7

    python
        path to a python executable to use in place of default (salt one)

    onlyif
        Only execute cmd if statement on the host return 0

    unless
        Do not execute cmd if statement on the host return 0

    use_vt
        Use the new salt VT to stream output [experimental]

    CLI Example:

    .. code-block:: bash

        salt '*' buildout.bootstrap /srv/mybuildout
    '''
    directory = os.path.abspath(directory)
    dbuild = _dot_buildout(directory)
    bootstrap_args = ''
    has_distribute = _has_old_distribute(python=python, runas=runas, env=env)
    has_new_st = _has_setuptools7(python=python, runas=runas, env=env)
    if (
        has_distribute and has_new_st
        and not distribute and new_st
    ):
        new_st = True
        distribute = False
    if (
        has_distribute and has_new_st
        and not distribute and new_st
    ):
        new_st = True
        distribute = False
    if (
        has_distribute and has_new_st
        and distribute and not new_st
    ):
        new_st = True
        distribute = False
    if (
        has_distribute and has_new_st
        and not distribute and not new_st
    ):
        new_st = True
        distribute = False

    if (
        not has_distribute and has_new_st
        and not distribute and new_st
    ):
        new_st = True
        distribute = False
    if (
        not has_distribute and has_new_st
        and not distribute and new_st
    ):
        new_st = True
        distribute = False
    if (
        not has_distribute and has_new_st
        and distribute and not new_st
    ):
        new_st = True
        distribute = False
    if (
        not has_distribute and has_new_st
        and not distribute and not new_st
    ):
        new_st = True
        distribute = False

    if (
        has_distribute and not has_new_st
        and not distribute and new_st
    ):
        new_st = True
        distribute = False
    if (
        has_distribute and not has_new_st
        and not distribute and new_st
    ):
        new_st = True
        distribute = False
    if (
        has_distribute and not has_new_st
        and distribute and not new_st
    ):
        new_st = False
        distribute = True
    if (
        has_distribute and not has_new_st
        and not distribute and not new_st
    ):
        new_st = False
        distribute = True

    if (
        not has_distribute and not has_new_st
        and not distribute and new_st
    ):
        new_st = True
        distribute = False
    if (
        not has_distribute and not has_new_st
        and not distribute and new_st
    ):
        new_st = True
        distribute = False
    if (
        not has_distribute and not has_new_st
        and distribute and not new_st
    ):
        new_st = False
        distribute = True
    if (
        not has_distribute and not has_new_st
        and not distribute and not new_st
    ):
        new_st = True
        distribute = False

    if new_st and distribute:
        distribute = False
    if new_st:
        distribute = False
        LOG.warning('Forcing to use setuptools as we have setuptools >= 0.7')
    if distribute:
        new_st = False
        if buildout_ver == 1:
            LOG.warning('Using distribute !')
            bootstrap_args += ' --distribute'
    if not os.path.isdir(dbuild):
        os.makedirs(dbuild)
    upgrade_bootstrap(directory,
                      offline=offline,
                      buildout_ver=buildout_ver)
    # be sure which buildout bootstrap we have
    b_py = os.path.join(directory, 'bootstrap.py')
    with salt.utils.files.fopen(b_py) as fic:
        content = salt.utils.stringutils.to_unicode(fic.read())
    if (
        (test_release is not False)
        and ' --accept-buildout-test-releases' in content
    ):
        bootstrap_args += ' --accept-buildout-test-releases'
    if config and '"-c"' in content:
        bootstrap_args += ' -c {0}'.format(config)
    # be sure that the bootstrap belongs to the running user
    try:
        if runas:
            uid = __salt__['user.info'](runas)['uid']
            gid = __salt__['user.info'](runas)['gid']
            os.chown('bootstrap.py', uid, gid)
    except (IOError, OSError) as exc:
        # don't block here, try to execute it if can pass
        _logger.error('BUILDOUT bootstrap permissions error: %s',
                      exc, exc_info=_logger.isEnabledFor(logging.DEBUG))
    cmd = '{0} bootstrap.py {1}'.format(python, bootstrap_args)
    ret = _Popen(cmd, directory=directory, runas=runas, loglevel=loglevel,
                 env=env, use_vt=use_vt)
    output = ret['output']
    return {'comment': cmd, 'out': output}