<commit_before>import os.path
import tempfile

from fabric.api import *
from fabric.contrib.console import confirm

env.hosts = ['<EMAIL>']

FIXTURES = [
    # 'auth.User',
    'tomo.Course',
    'tomo.ProblemSet',
    # 'tomo.Language',
    'tomo.Problem',
    'tomo.Part',
    # 'tomo.Submission',
    # 'tomo.Attempt',
]

env.srv_directory = '/srv/'
env.project_repository = '<EMAIL>:matijapretnar/projekt-tomo.git'
env.tomo_repository = '<EMAIL>:matijapretnar/tomo.git'

@task
def setup():
    with cd(env.srv_directory):
        sudo('git clone {project_repository} {project_name}'.format(**env))
    with cd(env.home):
        sudo('virtualenv --no-site-packages virtualenv')
        with prefix('source virtualenv/bin/activate'):
            sudo('pip install -r requirements/{project_name}.txt'.format(**env))
        sudo('git clone {tomo_repository}'.format(**env))
        sudo('mkdir static')
        with cd('static'):
            sudo('git clone https://github.com/mathjax/MathJax')
    update()

@task
def production():
    set_project('tomoprod')

@task
def std_production():
    set_project('tomostd')

@task
def lock():
    with cd(env.home):
        sudo('touch lock')
    restart()

@task
def unlock():
    with cd(env.home):
        sudo('rm lock')
    restart()

@task
def update():
    lock()
    with cd(env.home):
        sudo('git pull')
        with cd('tomo'):
            sudo('git pull')
    manage('collectstatic --noinput')
    manage('syncdb')
    manage('migrate')
    unlock()

@task
def update_all():
    lock()
    with cd(env.home):
        with prefix('source virtualenv/bin/activate'):
            sudo('pip install -r requirements/{project_name}.txt'.format(**env))
        with cd('static/MathJax'):
            sudo('git pull')
    unlock()

@task
def get_dump():
    for fixture in FIXTURES:
        with hide('stdout'):
            json = manage('dumpdata --indent=2 {0}'.format(fixture))
        with open('fixtures/{0}.json'.format(fixture), 'w') as f:
            f.write(json)

@task
def edit_apache():
    edit('/etc/apache2/sites-available/tomo.fmf.uni-lj.si', use_sudo=True)

@task
def restart_apache():
    sudo('apache2ctl graceful')

@task
def reset_tomodev():
    if confirm('Are you sure you want to reset the staging database?',
               default=False):
        postgres("dropdb tomodev")
        postgres("createdb -T tomo tomodev")

@task
def reset_local():
    local('touch tomo.db')
    local('rm tomo.db')
    local('./manage.py syncdb --noinput')<commit_msg>We restart apache after each edit of configuration.<commit_after>import os.path
import tempfile

from fabric.api import *
from fabric.contrib.console import confirm

env.hosts = ['<EMAIL>']

FIXTURES = [
    # 'auth.User',
    'tomo.Course',
    'tomo.ProblemSet',
    # 'tomo.Language',
    'tomo.Problem',
    'tomo.Part',
    # 'tomo.Submission',
    # 'tomo.Attempt',
]

env.srv_directory = '/srv/'
env.project_repository = '<EMAIL>:matijapretnar/projekt-tomo.git'
env.tomo_repository = '<EMAIL>:matijapretnar/tomo.git'

@task
def setup():
    with cd(env.srv_directory):
        sudo('git clone {project_repository} {project_name}'.format(**env))
    with cd(env.home):
        sudo('virtualenv --no-site-packages virtualenv')
        with prefix('source virtualenv/bin/activate'):
            sudo('pip install -r requirements/{project_name}.txt'.format(**env))
        sudo('git clone {tomo_repository}'.format(**env))
        sudo('mkdir static')
        with cd('static'):
            sudo('git clone https://github.com/mathjax/MathJax')
    update()

@task
def production():
    set_project('tomoprod')

@task
def std_production():
    set_project('tomostd')

@task
def lock():
    with cd(env.home):
        sudo('touch lock')
    restart()

@task
def unlock():
    with cd(env.home):
        sudo('rm lock')
    restart()

@task
def update():
    lock()
    with cd(env.home):
        sudo('git pull')
        with cd('tomo'):
            sudo('git pull')
    manage('collectstatic --noinput')
    manage('syncdb')
    manage('migrate')
    unlock()

@task
def update_all():
    lock()
    with cd(env.home):
        with prefix('source virtualenv/bin/activate'):
            sudo('pip install -r requirements/{project_name}.txt'.format(**env))
        with cd('static/MathJax'):
            sudo('git pull')
    unlock()

@task
def get_dump():
    for fixture in FIXTURES:
        with hide('stdout'):
            json = manage('dumpdata --indent=2 {0}'.format(fixture))
        with open('fixtures/{0}.json'.format(fixture), 'w') as f:
            f.write(json)

@task
def edit_apache():
    edit('/etc/apache2/sites-available/tomo.fmf.uni-lj.si', use_sudo=True)
    restart_apache()

@task
def restart_apache():
    sudo('apache2ctl graceful')

@task
def reset_tomodev():
    if confirm('Are you sure you want to reset the staging database?',
               default=False):
        postgres("dropdb tomodev")
        postgres("createdb -T tomo tomodev")

@task
def reset_local():
    local('touch tomo.db')
    local('rm tomo.db')
    local('./manage.py syncdb --noinput')
{'fraction_non_alphanumeric': 0.15855327468230693, 'fraction_numerical': 0.0019550342130987292, 'mean_word_length': 2.923312883435583, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, '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': '6554589', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1660, 'n_words': 365}