Пример #1
0
def configure_backend(options):
    """
    Establish the database, create an engine if needed, and
    register the models.

    :param options: Mapping of configuration options
    """
    global _ENGINE
    if not _ENGINE:
        debug = config.get_option(
            options, 'debug', type='bool', default=False)
        verbose = config.get_option(
            options, 'verbose', type='bool', default=False)
        timeout = config.get_option(
            options, 'sql_idle_timeout', type='int', default=3600)

        if options['sql_connection'] == "sqlite://":
            _ENGINE = create_engine(options['sql_connection'],
                                    connect_args={'check_same_thread': False},
                                    poolclass=StaticPool)
        else:
            _ENGINE = create_engine(options['sql_connection'],
                pool_recycle=timeout)

        logger = logging.getLogger('sqlalchemy.engine')
        if debug:
            logger.setLevel(logging.DEBUG)
        elif verbose:
            logger.setLevel(logging.INFO)

        register_models(options)
Пример #2
0
def configure_backend(options):
    hosts = options['memcache_hosts']
    global MEMCACHE_SERVER
    if not MEMCACHE_SERVER:
        MEMCACHE_SERVER = Memcache_Server(hosts)
    register_models(options)
    global CACHE_TIME
    CACHE_TIME = config.get_option(
        options, 'cache_time', type='int', default=86400)
Пример #3
0
def configure_db(options):
    """
    Establish the database, create an engine if needed, and
    register the models.

    :param options: Mapping of configuration options
    """
    global _ENGINE
    if not _ENGINE:
        debug = config.get_option(options, "debug", type="bool", default=False)
        verbose = config.get_option(options, "verbose", type="bool", default=False)
        timeout = config.get_option(options, "sql_idle_timeout", type="int", default=3600)
        _ENGINE = create_engine(options["sql_connection"], pool_recycle=timeout)
        logger = logging.getLogger("sqlalchemy.engine")
        if debug:
            logger.setLevel(logging.DEBUG)
        elif verbose:
            logger.setLevel(logging.INFO)
        register_models()
Пример #4
0
def configure_backend(options):
    hosts = options['memcache_hosts']
    global MEMCACHE_SERVER
    if not MEMCACHE_SERVER:
        MEMCACHE_SERVER = Memcache_Server(hosts)
    register_models(options)
    global CACHE_TIME
    CACHE_TIME = config.get_option(options,
                                   'cache_time',
                                   type='int',
                                   default=86400)
Пример #5
0
def configure_backend(options):
    """
    Establish the database, create an engine if needed, and
    register the models.

    :param options: Mapping of configuration options
    """
    global _ENGINE
    if not _ENGINE:
        debug = config.get_option(options, 'debug', type='bool', default=False)
        verbose = config.get_option(options,
                                    'verbose',
                                    type='bool',
                                    default=False)
        timeout = config.get_option(options,
                                    'sql_idle_timeout',
                                    type='int',
                                    default=3600)

        if options['sql_connection'] == FOR_TESTING_ONLY:
            _ENGINE = create_engine('sqlite://',
                                    connect_args={'check_same_thread': False},
                                    poolclass=StaticPool)
        else:
            _ENGINE = create_engine(options['sql_connection'],
                                    pool_recycle=timeout)

        logger = logging.getLogger('sqlalchemy.engine')
        if debug:
            logger.setLevel(logging.DEBUG)
        elif verbose:
            logger.setLevel(logging.INFO)

        register_models(options)

        # this is TERRIBLE coupling, but...
        # if we're starting up a test database, load sample fixtures
        if options['sql_connection'] == FOR_TESTING_ONLY:
            from keystone.test import sampledata
            sampledata.load_fixture()
Пример #6
0
def configure_backend(options):
    """
    Establish the database, create an engine if needed, and
    register the models.

    :param options: Mapping of configuration options
    """
    global _ENGINE
    if not _ENGINE:
        debug = config.get_option(
            options, 'debug', type='bool', default=False)
        verbose = config.get_option(
            options, 'verbose', type='bool', default=False)
        timeout = config.get_option(
            options, 'sql_idle_timeout', type='int', default=3600)

        if options['sql_connection'] == FOR_TESTING_ONLY:
            _ENGINE = create_engine('sqlite://',
                connect_args={'check_same_thread': False},
                poolclass=StaticPool)
        else:
            _ENGINE = create_engine(options['sql_connection'],
                pool_recycle=timeout)

        logger = logging.getLogger('sqlalchemy.engine')
        if debug:
            logger.setLevel(logging.DEBUG)
        elif verbose:
            logger.setLevel(logging.INFO)

        register_models(options)

        # this is TERRIBLE coupling, but...
        # if we're starting up a test database, load sample fixtures
        if options['sql_connection'] == FOR_TESTING_ONLY:
            from keystone.test import sampledata
            sampledata.load_fixture()