def salt(context, force=False):
    install_salt_dependencies(context, force)
    print('Checking Salt installation...', end='')
    reqs_path = os.path.join(context.topdir, 'python', 'requirements-salt.txt')
    process = subprocess.Popen(['pip', 'install', '-q', '-I', '-r', reqs_path], stdout=PIPE, stderr=PIPE)
    process.wait()
    if process.returncode:
        (out, err) = process.communicate()
        print('failed to install Salt via pip:')
        print('Output: {}\nError: {}'.format(out, err))
        return 1
    print('done')
    salt_root = os.path.join(context.sharedir, 'salt')
    config_dir = os.path.join(salt_root, 'etc', 'salt')
    pillar_dir = os.path.join(config_dir, 'pillars')
    config = {'hash_type': 'sha384', 'master': 'localhost', 'root_dir': salt_root, 'state_output': 'changes', 'state_tabular': True}
    if ('SERVO_SALTFS_ROOT' in os.environ):
        config.update({'fileserver_backend': ['roots'], 'file_roots': {'base': [os.path.abspath(os.environ['SERVO_SALTFS_ROOT'])]}})
    else:
        config.update({'fileserver_backend': ['git'], 'gitfs_env_whitelist': 'base', 'gitfs_provider': 'gitpython', 'gitfs_remotes': ['https://github.com/servo/saltfs.git']})
    if (not os.path.exists(config_dir)):
        os.makedirs(config_dir, mode=448)
    with open(os.path.join(config_dir, 'minion'), 'w') as config_file:
        config_file.write((json.dumps(config) + '\n'))
    pillar = {'top.sls': {'base': {'*': ['bootstrap']}}, 'bootstrap.sls': {'fully_managed': False}}
    if os.path.exists(pillar_dir):
        shutil.rmtree(pillar_dir)
    os.makedirs(pillar_dir, mode=448)
    for filename in pillar:
        with open(os.path.join(pillar_dir, filename), 'w') as pillar_file:
            pillar_file.write((json.dumps(pillar[filename]) + '\n'))
    cmd = [find_executable('salt-call'), '--local', '--config-dir={}'.format(config_dir), '--pillar-root={}'.format(pillar_dir), 'state.apply', 'servo-build-dependencies']
    if (not force):
        print('Running bootstrap in dry-run mode to show changes')
        retcode = run_as_root((cmd + ['test=True']))
        if (retcode != 0):
            print('Something went wrong while bootstrapping')
            return retcode
        proceed = input('Proposed changes are above, proceed with bootstrap? [y/N]: ')
        if (proceed.lower() not in ['y', 'yes']):
            return 0
        print('')
    print('Running Salt bootstrap')
    retcode = run_as_root((cmd + ['--retcode-passthrough']))
    if (retcode == 0):
        print('Salt bootstrapping complete')
    else:
        print('Salt bootstrapping encountered errors')
    return retcode
def salt(context, force=False):
    install_salt_dependencies(context, force)
    print('Checking Salt installation...', end=)
    reqs_path = os.path.join(context.topdir, 'python', 'requirements-salt.txt')
    process = subprocess.Popen(['pip', 'install', '-q', '-I', '-r', reqs_path], stdout=PIPE, stderr=PIPE)
    process.wait()
    if process.returncode:
        (out, err) = process.communicate()
        print('failed to install Salt via pip:')
        print('Output: {}\nError: {}'.format(out, err))
        return 1
    print('done')
    salt_root = os.path.join(context.sharedir, 'salt')
    config_dir = os.path.join(salt_root, 'etc', 'salt')
    pillar_dir = os.path.join(config_dir, 'pillars')
    config = {'hash_type': 'sha384', 'master': 'localhost', 'root_dir': salt_root, 'state_output': 'changes', 'state_tabular': True}
    if ('SERVO_SALTFS_ROOT' in os.environ):
        config.update({'fileserver_backend': ['roots'], 'file_roots': {'base': [os.path.abspath(os.environ['SERVO_SALTFS_ROOT'])]}})
    else:
        config.update({'fileserver_backend': ['git'], 'gitfs_env_whitelist': 'base', 'gitfs_provider': 'gitpython', 'gitfs_remotes': ['https://github.com/servo/saltfs.git']})
    if (not os.path.exists(config_dir)):
        os.makedirs(config_dir, mode=448)
    with open(os.path.join(config_dir, 'minion'), 'w') as config_file:
        config_file.write((json.dumps(config) + '\n'))
    pillar = {'top.sls': {'base': {'*': ['bootstrap']}}, 'bootstrap.sls': {'fully_managed': False}}
    if os.path.exists(pillar_dir):
        shutil.rmtree(pillar_dir)
    os.makedirs(pillar_dir, mode=448)
    for filename in pillar:
        with open(os.path.join(pillar_dir, filename), 'w') as pillar_file:
            pillar_file.write((json.dumps(pillar[filename]) + '\n'))
    cmd = [find_executable('salt-call'), '--local', '--config-dir={}'.format(config_dir), '--pillar-root={}'.format(pillar_dir), 'state.apply', 'servo-build-dependencies']
    if (not force):
        print('Running bootstrap in dry-run mode to show changes')
        retcode = run_as_root((cmd + ['test=True']))
        if (retcode != 0):
            print('Something went wrong while bootstrapping')
            return retcode
        proceed = input('Proposed changes are above, proceed with bootstrap? [y/N]: ')
        if (proceed.lower() not in ['y', 'yes']):
            return 0
        print()
    print('Running Salt bootstrap')
    retcode = run_as_root((cmd + ['--retcode-passthrough']))
    if (retcode == 0):
        print('Salt bootstrapping complete')
    else:
        print('Salt bootstrapping encountered errors')
    return retcode