changeset 6594:a844ea41da7e

paster_commands: inline helper methods - they don't help much
author Mads Kiilerich <mads@kiilerich.com>
date Thu, 13 Apr 2017 02:05:24 +0200
parents 167df0c8d191
children 21d210d29d7f
files kallithea/lib/paster_commands/common.py
diffstat 1 files changed, 16 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/paster_commands/common.py	Mon Apr 10 13:15:52 2017 +0300
+++ b/kallithea/lib/paster_commands/common.py	Thu Apr 13 02:05:24 2017 +0200
@@ -31,6 +31,12 @@
 
 import paste.deploy
 import gearbox.command
+from tg import config
+
+import kallithea.config.middleware
+import kallithea.model.base
+import kallithea.lib.utils2
+import kallithea.lib.utils
 
 
 def ask_ok(prompt, retries=4, complaint='Yes or no please!'):
@@ -59,12 +65,18 @@
         """
         Overrides Command.run
 
-        Checks for a config file argument and loads it.
+        If needed by the command, read config file and initialize database before running.
         """
         if self.takes_config_file:
-             self._bootstrap_config(args.config_file)
-             if self.requires_db_session:
-                  self._init_session()
+            path_to_ini_file = os.path.realpath(args.config_file)
+            conf = paste.deploy.appconfig('config:' + path_to_ini_file)
+            logging.config.fileConfig(path_to_ini_file)
+            kallithea.config.middleware.make_app(conf.global_conf, **conf.local_conf)
+
+            if self.requires_db_session:
+                kallithea.lib.utils.setup_cache_regions(config)
+                engine = kallithea.lib.utils2.engine_from_config(config, 'sqlalchemy.')
+                kallithea.model.base.init_model(engine)
 
         return super(BasePasterCommand, self).run(args)
 
@@ -78,30 +90,6 @@
 
         return parser
 
-    def _bootstrap_config(self, config_file):
-        """
-        Read the config file and initialize logging and the application.
-        """
-        from kallithea.config.middleware import make_app
-
-        path_to_ini_file = os.path.realpath(config_file)
-        conf = paste.deploy.appconfig('config:' + path_to_ini_file)
-        logging.config.fileConfig(path_to_ini_file)
-        make_app(conf.global_conf, **conf.local_conf)
-
-    def _init_session(self):
-        """
-        Initialize SqlAlchemy Session from global config.
-        """
-
-        from tg import config
-        from kallithea.model.base import init_model
-        from kallithea.lib.utils2 import engine_from_config
-        from kallithea.lib.utils import setup_cache_regions
-        setup_cache_regions(config)
-        engine = engine_from_config(config, 'sqlalchemy.')
-        init_model(engine)
-
     def error(self, msg, exitcode=1):
         """Write error message and exit"""
         sys.stderr.write('%s\n' % msg)