<commit_before>import os
import json

import fabric
from fabric.api import run, sudo, cd, put


fabric.state.env.colorize_errors = True
# fabric.state.output['stdout'] = False


VARS = dict(
    init_app=True,
    templates_dir=os.path.join(os.path.dirname(__file__), 'templates')
)


def render_template(template_name, remote_name):
    """ Render wrapper for simplify touch rendered template into target """
    if os.path.dirname(remote_name):
        run('mkdir -p {}'.format(os.path.dirname(remote_name)))
    fabric.contrib.files.upload_template(
        template_name, remote_name,
        context=VARS, use_jinja=True,
        backup=False, use_sudo=False, template_dir=VARS['templates_dir']
    )


def common(taskname):
    """ Run all common tasks """
    config = json.load(open(os.path.join(os.path.dirname(__file__), 'cfg.json')))
    VARS.update(config)
    fabric.tasks.execute(taskname)


def start_box():
    """ Create Vagrant file and up virtual machine """
    run('mkdir -p {root_dir}'.format(**VARS))
    with cd(VARS['root_dir']):
        render_template('Vagrantfile.jinja', 'Vagrantfile')
        render_template('Makefile.jinja', 'Makefile')
        run('chmod +x Makefile')
        # make provisioning folder
        run('mkdir -p provision')
        render_template('provision_fabfile.jinja', 'provision/fabric_provisioner.py')
        render_template('requirements.jinja', 'requirements.txt')
        render_template('requirements.jinja', 'requirements-remote.txt')
        render_template('settings_local.jinja', '{proj_name}/settings_local.py.example'.format(**VARS))
        if VARS.get('CELERY'):
            render_template('celery.jinja', '{proj_name}/celery.py'.format(**VARS))
        # copy templates for vagrant fabric render
        path = os.path.join(VARS['templates_dir'], 'vagrant_templates')
        run('mkdir -p {}'.format('provision/templates'))
        put(path, 'provision')
        run('rm -rf provision/templates && mv -f provision/vagrant_templates provision/templates')
        # run vagrant up
        run('vagrant up')
        # replace template
        VARS['init_app'] = False
        render_template('provision_fabfile.jinja', 'provision/fabric_provisioner.py')


def reprovision():
    with cd(VARS['root_dir']):
        run('vagrant provision')<commit_msg>:repeat: commit after init box<commit_after>import os
import json

import fabric
from fabric.api import run, sudo, cd, put


fabric.state.env.colorize_errors = True
# fabric.state.output['stdout'] = False


VARS = dict(
    init_app=True,
    templates_dir=os.path.join(os.path.dirname(__file__), 'templates')
)


def render_template(template_name, remote_name):
    """ Render wrapper for simplify touch rendered template into target """
    if os.path.dirname(remote_name):
        run('mkdir -p {}'.format(os.path.dirname(remote_name)))
    fabric.contrib.files.upload_template(
        template_name, remote_name,
        context=VARS, use_jinja=True,
        backup=False, use_sudo=False, template_dir=VARS['templates_dir']
    )


def common(taskname):
    """ Run all common tasks """
    config = json.load(open(os.path.join(os.path.dirname(__file__), 'cfg.json')))
    VARS.update(config)
    fabric.tasks.execute(taskname)


def start_box():
    """ Create Vagrant file and up virtual machine """
    run('mkdir -p {root_dir}'.format(**VARS))
    with cd(VARS['root_dir']):
        render_template('Vagrantfile.jinja', 'Vagrantfile')
        render_template('Makefile.jinja', 'Makefile')
        run('chmod +x Makefile')
        # make provisioning folder
        run('mkdir -p provision')
        render_template('provision_fabfile.jinja', 'provision/fabric_provisioner.py')
        render_template('requirements.jinja', 'requirements.txt')
        render_template('requirements.jinja', 'requirements-remote.txt')
        render_template('settings_local.jinja', '{proj_name}/settings_local.py.example'.format(**VARS))
        if VARS.get('CELERY'):
            render_template('celery.jinja', '{proj_name}/celery.py'.format(**VARS))
        # copy templates for vagrant fabric render
        path = os.path.join(VARS['templates_dir'], 'vagrant_templates')
        run('mkdir -p {}'.format('provision/templates'))
        put(path, 'provision')
        run('rm -rf provision/templates && mv -f provision/vagrant_templates provision/templates')
        # run vagrant up
        run('vagrant up')
        # replace template
        VARS['init_app'] = False
        render_template('provision_fabfile.jinja', 'provision/fabric_provisioner.py')
    fabric.tasks.execute('falstart_commit')


def falstart_commit():
    """ Try to commit after box start """
    with cd(VARS['root_dir']), fabric.context_managers.settings(warn_only=True):
        run('''echo "
# custome ignore
settings_local.py
.vagrant
var/
static/
" >> .gitignore''')
        run('git add . && git commit -m ":rocket: falstart init commit"')


def reprovision():
    with cd(VARS['root_dir']):
        run('vagrant provision')
{'fraction_non_alphanumeric': 0.13989637305699482, 'fraction_numerical': 0.0, 'mean_word_length': 3.642923219241443, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5338868', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1545, 'n_words': 302}