<commit_before>from __future__ import with_statement
import datetime
import glob

from fabric.api import *
from config.fabconfig import *

env.hosts = REMOTE_HOSTS
env.user = USER
env.sudo_user = FS_USER
env.key_filename = KEY_FILENAME


def setup_clean():
    with prefix('source %s/bin/activate' % VENV_PATH):
        with cd(WORKING_PATH):
            try:
                sudo("rm -rf %s" % CURRENT_DIR)
            except:
                pass
            try:
                sudo("rm -rf %s" % RELEASES_DIR)
            except:
                pass
            try:
                sudo("rm -rf %s" % CHECKOUT_DIR)
            except:
                pass
            sudo("mkdir -p %s %s" % (RELEASES_DIR, SHARED_DIR))
            sudo("git clone %s %s" % (GIT_URL, CHECKOUT_DIR))
    create_release()
    symlink_current()


def use_branch():
    with cd("%s/%s" % (WORKING_PATH, CHECKOUT_DIR)):
        sudo("git checkout %s" % GIT_BRANCH)


def update_remote_code():
    with cd("%s/%s" % (WORKING_PATH, CHECKOUT_DIR)):
        sudo("git pull")


def create_release():
    release = datetime.datetime.now().isoformat()
    release_dir = "%s/%s" % (RELEASES_DIR, release)
    with cd(WORKING_PATH):
        sudo("mkdir %s" % release_dir)
        sudo("cp -Rv %s/* %s/" % (CHECKOUT_DIR, release_dir))
        sudo("rm -rf %s/.git %s/.gitignore" % (release_dir, release_dir))


def symlink_current():
    with cd(WORKING_PATH):
        dirs = run("ls -d %s/*/" % RELEASES_DIR).split()
        dirs.sort()
        dirs.reverse()
        dir = dirs[0].strip('/')
        try:
            sudo("unlink %s" % CURRENT_DIR)
        except:
            pass
        sudo("ln -nfs %s %s" % (dir, CURRENT_DIR))
        with cd(dir):
            for path in SHARED_FILES:
                sudo("ln -nfs %s/%s/%s %s" % (WORKING_PATH, SHARED_DIR,
                                              path.split('/')[-1],
                                              path))
    with cd("%s/bin" % HOME_PATH):
        try:
            sudo("unlink ./run")
            sudo("unlink ./stop")
        except:
            pass
        sudo("ln -nfs %s/%s/config/run" % (WORKING_PATH, CURRENT_DIR))
        sudo("ln -nfs %s/%s/config/stop" % (WORKING_PATH, CURRENT_DIR))


def sync_remote_assets():
    with prefix("source %s/bin/activate" % VENV_PATH):
        # with cd("%s/%s" % (WORKING_PATH, SHARED_DIR)):
        #     try:
        #         sudo("rm -rf .static/CACHE")
        #     except:
        #         pass
        with cd("%s/%s" % (WORKING_PATH, CURRENT_DIR)):
            sudo("./manage.py collectstatic --noinput")
            sudo("./manage.py compress")


def install_dependencies():
    with prefix("source %s/bin/activate" % VENV_PATH):
        with cd("%s/%s" % (WORKING_PATH, CURRENT_DIR)):
            sudo("pip install -r requirements.txt")


def run_migrations():
    with prefix("source %s/bin/activate" % VENV_PATH):
        with cd("%s/%s" % (WORKING_PATH, CURRENT_DIR)):
            try:
                sudo("./manage.py createcachetable %s" % CACHE_TABLE_NAME)
            except:
                pass
            sudo("./manage.py syncdb --noinput")
            sudo("./manage.py migrate --noinput")


def stop():
    with cd(HOME_PATH):
        sudo("./bin/stop")


def restart():
    with cd(HOME_PATH):
        sudo("./bin/run")

<commit_msg>don't choke when compress is disabled<commit_after>from __future__ import with_statement
import datetime
import glob

from fabric.api import *
from config.fabconfig import *

env.hosts = REMOTE_HOSTS
env.user = USER
env.sudo_user = FS_USER
env.key_filename = KEY_FILENAME


def setup_clean():
    with prefix('source %s/bin/activate' % VENV_PATH):
        with cd(WORKING_PATH):
            try:
                sudo("rm -rf %s" % CURRENT_DIR)
            except:
                pass
            try:
                sudo("rm -rf %s" % RELEASES_DIR)
            except:
                pass
            try:
                sudo("rm -rf %s" % CHECKOUT_DIR)
            except:
                pass
            sudo("mkdir -p %s %s" % (RELEASES_DIR, SHARED_DIR))
            sudo("git clone %s %s" % (GIT_URL, CHECKOUT_DIR))
    create_release()
    symlink_current()


def use_branch():
    with cd("%s/%s" % (WORKING_PATH, CHECKOUT_DIR)):
        sudo("git checkout %s" % GIT_BRANCH)


def update_remote_code():
    with cd("%s/%s" % (WORKING_PATH, CHECKOUT_DIR)):
        sudo("git pull")


def create_release():
    release = datetime.datetime.now().isoformat()
    release_dir = "%s/%s" % (RELEASES_DIR, release)
    with cd(WORKING_PATH):
        sudo("mkdir %s" % release_dir)
        sudo("cp -Rv %s/* %s/" % (CHECKOUT_DIR, release_dir))
        sudo("rm -rf %s/.git %s/.gitignore" % (release_dir, release_dir))


def symlink_current():
    with cd(WORKING_PATH):
        dirs = run("ls -d %s/*/" % RELEASES_DIR).split()
        dirs.sort()
        dirs.reverse()
        dir = dirs[0].strip('/')
        try:
            sudo("unlink %s" % CURRENT_DIR)
        except:
            pass
        sudo("ln -nfs %s %s" % (dir, CURRENT_DIR))
        with cd(dir):
            for path in SHARED_FILES:
                sudo("ln -nfs %s/%s/%s %s" % (WORKING_PATH, SHARED_DIR,
                                              path.split('/')[-1],
                                              path))
    with cd("%s/bin" % HOME_PATH):
        try:
            sudo("unlink ./run")
            sudo("unlink ./stop")
        except:
            pass
        sudo("ln -nfs %s/%s/config/run" % (WORKING_PATH, CURRENT_DIR))
        sudo("ln -nfs %s/%s/config/stop" % (WORKING_PATH, CURRENT_DIR))


def sync_remote_assets():
    with prefix("source %s/bin/activate" % VENV_PATH):
        # with cd("%s/%s" % (WORKING_PATH, SHARED_DIR)):
        #     try:
        #         sudo("rm -rf .static/CACHE")
        #     except:
        #         pass
        with cd("%s/%s" % (WORKING_PATH, CURRENT_DIR)):
            sudo("./manage.py collectstatic --noinput")
            try:
                sudo("./manage.py compress")
            except:
                pass


def install_dependencies():
    with prefix("source %s/bin/activate" % VENV_PATH):
        with cd("%s/%s" % (WORKING_PATH, CURRENT_DIR)):
            sudo("pip install -r requirements.txt")


def run_migrations():
    with prefix("source %s/bin/activate" % VENV_PATH):
        with cd("%s/%s" % (WORKING_PATH, CURRENT_DIR)):
            try:
                sudo("./manage.py createcachetable %s" % CACHE_TABLE_NAME)
            except:
                pass
            sudo("./manage.py syncdb --noinput")
            sudo("./manage.py migrate --noinput")


def stop():
    with cd(HOME_PATH):
        sudo("./bin/stop")


def restart():
    with cd(HOME_PATH):
        sudo("./bin/run")


{'fraction_non_alphanumeric': 0.14434654919236417, 'fraction_numerical': 0.0005873715124816446, 'mean_word_length': 1.7834082550061299, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4568568', 'n_tokens_mistral': 2314, 'n_tokens_neox': 2176, 'n_words': 486}