<commit_before>from fabric.api import *

try:
    from config import host_strings # varies per-user, so not tracked in Git
    env.hosts = host_strings
except ImportError:
    env.hosts = ["peninsula.pomona.edu"]

env.site = "staging" # By default, run all of these tasks on 'staging'
env.origin = "<EMAIL>@github.com:aspc/mainsite.git"

"""
Deployment script for ASPC's main site and staging site

Provides 'stage' as an alias for 'on_staging apply_changes'
and 'deploy' for 'on_main apply_changes'
"""

def on_staging():
    env.site = "staging"
    env.branch = "staging"

def on_main():
    env.site = "main"
    env.branch = "production"

def stage():
    on_staging()
    apply_changes()

def deploy():
    on_main()
    apply_changes()

def migrate():
    with settings(
        cd("/srv/www/{0}/mainsite".format(env.site)),
        prefix("source /srv/www/{0}/env/bin/activate".format(env.site))
    ):
        sudo("./manage.py migrate", user=env.site)
        sudo("./manage.py syncdb", user=env.site)

def update_static():
    with settings(
        cd("/srv/www/{0}/mainsite".format(env.site)),
        prefix("source /srv/www/{0}/env/bin/activate".format(env.site))
    ):
        sudo("./manage.py collectstatic", user=env.site)

def install_requirements():
    with settings(
        cd("/srv/www/{0}/mainsite".format(env.site)),
        prefix("source /srv/www/{0}/env/bin/activate".format(env.site))
    ):
        sudo("pip install -r ./requirements.txt", user=env.site)

def reload():
    run("/srv/www/{0}/bin/gunicorn.sh reload".format(env.site))

def git_push_pull():
    local("git push {0} {1}".format(env.origin, env.branch))
    with settings(
        cd("/srv/www/{0}/mainsite".format(env.site)),
    ):
        sudo("git clean -f", user=env.site)
        sudo("git pull origin", user=env.site)
        sudo("git status", user=env.site)

def apply_changes():
    git_push_pull()
    install_requirements()
    update_static()
    migrate()
    reload()
<commit_msg>Make sure GitHub master is updated as part of deploy<commit_after>from fabric.api import *

try:
    from config import host_strings # varies per-user, so not tracked in Git
    env.hosts = host_strings
except ImportError:
    env.hosts = ["peninsula.pomona.edu"]

env.site = "staging" # By default, run all of these tasks on 'staging'
env.origin = "<EMAIL>@github.com:aspc/mainsite.git"

"""
Deployment script for ASPC's main site and staging site

Provides 'stage' as an alias for 'on_staging apply_changes'
and 'deploy' for 'on_main apply_changes'
"""

def on_staging():
    env.site = "staging"
    env.branch = "staging"

def on_main():
    env.site = "main"
    env.branch = "production"

def stage():
    on_staging()
    apply_changes()

def deploy():
    on_main()
    apply_changes()

def migrate():
    with settings(
        cd("/srv/www/{0}/mainsite".format(env.site)),
        prefix("source /srv/www/{0}/env/bin/activate".format(env.site))
    ):
        sudo("./manage.py migrate", user=env.site)
        sudo("./manage.py syncdb", user=env.site)

def update_static():
    with settings(
        cd("/srv/www/{0}/mainsite".format(env.site)),
        prefix("source /srv/www/{0}/env/bin/activate".format(env.site))
    ):
        sudo("./manage.py collectstatic", user=env.site)

def install_requirements():
    with settings(
        cd("/srv/www/{0}/mainsite".format(env.site)),
        prefix("source /srv/www/{0}/env/bin/activate".format(env.site))
    ):
        sudo("pip install -r ./requirements.txt", user=env.site)

def reload():
    run("/srv/www/{0}/bin/gunicorn.sh reload".format(env.site))

def git_push_pull():
    local("git push {0} master".format(env.origin))
    local("git checkout {0}".format(env.branch))
    local("git merge master")
    local("git push {0} {1}".format(env.origin, env.branch))
    local("git checkout master")
    local("git status")
    with settings(
        cd("/srv/www/{0}/mainsite".format(env.site)),
    ):
        sudo("git clean -f", user=env.site)
        sudo("git checkout -f .", user=env.site)
        sudo("git pull origin", user=env.site)
        sudo("git status", user=env.site)

def apply_changes():
    git_push_pull()
    install_requirements()
    update_static()
    migrate()
    reload()

{'fraction_non_alphanumeric': 0.16502347417840377, 'fraction_numerical': 0.005164319248826291, 'mean_word_length': 3.1169082125603866, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 16, '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': '3581359', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1439, 'n_words': 314}