Changeset - 63f767bcdf98
[Not reviewed]
default
0 3 0
domruf - 8 years ago 2017-08-16 23:21:43
dominikruf@gmail.com
commands: remove custom (re-)initializing of database model

The model has already beeen initialized through TurboGears after
make_app_without_logging has been called.

Since kallithea.lib.utils2.engine_from_config no longer is used, remove it.
All remaining references to engine_from_config are directly to the one from
sqlalchemy.
3 files changed with 0 insertions and 61 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/celerylib/__init__.py
Show inline comments
 
@@ -40,8 +40,6 @@ from kallithea.lib.pidlock import Daemon
 
from kallithea.model.base import init_model
 
from kallithea.model import meta
 

	
 
from sqlalchemy import engine_from_config
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
kallithea/lib/paster_commands/common.py
Show inline comments
 
@@ -77,8 +77,6 @@ class BasePasterCommand(gearbox.command.
 
                kallithea.config.middleware.make_app_without_logging(self.config.global_conf, **self.config.local_conf)
 
                # *now*, tg.config has been set and could be used ... but we just keep using self.config
 
                kallithea.lib.utils.setup_cache_regions(self.config)
 
                engine = kallithea.lib.utils2.engine_from_config(self.config, 'sqlalchemy.')
 
                kallithea.model.base.init_model(engine)
 

	
 
        return super(BasePasterCommand, self).run(args)
 

	
kallithea/lib/utils2.py
Show inline comments
 
@@ -260,63 +260,6 @@ def remove_prefix(s, prefix):
 
    return s
 

	
 

	
 
def engine_from_config(configuration, prefix='sqlalchemy.', **kwargs):
 
    """
 
    Custom engine_from_config functions that makes sure we use NullPool for
 
    file based sqlite databases. This prevents errors on sqlite. This only
 
    applies to sqlalchemy versions < 0.7.0
 

	
 
    """
 
    import sqlalchemy
 
    from sqlalchemy import engine_from_config as efc
 
    import logging
 

	
 
    if int(sqlalchemy.__version__.split('.')[1]) < 7:
 

	
 
        # This solution should work for sqlalchemy < 0.7.0, and should use
 
        # proxy=TimerProxy() for execution time profiling
 

	
 
        from sqlalchemy.pool import NullPool
 
        url = configuration[prefix + 'url']
 

	
 
        if url.startswith('sqlite'):
 
            kwargs.update({'poolclass': NullPool})
 
        return efc(configuration, prefix, **kwargs)
 
    else:
 
        import time
 
        from sqlalchemy import event
 

	
 
        log = logging.getLogger('sqlalchemy.engine')
 
        BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = xrange(30, 38)
 
        engine = efc(configuration, prefix, **kwargs)
 

	
 
        def color_sql(sql):
 
            COLOR_SEQ = "\033[1;%dm"
 
            COLOR_SQL = YELLOW
 
            normal = '\x1b[0m'
 
            return ''.join([COLOR_SEQ % COLOR_SQL, sql, normal])
 

	
 
        if configuration['debug']:
 
            # attach events only for debug configuration
 

	
 
            def before_cursor_execute(conn, cursor, statement,
 
                                    parameters, context, executemany):
 
                context._query_start_time = time.time()
 
                log.info(color_sql(">>>>> STARTING QUERY >>>>>"))
 

	
 
            def after_cursor_execute(conn, cursor, statement,
 
                                    parameters, context, executemany):
 
                total = time.time() - context._query_start_time
 
                log.info(color_sql("<<<<< TOTAL TIME: %f <<<<<" % total))
 

	
 
            event.listen(engine, "before_cursor_execute",
 
                         before_cursor_execute)
 
            event.listen(engine, "after_cursor_execute",
 
                         after_cursor_execute)
 

	
 
    return engine
 

	
 

	
 
def age(prevdate, show_short_version=False, now=None):
 
    """
 
    turns a datetime into an age string.
0 comments (0 inline, 0 general)