<commit_before>import sys
sys.path.append("../../lib")

import db as database
from celery import Celery
from subprocess import call

app = Celery('tasks', broker='amqp://idigphylo:<EMAIL>//')

@app.task
def add(x, y):
    return x + y


def save(fn):
    '''Save the resulting tree in .nex format to the MySQL database
    '''
    with open("{0}.con.tre".format(fn), "r") as tree_file:
        result = tree_file.read()
    db = database.Db()
    # FIXME: HERE
    #db.connect()
    #db.    


def run(fn):
    '''Execute MrBayes script
    '''
    with open("{0}.stdout".format(fn), "w") as out:
        retval = call("mpirun -np 8 bin/mb {0}".format(fn), shell=True, stdout=out)
    
    return retval == 0


if __name__ == "__main__":

    try:
        fn = sys.argv[1] 
    except IndexError:
        fn = "test/run.nex"

    print("Running test with test data {0}, this may take a minute...".format(fn))
    print run(fn)<commit_msg>Saving results to database. Also, hardcoded db connection string file to mcollins home dir; need better solution.<commit_after>import sys
sys.path.append("../../lib")

import database
from celery import Celery
from subprocess import call

app = Celery('tasks', broker='amqp://idigphylo:<EMAIL>//')

@app.task
def add(x, y):
    return x + y


def save(fn):
    '''Save the resulting tree in .nex format to the MySQL database
    '''
    with open("{0}.con.tre".format(fn), "r") as tree_file:
        file_text = tree_file.read()
    db = database.Database()
    result = database.Result(job_id = "asdf",
                             result = file_text,
                             timestamp = db.mk_time()
                            )
    db.sess.add(result)
    db.sess.commit()

def run(fn):
    '''Execute MrBayes script
    '''
    processors = 8

    with open("{0}.stdout".format(fn), "w") as out:
        retval = call("mpirun -np {0} bin/mb {1}".format(processors, fn),
                      shell=True, stdout=out)
    
    return retval == 0


if __name__ == "__main__":

    try:
        fn = sys.argv[1] 
    except IndexError:
        fn = "test/run.nex"

    print("Running test with test data {0}, this may take a minute...".format(fn))
    print run(fn)
    save(fn)
{'fraction_non_alphanumeric': 0.1476147614761476, 'fraction_numerical': 0.0067506750675067504, 'mean_word_length': 2.3732928679817906, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '6919779', 'n_tokens_mistral': 745, 'n_tokens_neox': 725, 'n_words': 212}