Exemple #1
0
def initialize(address='127.0.0.1:27017', database_name='hfos'):
    global schemastore
    global objectmodels
    global collections

    hfoslog("Testing database availability to ", address, lvl=debug,
            emitter='DB')

    try:
        client = pymongo.MongoClient(host=address.split(":")[0], port=int(
            address.split(":")[1]) if ":" in address else 27017)
        db = client[database_name]
        hfoslog("Database: ", db.command('buildinfo'), lvl=debug, emitter='DB')
    except Exception as e:
        hfoslog("No database available! Check if you have mongodb > 3.0 "
                "installed and running as well as listening on port 27017 "
                "of localhost. (Error: %s) -> EXIT" % e, lvl=critical,
                emitter='DB')
        sys.exit(5)

    warmongo.connect(database_name)

    schemastore = _build_schemastore_new()
    objectmodels = _build_model_factories(schemastore)
    collections = _build_collections(schemastore)
Exemple #2
0
def initialize(address='127.0.0.1:27017', database_name='hfos'):
    global schemastore
    global objectmodels
    global collections

    hfoslog("Testing database availability to ",
            address,
            lvl=debug,
            emitter='DB')

    try:
        client = pymongo.MongoClient(
            host=address.split(":")[0],
            port=int(address.split(":")[1]) if ":" in address else 27017)
        db = client[database_name]
        hfoslog("Database: ", db.command('buildinfo'), lvl=debug, emitter='DB')
    except Exception as e:
        hfoslog("No database available! Check if you have mongodb > 3.0 "
                "installed and running as well as listening on port 27017 "
                "of localhost. (Error: %s) -> EXIT" % e,
                lvl=critical,
                emitter='DB')
        sys.exit(5)

    warmongo.connect(database_name)

    schemastore = _build_schemastore_new()
    objectmodels = _build_model_factories(schemastore)
    collections = _build_collections(schemastore)
Exemple #3
0
    def setUp(self):
        self.schema = {
            'name': 'Country',
            'properties': {
                'name': {'type': 'string'},
                'abbreviation': {'type': 'string'},
                'languages': {
                    'type': ['array', 'null'],
                    'items': {
                        'type': 'string'
                    }
                }
            },
            'additionalProperties': False,
        }

        # Connect to warmongo_test - hopefully it doesn't exist
        warmongo.connect("warmongo_test")
        self.Country = warmongo.model_factory(self.schema)

        # Drop all the data in it
        self.Country.collection().remove({})

        # Create some defaults
        self.Country({
            "name": "Sweden",
            "abbreviation": "SE",
            "languages": ["swedish"]
        })
        self.Country({
            "name": "United States of America",
            "abbreviation": "US",
            "languages": ["english"]
        })
Exemple #4
0
    def setUp(self):
        self.schema = {
            'name': 'Country',
            'properties': {
                'name': {
                    'type': 'string'
                },
                'abbreviation': {
                    'type': 'string'
                },
                'languages': {
                    'type': 'array',
                    'items': {
                        'type': 'string'
                    }
                }
            },
            'additionalProperties': False,
        }

        # Connect to warmongo_test - hopefully it doesn't exist
        warmongo.connect("warmongo_test")
        self.Country = warmongo.model_factory(self.schema)

        # Drop all the data in it
        self.Country.collection().remove({})

        # Create some defaults
        sweden = self.Country({
            "name": "Sweden",
            "abbreviation": "SE",
            "languages": ["swedish"]
        })
        sweden.save()
        usa = self.Country({
            "name": "United States of America",
            "abbreviation": "US",
            "languages": ["english"]
        })
        usa.save()
Exemple #5
0
    sure = input("Are you sure to drop the complete database content?")
    if not (sure.upper() in ("Y", "J")):
        sys.exit(5)

    import pymongo

    client = pymongo.MongoClient(host="localhost", port=27017)
    db = client["hfos"]

    for col in db.collection_names(include_system_collections=False):
        hfoslog("[DB] Dropping collection ", col, lvl=warn)
        db.drop_collection(col)


warmongo.connect("hfos")


def _buildModelFactories():
    result = {}

    for schemaname in schemastore:

        schema = None

        try:
            schema = schemastore[schemaname]['schema']
        except KeyError:
            hfoslog("[DB] No schema found for ", schemaname, lvl=critical)

        try:
Exemple #6
0
    sure = input("Are you sure to drop the complete database content?")
    if not (sure.upper() in ("Y", "J")):
        sys.exit(5)

    import pymongo

    client = pymongo.MongoClient(host="localhost", port=27017)
    db = client["hfos"]

    for col in db.collection_names(include_system_collections=False):
        hfoslog("[DB] Dropping collection ", col, lvl=warn)
        db.drop_collection(col)


warmongo.connect("hfos")


def _buildModelFactories():
    result = {}

    for schemaname in schemastore:

        schema = None

        try:
            schema = schemastore[schemaname]['schema']
        except KeyError:
            hfoslog("[DB] No schema found for ", schemaname, lvl=critical)

        try: