<commit_before>from fabric.api import *

env.user = 'paperchase'

# Define host names for inside and outside the LAN
def inside():
    env.hosts = ['brick.local']

def outside():
    env.hosts = ['dedalusj.dyndns.org']

# Run Celery worker locally
def run_celery(loglevel="info"):
    local("celery -A paperchase.tasks worker -B --loglevel=%s" % loglevel)    
    
# Setup and maintenance of the remote server
def setup_repo():
    with settings(warn_only=True):
        if run("git clone https://github.com/dedalusj/PaperChase.git .").failed:
            run("git pull")

def setup_venv():
    run("curl -O https://raw.github.com/pypa/virtualenv/1.9.X/virtualenv.py")
    run("python virtualenv.py PC")
    run("PC/bin/pip install -r requirements.txt")

def setup():
    code_dir = '/Users/paperchase/server'
    local('mysqldump -u paperchase -p development > development.sql')
    with cd(code_dir):
        setup_repo()
        
    with cd(code_dir+'/webapp'):
        setup_venv()
        put('development.sql', code_dir+'/webapp')
        run('mysql --host=localhost --port=3306 --user=paperchase -p --reconnect development < development.sql')
        run("mkdir log")
    
def deploy():
    code_dir = '/Users/paperchase/server/webapp'
    put('paperchase/settings.py', code_dir+'/paperchase/')
    with cd(code_dir):
        pass
        
def update_database():
    run("alembic upgrade head")<commit_msg>Added setup methods to fabfile<commit_after>import string
from random import choice

from fabric.api import *
from fabric.operations import prompt

env.user = 'paperchase'

# Define host names for inside and outside the LAN
def inside():
    env.hosts = ['brick.local']

def outside():
    env.hosts = ['dedalusj.dyndns.org']
    
def vm():
    env.hosts = ['paperchasevm.local']

# Run Celery worker locally
def run_celery(loglevel="info"):
    local("celery -A paperchase.tasks worker -B --loglevel=%s" % loglevel)    
    
# Setup and maintenance of the remote server
def make_dir():
    run("mkdir PaperChase")

def setup_repo(path="PaperChase"):
    """Original clone of the repo"""
    with cd(path):
        run("git clone https://github.com/dedalusj/PaperChase.git .")
        with cd('webapp'):
            run("mkdir log")

def setup_venv(path="PaperChase/webapp"):
    with cd(path):
        run("curl -O https://raw.github.com/pypa/virtualenv/1.9.X/virtualenv.py")
        run("python virtualenv.py venv")
        run("venv/bin/pip install -r requirements.txt")
    fix_feedparser(path)
        
def fix_feedparser(path="PaperChase/webapp"):
    with cd(path):
        run("mkdir temp")
        cd("temp")
        run("git clone https://github.com/dedalusj/feedparser.git .")
        run("mv feedparser/feedparser.py ../venv/lib/python2.7/")
        cd("..")
        run("rm -fdr temp")
        
def prompt_for_settings():
    prompt("What's the MySQL database?", key="database", default="paperchase_development")
    prompt("Enter the paperchase user password for the database, ", key="db_password")
    prompt("Enter an email address for mail notifications, ", key="mail_address")
    prompt("What's the mail server?", key="mail_server")
    prompt("What's the mail port?", key="mail_port", default="465")
    prompt("Does the mail service use SSL?", key="mail_ssl", default="True")
    prompt("Enter a username for the mail service, ", key="mail_username")
    prompt("Enter a password for the mail service, ", key="mail_password") 

def setup_settings(path="PaperChase/webapp/paperchase"):
    prompt_for_settings()
    with cd(path):
        run("cp settings.py.example settings.py")
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$database',env.database))
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$db_password',env.db_password))
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$mail_address',env.mail_address))
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$mail_server',env.mail_server))
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$mail_port',env.mail_port))
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$mail_ssl',env.mail_ssl))
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$mail_username',env.mail_username))
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$mail_password',env.mail_password))
        
        chars = string.letters + string.digits
        length = 10
        secret_key = ''.join(choice(chars) for _ in range(length))
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$secret_key',secret_key))
        
        length = 22
        password_salt = ''.join(choice(chars) for _ in range(length))
        run('sed -i "" "s/{0}/{1}/" settings.py'.format('$password_salt',password_salt))

def setup():
    code_dir = '/Users/paperchase/server'
    local('mysqldump -u paperchase -p development > development.sql')
    with cd(code_dir):
        setup_repo()
        
    with cd(code_dir + '/webapp'):
        setup_venv()
        put('development.sql', code_dir + '/webapp')
        run('mysql --host=localhost --port=3306 --user=paperchase -p --reconnect development < development.sql')
        run("mkdir log")

def update_repo(path="PaperChase"):
    """Update the repo"""
    with cd(path):
        run("git pull")
    
def deploy():
    code_dir = '/Users/paperchase/server/webapp'
    put('paperchase/settings.py', code_dir+'/paperchase/')
    with cd(code_dir):
        pass
        
def update_database():
    run("alembic upgrade head")
{'fraction_non_alphanumeric': 0.16439104314582195, 'fraction_numerical': 0.007464045148370653, 'mean_word_length': 3.133935289691497, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 5, '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': '576375', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1775, 'n_words': 396}