Source

wdmmg / wdmmg / model / __init__.py

"""The application's model objects"""
import mongo

from wdmmg.model.mongo import Base, KeyMeta
from wdmmg.model.dataset import Dataset
from wdmmg.model.classifier import Classifier
from wdmmg.model.entry import Entry
from wdmmg.model.entity import Entity

def init_mongo(config):
    host = config.get('mongodb.host', 'localhost')
    port = config.get('mongodb.port', 27017)
    mongo.make_connection(host, port) 
    mongo.db_name = config.get('mongodb.database', 'wdmmg')

# TODO: merge in mongo.drop_db
# is there a difference between drop_db and dropping all the collections
class Repository(object):
    def rebuild_db(self):
        self.delete_all()

    def delete_all(self):
        # very slow
        # mongo.drop_db
        db = mongo.db()
        for name in db.collection_names():
            if name not in ['system.indexes']:
                db.drop_collection(name)

repo = Repository()