Ejemplo n.º 1
0
    def load_db_params(self, gc):
        self.databases = tuple(self.to_iter(gc["databases"]))
        self.db_params = {}
        if not self.databases:
            return

        dbm = db_manager.db_manager()
        db_param_names = ("name", "db_host", "db_user", "db_pass", "pool_size", "max_overflow")
        for db_name in self.databases:
            conf_params = self.to_iter(gc[db_name + "_db"])
            params = dict(zip(db_param_names, conf_params))
            dbm.engines[db_name] = db_manager.get_engine(**params)
            self.db_params[db_name] = params

        dbm.type_db = dbm.engines[gc["type_db"]]
        dbm.relation_type_db = dbm.engines[gc["rel_type_db"]]

        prefix = "db_table_"
        for k, v in gc.iteritems():
            if k.startswith(prefix):
                params = list(self.to_iter(v))
                name = k[len(prefix) :]
                kind = params[0]
                if kind == "thing":
                    dbm.add_thing(name, [dbm.engines[n] for n in params[1:]])
                elif kind == "relation":
                    dbm.add_relation(name, params[1], params[2], [dbm.engines[n] for n in params[3:]])
        return dbm
Ejemplo n.º 2
0
    def load_db_params(self, gc):
        self.databases = tuple(self.to_iter(gc['databases']))
        self.db_params = {}
        if not self.databases:
            return

        dbm = db_manager.db_manager()
        db_param_names = ('name', 'db_host', 'db_user', 'db_pass',
                          'pool_size', 'max_overflow')
        for db_name in self.databases:
            conf_params = self.to_iter(gc[db_name + '_db'])
            params = dict(zip(db_param_names, conf_params))
            dbm.engines[db_name] = db_manager.get_engine(**params)
            self.db_params[db_name] = params

        dbm.type_db = dbm.engines[gc['type_db']]
        dbm.relation_type_db = dbm.engines[gc['rel_type_db']]

        prefix = 'db_table_'
        for k, v in gc.iteritems():
            if k.startswith(prefix):
                params = list(self.to_iter(v))
                name = k[len(prefix):]
                kind = params[0]
                if kind == 'thing':
                    dbm.add_thing(name, [dbm.engines[n] for n in params[1:]])
                elif kind == 'relation':
                    dbm.add_relation(name, params[1], params[2],
                                     [dbm.engines[n] for n in params[3:]])
        return dbm
Ejemplo n.º 3
0
    def load_db_params(self, gc):
        from r2.lib.services import get_db_load

        self.databases = tuple(self.to_iter(gc['databases']))
        self.db_params = {}
        if not self.databases:
            return

        dbm = db_manager.db_manager()
        db_param_names = ('name', 'db_host', 'db_user', 'db_pass', 'db_port',
                          'pool_size', 'max_overflow')
        for db_name in self.databases:
            conf_params = self.to_iter(gc[db_name + '_db'])
            params = dict(zip(db_param_names, conf_params))
            if params['db_user'] == "*":
                params['db_user'] = self.db_user
            if params['db_pass'] == "*":
                params['db_pass'] = self.db_pass
            if params['db_port'] == "*":
                params['db_port'] = self.db_port

            if params['pool_size'] == "*":
                params['pool_size'] = self.db_pool_size
            if params['max_overflow'] == "*":
                params['max_overflow'] = self.db_pool_overflow_size

            ip = params['db_host']
            ip_loads = get_db_load(self.servicecache, ip)
            if ip not in ip_loads or ip_loads[ip][0] < 1000:
                dbm.setup_db(db_name, g_override=self, **params)
            self.db_params[db_name] = params

        dbm.type_db = dbm.get_engine(gc['type_db'])
        dbm.relation_type_db = dbm.get_engine(gc['rel_type_db'])

        def split_flags(p):
            return ([n for n in p if not n.startswith("!")],
                    dict((n.strip('!'), True) for n in p if n.startswith("!")))

        prefix = 'db_table_'
        for k, v in gc.iteritems():
            if k.startswith(prefix):
                params = list(self.to_iter(v))
                name = k[len(prefix):]
                kind = params[0]
                if kind == 'thing':
                    engines, flags = split_flags(params[1:])
                    dbm.add_thing(name, dbm.get_engines(engines),
                                  **flags)
                elif kind == 'relation':
                    engines, flags = split_flags(params[3:])
                    dbm.add_relation(name, params[1], params[2],
                                     dbm.get_engines(engines),
                                     **flags)
        return dbm
Ejemplo n.º 4
0
    def load_db_params(self, gc):
        from r2.lib.services import get_db_load

        self.databases = tuple(self.to_iter(gc['databases']))
        self.db_params = {}
        if not self.databases:
            return

        dbm = db_manager.db_manager()
        db_param_names = ('name', 'db_host', 'db_user', 'db_pass', 'db_port',
                          'pool_size', 'max_overflow')
        for db_name in self.databases:
            conf_params = self.to_iter(gc[db_name + '_db'])
            params = dict(zip(db_param_names, conf_params))
            if params['db_user'] == "*":
                params['db_user'] = self.db_user
            if params['db_pass'] == "*":
                params['db_pass'] = self.db_pass
            if params['db_port'] == "*":
                params['db_port'] = self.db_port

            if params['pool_size'] == "*":
                params['pool_size'] = self.db_pool_size
            if params['max_overflow'] == "*":
                params['max_overflow'] = self.db_pool_overflow_size

            ip = params['db_host']
            ip_loads = get_db_load(self.servicecache, ip)
            if ip not in ip_loads or ip_loads[ip][0] < 1000:
                dbm.setup_db(db_name, g_override=self, **params)
            self.db_params[db_name] = params

        dbm.type_db = dbm.get_engine(gc['type_db'])
        dbm.relation_type_db = dbm.get_engine(gc['rel_type_db'])

        def split_flags(p):
            return ([n for n in p if not n.startswith("!")],
                    dict((n.strip('!'), True) for n in p if n.startswith("!")))

        prefix = 'db_table_'
        for k, v in gc.iteritems():
            if k.startswith(prefix):
                params = list(self.to_iter(v))
                name = k[len(prefix):]
                kind = params[0]
                if kind == 'thing':
                    engines, flags = split_flags(params[1:])
                    dbm.add_thing(name, dbm.get_engines(engines), **flags)
                elif kind == 'relation':
                    engines, flags = split_flags(params[3:])
                    dbm.add_relation(name, params[1], params[2],
                                     dbm.get_engines(engines), **flags)
        return dbm
Ejemplo n.º 5
0
    def load_db_params(self):
        self.databases = tuple(ConfigValue.to_iter(self.config.raw_data['databases']))
        self.db_params = {}
        if not self.databases:
            return

        dbm = db_manager.db_manager()
        db_param_names = ('name', 'db_host', 'db_user', 'db_pass', 'db_port',
                          'pool_size', 'max_overflow')
        for db_name in self.databases:
            conf_params = ConfigValue.to_iter(self.config.raw_data[db_name + '_db'])
            params = dict(zip(db_param_names, conf_params))
            if params['db_user'] == "*":
                params['db_user'] = self.db_user
            if params['db_pass'] == "*":
                params['db_pass'] = self.db_pass
            if params['db_port'] == "*":
                params['db_port'] = self.db_port

            if params['pool_size'] == "*":
                params['pool_size'] = self.db_pool_size
            if params['max_overflow'] == "*":
                params['max_overflow'] = self.db_pool_overflow_size

            dbm.setup_db(db_name, g_override=self, **params)
            self.db_params[db_name] = params

        dbm.type_db = dbm.get_engine(self.config.raw_data['type_db'])
        dbm.relation_type_db = dbm.get_engine(self.config.raw_data['rel_type_db'])

        def split_flags(p):
            return ([n for n in p if not n.startswith("!")],
                    dict((n.strip('!'), True) for n in p if n.startswith("!")))

        prefix = 'db_table_'
        for k, v in self.config.raw_data.iteritems():
            if k.startswith(prefix):
                params = list(ConfigValue.to_iter(v))
                name = k[len(prefix):]
                kind = params[0]
                if kind == 'thing':
                    engines, flags = split_flags(params[1:])
                    dbm.add_thing(name, dbm.get_engines(engines),
                                  **flags)
                elif kind == 'relation':
                    engines, flags = split_flags(params[3:])
                    dbm.add_relation(name, params[1], params[2],
                                     dbm.get_engines(engines),
                                     **flags)
        return dbm
Ejemplo n.º 6
0
    def load_db_params(self, gc):
        self.databases = tuple(self.to_iter(gc['databases']))
        self.db_params = {}
        if not self.databases:
            return

        dbm = db_manager.db_manager()
        db_param_names = ('name', 'db_host', 'db_user', 'db_pass', 'pool_size',
                          'max_overflow')
        for db_name in self.databases:
            conf_params = self.to_iter(gc[db_name + '_db'])
            params = dict(zip(db_param_names, conf_params))
            if params['db_user'] == "*":
                params['db_user'] = self.db_user
            if params['db_pass'] == "*":
                params['db_pass'] = self.db_pass
            dbm.setup_db(db_name, **params)
            self.db_params[db_name] = params

        dbm.type_db = dbm.get_engine(gc['type_db'])
        dbm.relation_type_db = dbm.get_engine(gc['rel_type_db'])
        dbm.hardcache_db = dbm.get_engine(gc['hardcache_db'])

        def split_flags(p):
            return ([n for n in p if not n.startswith("!")],
                    dict((n.strip('!'), True) for n in p if n.startswith("!")))

        prefix = 'db_table_'
        for k, v in gc.iteritems():
            if k.startswith(prefix):
                params = list(self.to_iter(v))
                name = k[len(prefix):]
                kind = params[0]
                if kind == 'thing':
                    engines, flags = split_flags(params[1:])
                    dbm.add_thing(name, [dbm.get_engine(n) for n in engines],
                                  **flags)
                elif kind == 'relation':
                    engines, flags = split_flags(params[3:])
                    dbm.add_relation(name, params[1], params[2],
                                     [dbm.get_engine(n) for n in engines],
                                     **flags)
        return dbm
Ejemplo n.º 7
0
# Original Code is CondeNet, Inc.
# 
# All portions of the code written by CondeNet are Copyright (c) 2006-2008
# CondeNet, Inc. All Rights Reserved.
################################################################################
from r2.lib.manager import db_manager
from pylons import g
try:
    #TODO: move?
    from r2admin.config.databases import *
except:
    pass

tz = g.tz

dbm = db_manager.db_manager()

main_engine = db_manager.get_engine(g.main_db_name,
                                    db_host = g.main_db_host,
                                    db_user = g.main_db_user,
                                    db_pass = g.main_db_pass)

comment_engine = db_manager.get_engine(g.comment_db_name,
                                    db_host = g.comment_db_host,
                                    db_user = g.comment_db_user,
                                    db_pass = g.comment_db_pass)

vote_engine = db_manager.get_engine(g.vote_db_name,
                                    db_host = g.vote_db_host,
                                    db_user = g.vote_db_user,
                                    db_pass = g.vote_db_pass)
Ejemplo n.º 8
0
    def load_db_params(self):
        self.databases = tuple(
            ConfigValue.to_iter(self.config.raw_data['databases']))
        self.db_params = {}
        if not self.databases:
            return

        dbm = db_manager.db_manager()
        db_param_names = ('name', 'db_host', 'db_user', 'db_pass', 'db_port',
                          'pool_size', 'max_overflow')
        for db_name in self.databases:
            conf_params = ConfigValue.to_iter(self.config.raw_data[db_name +
                                                                   '_db'])
            params = dict(zip(db_param_names, conf_params))
            if params['db_user'] == "*":
                params['db_user'] = self.db_user
            if params['db_pass'] == "*":
                params['db_pass'] = self.db_pass
            if params['db_port'] == "*":
                params['db_port'] = self.db_port

            if params['pool_size'] == "*":
                params['pool_size'] = self.db_pool_size
            if params['max_overflow'] == "*":
                params['max_overflow'] = self.db_pool_overflow_size

            dbm.setup_db(db_name, g_override=self, **params)
            self.db_params[db_name] = params

        dbm.type_db = dbm.get_engine(self.config.raw_data['type_db'])
        dbm.relation_type_db = dbm.get_engine(
            self.config.raw_data['rel_type_db'])

        def split_flags(raw_params):
            params = []
            flags = {}

            for param in raw_params:
                if not param.startswith("!"):
                    params.append(param)
                else:
                    key, sep, value = param[1:].partition("=")
                    if sep:
                        flags[key] = value
                    else:
                        flags[key] = True

            return params, flags

        prefix = 'db_table_'
        self.predefined_type_ids = {}
        for k, v in self.config.raw_data.iteritems():
            if not k.startswith(prefix):
                continue

            params, table_flags = split_flags(ConfigValue.to_iter(v))
            name = k[len(prefix):]
            kind = params[0]
            server_list = self.config.raw_data["db_servers_" + name]
            engines, flags = split_flags(ConfigValue.to_iter(server_list))

            typeid = table_flags.get("typeid")
            if typeid:
                self.predefined_type_ids[name] = int(typeid)

            if kind == 'thing':
                dbm.add_thing(name, dbm.get_engines(engines), **flags)
            elif kind == 'relation':
                dbm.add_relation(name, params[1], params[2],
                                 dbm.get_engines(engines), **flags)
        return dbm
Ejemplo n.º 9
0
    def load_db_params(self):
        self.databases = tuple(ConfigValue.to_iter(self.config.raw_data['databases']))
        self.db_params = {}
        if not self.databases:
            return

        dbm = db_manager.db_manager()
        db_param_names = ('name', 'db_host', 'db_user', 'db_pass', 'db_port',
                          'pool_size', 'max_overflow')
        for db_name in self.databases:
            conf_params = ConfigValue.to_iter(self.config.raw_data[db_name + '_db'])
            params = dict(zip(db_param_names, conf_params))
            if params['db_user'] == "*":
                params['db_user'] = self.db_user
            if params['db_pass'] == "*":
                params['db_pass'] = self.db_pass
            if params['db_port'] == "*":
                params['db_port'] = self.db_port

            if params['pool_size'] == "*":
                params['pool_size'] = self.db_pool_size
            if params['max_overflow'] == "*":
                params['max_overflow'] = self.db_pool_overflow_size

            dbm.setup_db(db_name, g_override=self, **params)
            self.db_params[db_name] = params

        dbm.type_db = dbm.get_engine(self.config.raw_data['type_db'])
        dbm.relation_type_db = dbm.get_engine(self.config.raw_data['rel_type_db'])

        def split_flags(raw_params):
            params = []
            flags = {}

            for param in raw_params:
                if not param.startswith("!"):
                    params.append(param)
                else:
                    key, sep, value = param[1:].partition("=")
                    if sep:
                        flags[key] = value
                    else:
                        flags[key] = True

            return params, flags

        prefix = 'db_table_'
        self.predefined_type_ids = {}
        for k, v in self.config.raw_data.iteritems():
            if not k.startswith(prefix):
                continue

            params, table_flags = split_flags(ConfigValue.to_iter(v))
            name = k[len(prefix):]
            kind = params[0]
            server_list = self.config.raw_data["db_servers_" + name]
            engines, flags = split_flags(ConfigValue.to_iter(server_list))

            typeid = table_flags.get("typeid")
            if typeid:
                self.predefined_type_ids[name] = int(typeid)

            if kind == 'thing':
                dbm.add_thing(name, dbm.get_engines(engines),
                              **flags)
            elif kind == 'relation':
                dbm.add_relation(name, params[1], params[2],
                                 dbm.get_engines(engines),
                                 **flags)
        return dbm
Ejemplo n.º 10
0
# Original Code is CondeNet, Inc.
#
# All portions of the code written by CondeNet are Copyright (c) 2006-2008
# CondeNet, Inc. All Rights Reserved.
################################################################################
from r2.lib.manager import db_manager
from pylons import g
try:
    #TODO: move?
    from r2admin.config.databases import *
except:
    pass

tz = g.tz

dbm = db_manager.db_manager()

main_engine = db_manager.get_engine(g.main_db_name,
                                    db_host=g.main_db_host,
                                    db_user=g.main_db_user,
                                    db_pass=g.main_db_pass)

comment_engine = db_manager.get_engine(g.comment_db_name,
                                       db_host=g.comment_db_host,
                                       db_user=g.comment_db_user,
                                       db_pass=g.comment_db_pass)

vote_engine = db_manager.get_engine(g.vote_db_name,
                                    db_host=g.vote_db_host,
                                    db_user=g.vote_db_user,
                                    db_pass=g.vote_db_pass)
Ejemplo n.º 11
0
    def load_db_params(self):
        self.databases = tuple(ConfigValue.to_iter(self.config.raw_data["databases"]))
        self.db_params = {}
        self.predefined_type_ids = {}
        if not self.databases:
            return

        if self.env == "unit_test":
            from mock import MagicMock

            return MagicMock()

        dbm = db_manager.db_manager()
        db_param_names = ("name", "db_host", "db_user", "db_pass", "db_port", "pool_size", "max_overflow")
        for db_name in self.databases:
            conf_params = ConfigValue.to_iter(self.config.raw_data[db_name + "_db"])
            params = dict(zip(db_param_names, conf_params))
            if params["db_user"] == "*":
                params["db_user"] = self.db_user
            if params["db_pass"] == "*":
                params["db_pass"] = self.db_pass
            if params["db_port"] == "*":
                params["db_port"] = self.db_port

            if params["pool_size"] == "*":
                params["pool_size"] = self.db_pool_size
            if params["max_overflow"] == "*":
                params["max_overflow"] = self.db_pool_overflow_size

            dbm.setup_db(db_name, g_override=self, **params)
            self.db_params[db_name] = params

        dbm.type_db = dbm.get_engine(self.config.raw_data["type_db"])
        dbm.relation_type_db = dbm.get_engine(self.config.raw_data["rel_type_db"])

        def split_flags(raw_params):
            params = []
            flags = {}

            for param in raw_params:
                if not param.startswith("!"):
                    params.append(param)
                else:
                    key, sep, value = param[1:].partition("=")
                    if sep:
                        flags[key] = value
                    else:
                        flags[key] = True

            return params, flags

        prefix = "db_table_"
        for k, v in self.config.raw_data.iteritems():
            if not k.startswith(prefix):
                continue

            params, table_flags = split_flags(ConfigValue.to_iter(v))
            name = k[len(prefix) :]
            kind = params[0]
            server_list = self.config.raw_data["db_servers_" + name]
            engines, flags = split_flags(ConfigValue.to_iter(server_list))

            typeid = table_flags.get("typeid")
            if typeid:
                self.predefined_type_ids[name] = int(typeid)

            if kind == "thing":
                dbm.add_thing(name, dbm.get_engines(engines), **flags)
            elif kind == "relation":
                dbm.add_relation(name, params[1], params[2], dbm.get_engines(engines), **flags)
        return dbm