Changeset - c184df63e470
[Not reviewed]
default
0 2 0
Mads Kiilerich - 9 years ago 2017-04-13 02:25:59
mads@kiilerich.com
lib: reduce impact of bad import cycle

Follow-up to e0f31c7d0f5e.

It is unfortunate that generic lib code depends on
kallithea.lib.paster_commands.common - it would make more sense if it was the
other way around. We thus move the import down to inside the function that
needs it.

The import of kallithea.lib.paster_commands.common in db_manage triggered its
import of logging.config . middleware.py thus also got logging.config when it
just imported logging and things worked. Without this import of
paster_commands, we also have to fix the import in db_manage.
2 files changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
kallithea/config/middleware.py
Show inline comments
 
@@ -4,25 +4,25 @@
 
# the Free Software Foundation, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
"""WSGI middleware initialization for the Kallithea application."""
 

	
 
import logging
 
import logging.config
 
from kallithea.config.app_cfg import base_config
 
from kallithea.config.environment import load_environment
 

	
 
__all__ = ['make_app']
 

	
 
# Use base_config to setup the necessary PasteDeploy application factory.
 
# make_base_app will wrap the TurboGears2 app with all the middleware it needs.
 
make_base_app = base_config.setup_tg_wsgi_app(load_environment)
 

	
 

	
 
def make_app(global_conf, full_stack=True, **app_conf):
 
    """
kallithea/lib/db_manage.py
Show inline comments
 
@@ -27,25 +27,24 @@ Original author and date, and relevant c
 
"""
 

	
 
import os
 
import sys
 
import time
 
import uuid
 
import logging
 
from os.path import dirname
 

	
 
import alembic.config
 
import alembic.command
 

	
 
from kallithea.lib.paster_commands.common import ask_ok
 
from kallithea.model.user import UserModel
 
from kallithea.model.base import init_model
 
from kallithea.model.db import User, Permission, Ui, \
 
    Setting, UserToPerm, RepoGroup, \
 
    UserRepoGroupToPerm, CacheInvalidation, Repository
 

	
 
from sqlalchemy.engine import create_engine
 
from kallithea.model.repo_group import RepoGroupModel
 
#from kallithea.model import meta
 
from kallithea.model.meta import Session, Base
 
from kallithea.model.repo import RepoModel
 
from kallithea.model.permission import PermissionModel
 
@@ -69,24 +68,25 @@ class DbManage(object):
 
        self.root = root
 
        self.dburi = dbconf
 
        self.log_sql = log_sql
 
        self.db_exists = False
 
        self.cli_args = cli_args or {}
 
        self.init_db(SESSION=SESSION)
 

	
 
    def _ask_ok(self, msg):
 
        """Invoke ask_ok unless the force_ask option provides the answer"""
 
        force_ask = self.cli_args.get('force_ask')
 
        if force_ask is not None:
 
            return force_ask
 
        from kallithea.lib.paster_commands.common import ask_ok
 
        return ask_ok(msg)
 

	
 
    def init_db(self, SESSION=None):
 
        if SESSION:
 
            self.sa = SESSION
 
        else:
 
            #init new sessions
 
            engine = create_engine(self.dburi, echo=self.log_sql)
 
            init_model(engine)
 
            self.sa = Session()
 

	
 
    def create_tables(self, override=False):
0 comments (0 inline, 0 general)