<commit_before>from fabric.api import env, task, local, cd, lcd, run, sudo, put

from tempfile import NamedTemporaryFile

env.use_ssh_config = True
env.hosts = ['skylines@skylines']

APP_DIR = '/home/skylines'
SRC_DIR = '%s/src' % APP_DIR


@task
def deploy(branch='master', force=False):
    deploy_ember()
    push(branch, force)
    bower_install()
    restart()


@task
def deploy_ember():
    with lcd('ember'):
        local('node_modules/.bin/ember deploy production -v')


@task
def push(branch='HEAD', force=False):
    cmd = 'git push %s:%s %s:master' % (env.host_string, SRC_DIR, branch)
    if force:
        cmd += ' --force'

    local(cmd)


@task
def restart():
    with cd(SRC_DIR):
        run('git reset --hard')

        # compile i18n .mo files
        manage('babel compile')

        # generate JS/CSS assets
        manage('assets build')

        # do database migrations
        manage('migrate upgrade')

        # restart services
        restart_service('skylines-api')
        restart_service('skylines')
        restart_service('mapserver')
        restart_service('tracking')
        restart_service('celery')
        restart_service('mapproxy')


@task
def restart_service(service):
    # Using the sudo() command somehow always provokes a password prompt,
    # even if NOPASSWD is specified in the sudoers file...
    run('sudo supervisorctl restart %s' % service)


@task
def manage(cmd, user=None):
    with cd(SRC_DIR):
        if user:
            sudo('./manage.py %s' % cmd, user=user)
        else:
            run('./manage.py %s' % cmd)


@task
def update_mapproxy():
    with NamedTemporaryFile() as f:
        content = open('mapserver/mapproxy/mapproxy.yaml').read()

        content = content.replace(
            'base_dir: \'/tmp/cache_data\'',
            'base_dir: \'%s/cache/mapproxy\'' % APP_DIR,
        )

        content = content.replace(
            'lock_dir: \'/tmp/cache_data/tile_locks\'',
            'lock_dir: \'%s/cache/mapproxy/tile_locks\'' % APP_DIR,
        )

        f.write(content)
        f.flush()

        put(f.name, '%s/config/mapproxy.yaml' % APP_DIR)


@task
def pip_install():
    with cd(SRC_DIR):
        run('git reset --hard')
        run('pip install -e .')


@task
def bower_install():
    with cd(SRC_DIR + '/ember'):
        run('bower install')


@task
def clean_mapproxy_cache():
    with cd('/home/skylines/cache/mapproxy'):
        run('rm -rv *')<commit_msg>fabfile: Remove obsolete "bower install" step<commit_after>from fabric.api import env, task, local, cd, lcd, run, sudo, put

from tempfile import NamedTemporaryFile

env.use_ssh_config = True
env.hosts = ['skylines@skylines']

APP_DIR = '/home/skylines'
SRC_DIR = '%s/src' % APP_DIR


@task
def deploy(branch='master', force=False):
    deploy_ember()
    push(branch, force)
    restart()


@task
def deploy_ember():
    with lcd('ember'):
        local('node_modules/.bin/ember deploy production -v')


@task
def push(branch='HEAD', force=False):
    cmd = 'git push %s:%s %s:master' % (env.host_string, SRC_DIR, branch)
    if force:
        cmd += ' --force'

    local(cmd)


@task
def restart():
    with cd(SRC_DIR):
        run('git reset --hard')

        # compile i18n .mo files
        manage('babel compile')

        # generate JS/CSS assets
        manage('assets build')

        # do database migrations
        manage('migrate upgrade')

        # restart services
        restart_service('skylines-api')
        restart_service('skylines')
        restart_service('mapserver')
        restart_service('tracking')
        restart_service('celery')
        restart_service('mapproxy')


@task
def restart_service(service):
    # Using the sudo() command somehow always provokes a password prompt,
    # even if NOPASSWD is specified in the sudoers file...
    run('sudo supervisorctl restart %s' % service)


@task
def manage(cmd, user=None):
    with cd(SRC_DIR):
        if user:
            sudo('./manage.py %s' % cmd, user=user)
        else:
            run('./manage.py %s' % cmd)


@task
def update_mapproxy():
    with NamedTemporaryFile() as f:
        content = open('mapserver/mapproxy/mapproxy.yaml').read()

        content = content.replace(
            'base_dir: \'/tmp/cache_data\'',
            'base_dir: \'%s/cache/mapproxy\'' % APP_DIR,
        )

        content = content.replace(
            'lock_dir: \'/tmp/cache_data/tile_locks\'',
            'lock_dir: \'%s/cache/mapproxy/tile_locks\'' % APP_DIR,
        )

        f.write(content)
        f.flush()

        put(f.name, '%s/config/mapproxy.yaml' % APP_DIR)


@task
def pip_install():
    with cd(SRC_DIR):
        run('git reset --hard')
        run('pip install -e .')


@task
def clean_mapproxy_cache():
    with cd('/home/skylines/cache/mapproxy'):
        run('rm -rv *')
{'fraction_non_alphanumeric': 0.13992962119643967, 'fraction_numerical': 0.0008279859242392879, 'mean_word_length': 2.53474762253109, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1482881', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1586, 'n_words': 372}