Example #1
0
def count_settings(ga_config=None) -> int:
    d = {}

    if ga_config is not None:
        d['module'] = str(ga_config.__module__) + "." + str(
            ga_config.__class__.__name__)
        d.update(ga_config.make_dict())

    db = MongoDBConnection.get_settings_db()
    return db.count_documents(d)
Example #2
0
def find_settings(ga_config=None) -> pymongo.cursor.Cursor:
    d = {}

    if ga_config is not None:
        d['module'] = str(ga_config.__module__) + "." + str(
            ga_config.__class__.__name__)
        d.update(ga_config.make_dict())

    db = MongoDBConnection.get_settings_db()
    return db.find(d)
Example #3
0
def get_settings_obj(settings_name: str):
    db = MongoDBConnection.get_settings_db()
    settings = db.find_one({"_id": settings_name})

    if settings is not None:
        whole_path_str = settings['module']

        index = whole_path_str.rfind(".")
        module_str = whole_path_str[0:index]
        class_str = whole_path_str[index + 1:]

        module = importlib.import_module(module_str)
        my_class = getattr(module, class_str)

        return my_class.load_from_dict(settings)
    else:
        raise RuntimeError("Unknown settings {0}".format(settings_name))
Example #4
0
def save_settings(settings_name: str, ga_config):
    db = MongoDBConnection.get_settings_db()
    settings = db.find_one({"_id": settings_name})

    if settings is None:
        config_properties = dict(ga_config.serialize())
        config_properties['_id'] = settings_name

        path = str(ga_config.__module__) + "." + str(
            ga_config.__class__.__name__)
        config_properties['module'] = path

        db.insert_one(config_properties)
    else:
        raise RuntimeError(
            "{0} already exists in the settings database".format(
                settings_name))
Example #5
0
def get_settings(settings_name: str) -> Dict:
    db = MongoDBConnection.get_settings_db()
    settings = db.find_one({"_id": settings_name})
    return settings
Example #6
0
def remove_settings(settings: List[str]):
    db = MongoDBConnection.get_settings_db()
    db.remove({'_id': {'$in': settings}})
Example #7
0
def update_settings(settings_name: str, ga_config):
    db = MongoDBConnection.get_settings_db()
    db.update_one({'_id': settings_name}, {'$set': ga_config.serialize()})