Mercurial > kallithea
changeset 8035:eefb46488667
lib: some cleanup of utils.py imports
Utils really shouldn't rely on model ...
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Wed, 25 Dec 2019 23:03:28 +0100 |
parents | ed78b4fbe2a3 |
children | e7b6a0ce123c |
files | kallithea/lib/utils.py |
diffstat | 1 files changed, 16 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/utils.py Thu Dec 26 05:13:25 2019 +0100 +++ b/kallithea/lib/utils.py Wed Dec 25 23:03:28 2019 +0100 @@ -37,15 +37,18 @@ from beaker.cache import _cache_decorate from tg.i18n import ugettext as _ +import kallithea.config.conf from kallithea.lib.exceptions import HgsubversionImportError -from kallithea.lib.utils2 import get_current_authuser, safe_str, safe_unicode +from kallithea.lib.utils2 import aslist, get_current_authuser, safe_str, safe_unicode +from kallithea.lib.vcs.backends.git.repository import GitRepository +from kallithea.lib.vcs.backends.hg.repository import MercurialRepository +from kallithea.lib.vcs.conf import settings from kallithea.lib.vcs.exceptions import VCSError from kallithea.lib.vcs.utils.fakemod import create_module from kallithea.lib.vcs.utils.helpers import get_scm from kallithea.lib.vcs.utils.hgcompat import config, ui from kallithea.model import meta from kallithea.model.db import RepoGroup, Repository, Setting, Ui, User, UserGroup, UserLog -from kallithea.model.repo_group import RepoGroupModel log = logging.getLogger(__name__) @@ -102,7 +105,6 @@ rest = '/' + rest_ repo_id = _get_permanent_id(first) if repo_id is not None: - from kallithea.model.db import Repository repo = Repository.get(repo_id) if repo is not None: return repo.repo_name + rest @@ -225,7 +227,6 @@ def is_valid_repo_uri(repo_type, url, ui): """Check if the url seems like a valid remote repo location - raise an Exception if any problems""" if repo_type == 'hg': - from kallithea.lib.vcs.backends.hg.repository import MercurialRepository if url.startswith('http') or url.startswith('ssh'): # initially check if it's at least the proper URL # or does it pass basic auth @@ -243,7 +244,6 @@ raise Exception('URI %s not allowed' % (url,)) elif repo_type == 'git': - from kallithea.lib.vcs.backends.git.repository import GitRepository if url.startswith('http') or url.startswith('git'): # initially check if it's at least the proper URL # or does it pass basic auth @@ -387,16 +387,14 @@ :param config: kallithea.CONFIG """ - from kallithea.lib.vcs import conf - from kallithea.lib.utils2 import aslist - conf.settings.BACKENDS = { + settings.BACKENDS = { 'hg': 'kallithea.lib.vcs.backends.hg.MercurialRepository', 'git': 'kallithea.lib.vcs.backends.git.GitRepository', } - conf.settings.GIT_EXECUTABLE_PATH = config.get('git_path', 'git') - conf.settings.GIT_REV_FILTER = config.get('git_rev_filter', '--all').strip() - conf.settings.DEFAULT_ENCODINGS = aslist(config.get('default_encoding', + settings.GIT_EXECUTABLE_PATH = config.get('git_path', 'git') + settings.GIT_REV_FILTER = config.get('git_rev_filter', '--all').strip() + settings.DEFAULT_ENCODINGS = aslist(config.get('default_encoding', 'utf-8'), sep=',') @@ -406,13 +404,11 @@ :param config: kallithea.CONFIG """ - from kallithea.config import conf - log.debug('adding extra into INDEX_EXTENSIONS') - conf.INDEX_EXTENSIONS.extend(re.split(r'\s+', config.get('index.extensions', ''))) + kallithea.config.conf.INDEX_EXTENSIONS.extend(re.split(r'\s+', config.get('index.extensions', ''))) log.debug('adding extra into INDEX_FILENAMES') - conf.INDEX_FILENAMES.extend(re.split(r'\s+', config.get('index.filenames', ''))) + kallithea.config.conf.INDEX_FILENAMES.extend(re.split(r'\s+', config.get('index.filenames', ''))) def map_groups(path): @@ -423,6 +419,7 @@ :param paths: full path to repository """ + from kallithea.model.repo_group import RepoGroupModel sa = meta.Session() groups = path.split(Repository.url_sep()) parent = None @@ -540,9 +537,6 @@ def load_rcextensions(root_path): - import kallithea - from kallithea.config import conf - path = os.path.join(root_path, 'rcextensions', '__init__.py') if os.path.isfile(path): rcext = create_module('rc', path) @@ -550,17 +544,17 @@ log.debug('Found rcextensions now loading %s...', rcext) # Additional mappings that are not present in the pygments lexers - conf.LANGUAGES_EXTENSIONS_MAP.update(getattr(EXT, 'EXTRA_MAPPINGS', {})) + kallithea.config.conf.LANGUAGES_EXTENSIONS_MAP.update(getattr(EXT, 'EXTRA_MAPPINGS', {})) # OVERRIDE OUR EXTENSIONS FROM RC-EXTENSIONS (if present) if getattr(EXT, 'INDEX_EXTENSIONS', []): log.debug('settings custom INDEX_EXTENSIONS') - conf.INDEX_EXTENSIONS = getattr(EXT, 'INDEX_EXTENSIONS', []) + kallithea.config.conf.INDEX_EXTENSIONS = getattr(EXT, 'INDEX_EXTENSIONS', []) # ADDITIONAL MAPPINGS log.debug('adding extra into INDEX_EXTENSIONS') - conf.INDEX_EXTENSIONS.extend(getattr(EXT, 'EXTRA_INDEX_EXTENSIONS', [])) + kallithea.config.conf.INDEX_EXTENSIONS.extend(getattr(EXT, 'EXTRA_INDEX_EXTENSIONS', [])) # auto check if the module is not missing any data, set to default if is # this will help autoupdate new feature of rcext module @@ -581,11 +575,7 @@ Checks what version of git is installed on the system, and raise a system exit if it's too old for Kallithea to work properly. """ - from kallithea import BACKENDS - from kallithea.lib.vcs.backends.git.repository import GitRepository - from kallithea.lib.vcs.conf import settings - - if 'git' not in BACKENDS: + if 'git' not in kallithea.BACKENDS: return None if not settings.GIT_EXECUTABLE_PATH: