changeset 6921:63f767bcdf98

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.
author domruf <dominikruf@gmail.com>
date Wed, 16 Aug 2017 23:21:43 +0200
parents 9cdb81c7b855
children f49e1b6cff90
files kallithea/lib/celerylib/__init__.py kallithea/lib/paster_commands/common.py kallithea/lib/utils2.py
diffstat 3 files changed, 0 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/celerylib/__init__.py	Tue Oct 03 00:14:40 2017 +0200
+++ b/kallithea/lib/celerylib/__init__.py	Wed Aug 16 23:21:43 2017 +0200
@@ -40,8 +40,6 @@
 from kallithea.model.base import init_model
 from kallithea.model import meta
 
-from sqlalchemy import engine_from_config
-
 
 log = logging.getLogger(__name__)
 
--- a/kallithea/lib/paster_commands/common.py	Tue Oct 03 00:14:40 2017 +0200
+++ b/kallithea/lib/paster_commands/common.py	Wed Aug 16 23:21:43 2017 +0200
@@ -77,8 +77,6 @@
                 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)
 
--- a/kallithea/lib/utils2.py	Tue Oct 03 00:14:40 2017 +0200
+++ b/kallithea/lib/utils2.py	Wed Aug 16 23:21:43 2017 +0200
@@ -260,63 +260,6 @@
     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.