Changeset - 2ff983214ea0
[Not reviewed]
default
0 6 0
Mads Kiilerich (mads) - 5 years ago 2020-10-11 01:07:51
mads@kiilerich.com
Grafted from: 590d7b14321f
imports: always import the whole kallithea module to use top level kallithea variables

This is slightly more lazy and might avoid some depeendency issues.
6 files changed with 23 insertions and 31 deletions:
0 comments (0 inline, 0 general)
docs/conf.py
Show inline comments
 
@@ -14,7 +14,7 @@
 
import os
 
import sys
 

	
 
from kallithea import __version__
 
import kallithea
 

	
 

	
 
# If extensions (or modules to document with autodoc) are in another directory,
 
@@ -56,9 +56,9 @@ copyright = '2010-2020 by various author
 
# The short X.Y version.
 
root = os.path.dirname(os.path.dirname(__file__))
 
sys.path.append(root)
 
version = __version__
 
version = kallithea.__version__
 
# The full version, including alpha/beta/rc tags.
 
release = __version__
 
release = kallithea.__version__
 

	
 
# The language for content autogenerated by Sphinx. Refer to documentation
 
# for a list of supported languages.
kallithea/lib/base.py
Show inline comments
 
@@ -43,7 +43,7 @@ from tg import TGController, config, ren
 
from tg import tmpl_context as c
 
from tg.i18n import ugettext as _
 

	
 
from kallithea import BACKENDS, __version__
 
import kallithea
 
from kallithea.config.routing import url
 
from kallithea.lib import auth_modules, ext_json
 
from kallithea.lib.auth import AuthUser, HasPermissionAnyMiddleware
 
@@ -368,7 +368,7 @@ class BaseController(TGController):
 
                log.error('CSRF check failed')
 
                raise webob.exc.HTTPForbidden()
 

	
 
        c.kallithea_version = __version__
 
        c.kallithea_version = kallithea.__version__
 
        rc_config = Setting.get_app_settings()
 

	
 
        # Visual options
 
@@ -413,7 +413,7 @@ class BaseController(TGController):
 
        # END CONFIG VARS
 

	
 
        c.repo_name = get_repo_slug(request)  # can be empty
 
        c.backends = list(BACKENDS)
 
        c.backends = list(kallithea.BACKENDS)
 

	
 
        self.cut_off_limit = safe_int(config.get('cut_off_limit'))
 

	
kallithea/lib/hooks.py
Show inline comments
 
@@ -31,6 +31,7 @@ import time
 

	
 
import mercurial.scmutil
 

	
 
import kallithea
 
from kallithea.lib import helpers as h
 
from kallithea.lib.exceptions import UserCreationError
 
from kallithea.lib.utils import action_logger, make_ui
 
@@ -94,8 +95,7 @@ def log_pull_action(ui, repo, **kwargs):
 
    action = 'pull'
 
    action_logger(user, action, ex.repository, ex.ip, commit=True)
 
    # extension hook call
 
    from kallithea import EXTENSIONS
 
    callback = getattr(EXTENSIONS, 'PULL_HOOK', None)
 
    callback = getattr(kallithea.EXTENSIONS, 'PULL_HOOK', None)
 
    if callable(callback):
 
        kw = {}
 
        kw.update(ex)
 
@@ -133,8 +133,7 @@ def process_pushed_raw_ids(revs):
 
    ScmModel().mark_for_invalidation(ex.repository)
 

	
 
    # extension hook call
 
    from kallithea import EXTENSIONS
 
    callback = getattr(EXTENSIONS, 'PUSH_HOOK', None)
 
    callback = getattr(kallithea.EXTENSIONS, 'PUSH_HOOK', None)
 
    if callable(callback):
 
        kw = {'pushed_revs': revs}
 
        kw.update(ex)
 
@@ -164,8 +163,7 @@ def log_create_repository(repository_dic
 
     'repo_name'
 

	
 
    """
 
    from kallithea import EXTENSIONS
 
    callback = getattr(EXTENSIONS, 'CREATE_REPO_HOOK', None)
 
    callback = getattr(kallithea.EXTENSIONS, 'CREATE_REPO_HOOK', None)
 
    if callable(callback):
 
        kw = {}
 
        kw.update(repository_dict)
 
@@ -176,8 +174,7 @@ def log_create_repository(repository_dic
 

	
 
def check_allowed_create_user(user_dict, created_by, **kwargs):
 
    # pre create hooks
 
    from kallithea import EXTENSIONS
 
    callback = getattr(EXTENSIONS, 'PRE_CREATE_USER_HOOK', None)
 
    callback = getattr(kallithea.EXTENSIONS, 'PRE_CREATE_USER_HOOK', None)
 
    if callable(callback):
 
        allowed, reason = callback(created_by=created_by, **user_dict)
 
        if not allowed:
 
@@ -212,8 +209,7 @@ def log_create_user(user_dict, created_b
 
     'emails',
 

	
 
    """
 
    from kallithea import EXTENSIONS
 
    callback = getattr(EXTENSIONS, 'CREATE_USER_HOOK', None)
 
    callback = getattr(kallithea.EXTENSIONS, 'CREATE_USER_HOOK', None)
 
    if callable(callback):
 
        callback(created_by=created_by, **user_dict)
 

	
 
@@ -224,8 +220,7 @@ def log_create_pullrequest(pullrequest_d
 

	
 
    :param pullrequest_dict: dict dump of pull request object
 
    """
 
    from kallithea import EXTENSIONS
 
    callback = getattr(EXTENSIONS, 'CREATE_PULLREQUEST_HOOK', None)
 
    callback = getattr(kallithea.EXTENSIONS, 'CREATE_PULLREQUEST_HOOK', None)
 
    if callable(callback):
 
        return callback(created_by=created_by, **pullrequest_dict)
 

	
 
@@ -254,8 +249,7 @@ def log_delete_repository(repository_dic
 
     'repo_name'
 

	
 
    """
 
    from kallithea import EXTENSIONS
 
    callback = getattr(EXTENSIONS, 'DELETE_REPO_HOOK', None)
 
    callback = getattr(kallithea.EXTENSIONS, 'DELETE_REPO_HOOK', None)
 
    if callable(callback):
 
        kw = {}
 
        kw.update(repository_dict)
 
@@ -293,8 +287,7 @@ def log_delete_user(user_dict, deleted_b
 
     'emails',
 

	
 
    """
 
    from kallithea import EXTENSIONS
 
    callback = getattr(EXTENSIONS, 'DELETE_USER_HOOK', None)
 
    callback = getattr(kallithea.EXTENSIONS, 'DELETE_USER_HOOK', None)
 
    if callable(callback):
 
        callback(deleted_by=deleted_by, **user_dict)
 

	
kallithea/lib/utils2.py
Show inline comments
 
@@ -41,6 +41,7 @@ from tg.i18n import ungettext
 
from tg.support.converters import asbool, aslist
 
from webhelpers2.text import collapse, remove_formatting, strip_tags
 

	
 
import kallithea
 
from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str  # re-export
 
from kallithea.lib.vcs.utils.lazy import LazyProperty
 

	
 
@@ -442,14 +443,13 @@ def set_hook_environment(username, ip_ad
 

	
 
    Must always be called before anything with hooks are invoked.
 
    """
 
    from kallithea import CONFIG
 
    extras = {
 
        'ip': ip_addr, # used in log_push/pull_action action_logger
 
        'username': username,
 
        'action': action or 'push_local', # used in log_push_action_raw_ids action_logger
 
        'repository': repo_name,
 
        'scm': repo_alias, # used to pick hack in log_push_action_raw_ids
 
        'config': CONFIG['__file__'], # used by git hook to read config
 
        'config': kallithea.CONFIG['__file__'], # used by git hook to read config
 
    }
 
    os.environ['KALLITHEA_EXTRAS'] = json.dumps(extras)
 

	
kallithea/model/forms.py
Show inline comments
 
@@ -39,7 +39,7 @@ import formencode
 
from formencode import All
 
from tg.i18n import ugettext as _
 

	
 
from kallithea import BACKENDS
 
import kallithea
 
from kallithea.model import validators as v
 

	
 

	
 
@@ -238,7 +238,7 @@ def PasswordResetConfirmationForm():
 
    return _PasswordResetConfirmationForm
 

	
 

	
 
def RepoForm(edit=False, old_data=None, supported_backends=BACKENDS,
 
def RepoForm(edit=False, old_data=None, supported_backends=kallithea.BACKENDS,
 
             repo_groups=None, landing_revs=None):
 
    old_data = old_data or {}
 
    repo_groups = repo_groups or []
 
@@ -315,7 +315,7 @@ def RepoFieldForm():
 
    return _RepoFieldForm
 

	
 

	
 
def RepoForkForm(edit=False, old_data=None, supported_backends=BACKENDS,
 
def RepoForkForm(edit=False, old_data=None, supported_backends=kallithea.BACKENDS,
 
                 repo_groups=None, landing_revs=None):
 
    old_data = old_data or {}
 
    repo_groups = repo_groups or []
 
@@ -431,7 +431,7 @@ def CustomDefaultPermissionsForm():
 
    return _CustomDefaultPermissionsForm
 

	
 

	
 
def DefaultsForm(edit=False, old_data=None, supported_backends=BACKENDS):
 
def DefaultsForm(edit=False, old_data=None, supported_backends=kallithea.BACKENDS):
 
    class _DefaultsForm(formencode.Schema):
 
        allow_extra_fields = True
 
        filter_extra_fields = True
kallithea/model/scm.py
Show inline comments
 
@@ -36,7 +36,6 @@ import pkg_resources
 
from tg.i18n import ugettext as _
 

	
 
import kallithea
 
from kallithea import BACKENDS
 
from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoPermissionLevel, HasUserGroupPermissionLevel
 
from kallithea.lib.exceptions import IMCCommitError, NonRelativePathError
 
from kallithea.lib.hooks import process_pushed_raw_ids
 
@@ -188,10 +187,10 @@ class ScmModel(object):
 

	
 
                    klass = get_backend(path[0])
 

	
 
                    if path[0] == 'hg' and path[0] in BACKENDS:
 
                    if path[0] == 'hg' and path[0] in kallithea.BACKENDS:
 
                        repos[name] = klass(path[1], baseui=baseui)
 

	
 
                    if path[0] == 'git' and path[0] in BACKENDS:
 
                    if path[0] == 'git' and path[0] in kallithea.BACKENDS:
 
                        repos[name] = klass(path[1])
 
            except OSError:
 
                continue
0 comments (0 inline, 0 general)