changeset 6797:d8b7a1a023a6

gearbox: if a config file is specified, store it in the command instance so it is available without tg This will prevent a plain 'gearbox make-rcext -c kallithea.ini' from crashing in here = config['here'] Note: kallithea.CONFIG serves a very similar purpose. Modified by Mads Kiilerich.
author domruf <dominikruf@gmail.com>
date Sun, 11 Jun 2017 16:56:12 +0200
parents e40122629a01
children 6ca4f9f68eb5
files kallithea/lib/paster_commands/celeryd.py kallithea/lib/paster_commands/common.py kallithea/lib/paster_commands/make_index.py kallithea/lib/paster_commands/make_rcextensions.py kallithea/lib/paster_commands/setup_db.py
diffstat 5 files changed, 14 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/paster_commands/celeryd.py	Sat Aug 12 17:32:27 2017 +0200
+++ b/kallithea/lib/paster_commands/celeryd.py	Sun Jun 11 16:56:12 2017 +0200
@@ -20,9 +20,8 @@
 
     def take_action(self, args):
         from kallithea.lib import celerypylons
-        from tg import config
         try:
-            CELERY_ON = str2bool(config['app_conf'].get('use_celery'))
+            CELERY_ON = str2bool(self.config['app_conf'].get('use_celery'))
         except KeyError:
             CELERY_ON = False
 
@@ -31,7 +30,7 @@
                             'file before running celeryd')
         kallithea.CELERY_ON = CELERY_ON
 
-        load_rcextensions(config['here'])
+        load_rcextensions(self.config['here'])
         cmd = celerypylons.worker.worker(celerypylons.app.app_or_default())
 
         celery_args = args.celery_args
--- a/kallithea/lib/paster_commands/common.py	Sat Aug 12 17:32:27 2017 +0200
+++ b/kallithea/lib/paster_commands/common.py	Sun Jun 11 16:56:12 2017 +0200
@@ -31,7 +31,6 @@
 
 import paste.deploy
 import gearbox.command
-from tg import config
 
 import kallithea.config.middleware
 import kallithea.model.base
@@ -60,6 +59,7 @@
     # override to control how much get_parser and run should do:
     takes_config_file = True
     requires_db_session = True
+    config = None # set to the actual config object in run if takes_config_file is true
 
     def run(self, args):
         """
@@ -69,13 +69,15 @@
         """
         if self.takes_config_file:
             path_to_ini_file = os.path.realpath(args.config_file)
-            conf = paste.deploy.appconfig('config:' + path_to_ini_file)
+            self.config = paste.deploy.appconfig('config:' + path_to_ini_file)
+            # TODO: also initialize kallithea.CONFIG?
             logging.config.fileConfig(path_to_ini_file)
 
             if self.requires_db_session:
-                kallithea.config.middleware.make_app_without_logging(conf.global_conf, **conf.local_conf)
-                kallithea.lib.utils.setup_cache_regions(config)
-                engine = kallithea.lib.utils2.engine_from_config(config, 'sqlalchemy.')
+                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/paster_commands/make_index.py	Sat Aug 12 17:32:27 2017 +0200
+++ b/kallithea/lib/paster_commands/make_index.py	Sun Jun 11 16:56:12 2017 +0200
@@ -40,9 +40,8 @@
     "Kallithea: Create or update full text search index"
 
     def take_action(self, args):
-        from tg import config
-        index_location = config['index_dir']
-        load_rcextensions(config['here'])
+        index_location = self.config['index_dir']
+        load_rcextensions(self.config['here'])
 
         repo_location = args.repo_location \
             if args.repo_location else RepoModel().repos_path
--- a/kallithea/lib/paster_commands/make_rcextensions.py	Sat Aug 12 17:32:27 2017 +0200
+++ b/kallithea/lib/paster_commands/make_rcextensions.py	Sun Jun 11 16:56:12 2017 +0200
@@ -44,9 +44,7 @@
     requires_db_session = False
 
     def take_action(self, args):
-        from tg import config
-
-        here = config['here']
+        here = self.config['here']
         content = pkg_resources.resource_string(
             'kallithea', os.path.join('config', 'rcextensions', '__init__.py')
         )
--- a/kallithea/lib/paster_commands/setup_db.py	Sat Aug 12 17:32:27 2017 +0200
+++ b/kallithea/lib/paster_commands/setup_db.py	Sun Jun 11 16:56:12 2017 +0200
@@ -91,11 +91,8 @@
         return parser
 
     def take_action(self, opts):
-        path_to_ini_file = os.path.realpath(opts.config_file)
-        conf = paste.deploy.appconfig('config:' + path_to_ini_file)
-
-        dbconf = conf['sqlalchemy.url']
-        dbmanage = DbManage(dbconf=dbconf, root=conf['here'],
+        dbconf = self.config['sqlalchemy.url']
+        dbmanage = DbManage(dbconf=dbconf, root=self.config['here'],
                             tests=False, cli_args=vars(opts))
         dbmanage.create_tables(override=True)
         opts = dbmanage.config_prompt(None)