<commit_before>from fabric.api import roles, env, run, cd, sudo
from fabric.contrib.files import upload_template

env.hosts = [
    '<EMAIL>',
    '<EMAIL>',
    '<EMAIL>',
    '<EMAIL>',
]

env.roledefs = {
    'dev': ['<EMAIL>', ],
    'staging': ['<EMAIL>'],
    'production': ['<EMAIL>'],
    'build': ['<EMAIL>'],
}


def echo():
    run('ls /')

def ensure_docker_compose():
    sudo('which docker-compose || pip install docker-compose')

@roles('build')
def build_dockerimage(branch_or_tag='develop'):

    with cd('~/build_setup/'):
        run('./update_env.sh')

    with cd('/home/ubuntu/build_setup/dockersetup/projects/nutsurv'):
        run('BRANCH={} ./run_build.sh'.format(branch_or_tag))
        run('docker push docker-registry.eocng.org/ehealthafrica/nutsurv:{}'.format(
            branch_or_tag))

@roles('dev', 'staging', 'production')
def deploy(branch_or_tag=None, do_stop=True):

    if env.host_string == '<EMAIL>':
        if branch_or_tag is None:
            branch_or_tag = 'develop'

    else:
        assert branch_or_tag, "Please specify a tag"
        assert branch_or_tag.startswith('v'), "You can only deploy tags to {}".format(env.host_string)

    run('docker pull docker-registry.eocng.org/ehealthafrica/nutsurv:{}'.format(
        branch_or_tag))

    if do_stop is True:
        stop_result = run('docker stop nutsurvdeploy_web_1', warn_only=True)

        if (stop_result
                and (stop_result != 'nutsurvdeploy_web_1')
                and ('no such' not in stop_result.lower())):
            assert False, stop_result

    run('test -e ~/nutsurv_deploy/ || mkdir ~/nutsurv_deploy/')
    ensure_docker_compose()
    upload_template(
        'docker-compose-deploy.yml.template',
        '~/nutsurv_deploy/docker-compose-deploy.yml',
        context={'branch_or_tag': branch_or_tag, }
    )


@roles('dev', 'staging', 'production')
def up():

    run('test -e ~/nutsurv_deploy/configuration.py')
    run('test -e ~/nutsurv_deploy/certs/cert.pem')
    run('test -e ~/nutsurv_deploy/certs/key.pem')

    ensure_docker_compose()
    with cd('~/nutsurv_deploy'):
        run('docker-compose -f ~/nutsurv_deploy/docker-compose-deploy.yml up -d web')

@roles('dev', 'staging', 'production')
def migrate():
    ensure_docker_compose()
    with cd('~/nutsurv_deploy'):
        run('docker-compose -f ~/nutsurv_deploy/docker-compose-deploy.yml run web python /opt/nutsurv/nutsurv/manage.py migrate')
        run('docker-compose -f ~/nutsurv_deploy/docker-compose-deploy.yml run web python /opt/nutsurv/nutsurv/manage.py createcachetable')
<commit_msg>fabfile: test -f or -d instead of -e<commit_after>from fabric.api import roles, env, run, cd, sudo
from fabric.contrib.files import upload_template

env.hosts = [
    '<EMAIL>',
    '<EMAIL>',
    '<EMAIL>',
    '<EMAIL>',
]

env.roledefs = {
    'dev': ['<EMAIL>', ],
    'staging': ['<EMAIL>'],
    'production': ['<EMAIL>'],
    'build': ['<EMAIL>.eocng.org'],
}


def echo():
    run('ls /')

def ensure_docker_compose():
    sudo('which docker-compose || pip install docker-compose')

@roles('build')
def build_dockerimage(branch_or_tag='develop'):

    with cd('~/build_setup/'):
        run('./update_env.sh')

    with cd('/home/ubuntu/build_setup/dockersetup/projects/nutsurv'):
        run('BRANCH={} ./run_build.sh'.format(branch_or_tag))
        run('docker push docker-registry.eocng.org/ehealthafrica/nutsurv:{}'.format(
            branch_or_tag))

@roles('dev', 'staging', 'production')
def deploy(branch_or_tag=None, do_stop=True):

    if env.host_string == '<EMAIL>':
        if branch_or_tag is None:
            branch_or_tag = 'develop'

    else:
        assert branch_or_tag, "Please specify a tag"
        assert branch_or_tag.startswith('v'), "You can only deploy tags to {}".format(env.host_string)

    run('docker pull docker-registry.eocng.org/ehealthafrica/nutsurv:{}'.format(
        branch_or_tag))

    if do_stop is True:
        stop_result = run('docker stop nutsurvdeploy_web_1', warn_only=True)

        if (stop_result
                and (stop_result != 'nutsurvdeploy_web_1')
                and ('no such' not in stop_result.lower())):
            assert False, stop_result

    run('test -d ~/nutsurv_deploy/ || mkdir ~/nutsurv_deploy/')
    ensure_docker_compose()
    upload_template(
        'docker-compose-deploy.yml.template',
        '~/nutsurv_deploy/docker-compose-deploy.yml',
        context={'branch_or_tag': branch_or_tag, }
    )


@roles('dev', 'staging', 'production')
def up():

    run('test -f ~/nutsurv_deploy/configuration.py')
    run('test -f ~/nutsurv_deploy/certs/cert.pem')
    run('test -f ~/nutsurv_deploy/certs/key.pem')

    ensure_docker_compose()
    with cd('~/nutsurv_deploy'):
        run('docker-compose -f ~/nutsurv_deploy/docker-compose-deploy.yml up -d web')

@roles('dev', 'staging', 'production')
def migrate():
    ensure_docker_compose()
    with cd('~/nutsurv_deploy'):
        run('docker-compose -f ~/nutsurv_deploy/docker-compose-deploy.yml run web python /opt/nutsurv/nutsurv/manage.py migrate')
        run('docker-compose -f ~/nutsurv_deploy/docker-compose-deploy.yml run web python /opt/nutsurv/nutsurv/manage.py createcachetable')

{'fraction_non_alphanumeric': 0.15897337674774947, 'fraction_numerical': 0.0007661367554108408, 'mean_word_length': 3.3050288540807915, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '3244544', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1825, 'n_words': 339}