<commit_before>#!/usr/bin/env python
import os
import sys
import optparse
import inspect

import pybossa.model as model
from pybossa.core import db
import pybossa.web as web

from alembic.config import Config
from alembic import command

def setup_alembic_config():
    if "DATABASE_URL" not in os.environ:
        alembic_cfg = Config("alembic.ini")
    else:
        dynamic_filename = "alembic-heroku.ini"
        with file("alembic.ini.template") as f:
            with file(dynamic_filename, "w") as conf:
                for line in f.readlines():
                    if line.startswith("sqlalchemy.url"):
                        conf.write("sqlalchemy.url = %s\n" % 
                                   os.environ['DATABASE_URL'])
                    else:
                        conf.write(line)
        alembic_cfg = Config(dynamic_filename)

    command.stamp(alembic_cfg, "head")

def db_create():
    '''Create the db'''
    db.create_all()
    # then, load the Alembic configuration and generate the
    # version table, "stamping" it with the most recent rev:
    setup_alembic_config()

def db_rebuild():
    '''Rebuild the db'''
    db.drop_all()
    db.create_all()
    # then, load the Alembic configuration and generate the
    # version table, "stamping" it with the most recent rev:
    setup_alembic_config()

def fixtures():
    '''Create some fixtures!'''
    user = model.User(
        name=u'tester',
        email_addr=u'<EMAIL>',
        api_key='tester'
        )
    user.set_password(u'<PASSWORD>')
    db.session.add(user)
    db.session.commit()


## ==================================================<commit_msg>db_create populates the Categories<commit_after>#!/usr/bin/env python
import os
import sys
import optparse
import inspect

import pybossa.model as model
from pybossa.core import db
import pybossa.web as web

from alembic.config import Config
from alembic import command

def setup_alembic_config():
    if "DATABASE_URL" not in os.environ:
        alembic_cfg = Config("alembic.ini")
    else:
        dynamic_filename = "alembic-heroku.ini"
        with file("alembic.ini.template") as f:
            with file(dynamic_filename, "w") as conf:
                for line in f.readlines():
                    if line.startswith("sqlalchemy.url"):
                        conf.write("sqlalchemy.url = %s\n" %
                                   os.environ['DATABASE_URL'])
                    else:
                        conf.write(line)
        alembic_cfg = Config(dynamic_filename)

    command.stamp(alembic_cfg, "head")

def db_create():
    '''Create the db'''
    db.create_all()
    # then, load the Alembic configuration and generate the
    # version table, "stamping" it with the most recent rev:
    setup_alembic_config()
    # finally, add a minimum set of categories: Volunteer Thinking, Volunteer Sensing, Published and Draft
    categories = []
    categories.append(model.Category(name="Volunteer Thinking"))
    categories.append(model.Category(name="Volunteer Sensing"))
    categories.append(model.Category(name="Published"))
    categories.append(model.Category(name="Draft"))
    db.session.add_all(categories)
    db.session.commit()

def db_rebuild():
    '''Rebuild the db'''
    db.drop_all()
    db.create_all()
    # then, load the Alembic configuration and generate the
    # version table, "stamping" it with the most recent rev:
    setup_alembic_config()

def fixtures():
    '''Create some fixtures!'''
    user = model.User(
        name=u'tester',
        email_addr=u'<EMAIL>',
        api_key='tester'
        )
    user.set_password(u'<PASSWORD>')
    db.session.add(user)
    db.session.commit()


## ==================================================
{'fraction_non_alphanumeric': 0.13279785809906292, 'fraction_numerical': 0.0, 'mean_word_length': 2.673549655850541, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1701828', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1116, 'n_words': 282}