# HG changeset patch # User Mads Kiilerich # Date 1604267610 -3600 # Node ID 8f5bc94959dec30eecfb901f002b7817864033db # Parent 710512deb83dcc4725614ec0ee8cf99e7e1a034d lib: move check_git_version from utils to utils2 diff -r 710512deb83d -r 8f5bc94959de kallithea/config/app_cfg.py --- a/kallithea/config/app_cfg.py Sun Nov 01 23:50:29 2020 +0100 +++ b/kallithea/config/app_cfg.py Sun Nov 01 22:53:30 2020 +0100 @@ -34,8 +34,8 @@ import kallithea.model.base import kallithea.model.meta from kallithea.lib import celerypylons -from kallithea.lib.utils import check_git_version, load_extensions, set_app_settings, set_indexer_config, set_vcs_config -from kallithea.lib.utils2 import asbool +from kallithea.lib.utils import load_extensions, set_app_settings, set_indexer_config, set_vcs_config +from kallithea.lib.utils2 import asbool, check_git_version from kallithea.model import db diff -r 710512deb83d -r 8f5bc94959de kallithea/lib/utils.py --- a/kallithea/lib/utils.py Sun Nov 01 23:50:29 2020 +0100 +++ b/kallithea/lib/utils.py Sun Nov 01 22:53:30 2020 +0100 @@ -29,10 +29,8 @@ import logging import os import re -import sys import traceback import urllib.error -from distutils.version import StrictVersion import mercurial.config import mercurial.error @@ -44,7 +42,7 @@ 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 RepositoryError, VCSError +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.model import db, meta @@ -541,57 +539,6 @@ # MISC #============================================================================== -git_req_ver = StrictVersion('1.7.4') - -def check_git_version(): - """ - 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. - """ - if 'git' not in kallithea.BACKENDS: - return None - - if not settings.GIT_EXECUTABLE_PATH: - log.warning('No git executable configured - check "git_path" in the ini file.') - return None - - try: - stdout, stderr = GitRepository._run_git_command(['--version']) - except RepositoryError as e: - # message will already have been logged as error - log.warning('No working git executable found - check "git_path" in the ini file.') - return None - - if stderr: - log.warning('Error/stderr from "%s --version":\n%s', settings.GIT_EXECUTABLE_PATH, safe_str(stderr)) - - if not stdout: - log.warning('No working git executable found - check "git_path" in the ini file.') - return None - - output = safe_str(stdout).strip() - m = re.search(r"\d+.\d+.\d+", output) - if m: - ver = StrictVersion(m.group(0)) - log.debug('Git executable: "%s", version %s (parsed from: "%s")', - settings.GIT_EXECUTABLE_PATH, ver, output) - if ver < git_req_ver: - log.error('Kallithea detected %s version %s, which is too old ' - 'for the system to function properly. ' - 'Please upgrade to version %s or later. ' - 'If you strictly need Mercurial repositories, you can ' - 'clear the "git_path" setting in the ini file.', - settings.GIT_EXECUTABLE_PATH, ver, git_req_ver) - log.error("Terminating ...") - sys.exit(1) - else: - ver = StrictVersion('0.0.0') - log.warning('Error finding version number in "%s --version" stdout:\n%s', - settings.GIT_EXECUTABLE_PATH, output) - - return ver - - def extract_mentioned_users(text): """ Returns set of actual database Users @mentioned in given text. """ result = set() diff -r 710512deb83d -r 8f5bc94959de kallithea/lib/utils2.py --- a/kallithea/lib/utils2.py Sun Nov 01 23:50:29 2020 +0100 +++ b/kallithea/lib/utils2.py Sun Nov 01 22:53:30 2020 +0100 @@ -35,8 +35,10 @@ import os import re import string +import sys import time import urllib.parse +from distutils.version import StrictVersion import bcrypt import urlobject @@ -52,6 +54,8 @@ import kallithea from kallithea.lib import webutils from kallithea.lib.vcs.backends.base import BaseRepository, EmptyChangeset +from kallithea.lib.vcs.backends.git.repository import GitRepository +from kallithea.lib.vcs.conf import settings from kallithea.lib.vcs.exceptions import RepositoryError from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str # re-export from kallithea.lib.vcs.utils.lazy import LazyProperty @@ -620,3 +624,54 @@ return False log.error('check_password failed - no method found for hash length %s', len(hashed)) return False + + +git_req_ver = StrictVersion('1.7.4') + +def check_git_version(): + """ + 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. + """ + if 'git' not in kallithea.BACKENDS: + return None + + if not settings.GIT_EXECUTABLE_PATH: + log.warning('No git executable configured - check "git_path" in the ini file.') + return None + + try: + stdout, stderr = GitRepository._run_git_command(['--version']) + except RepositoryError as e: + # message will already have been logged as error + log.warning('No working git executable found - check "git_path" in the ini file.') + return None + + if stderr: + log.warning('Error/stderr from "%s --version":\n%s', settings.GIT_EXECUTABLE_PATH, safe_str(stderr)) + + if not stdout: + log.warning('No working git executable found - check "git_path" in the ini file.') + return None + + output = safe_str(stdout).strip() + m = re.search(r"\d+.\d+.\d+", output) + if m: + ver = StrictVersion(m.group(0)) + log.debug('Git executable: "%s", version %s (parsed from: "%s")', + settings.GIT_EXECUTABLE_PATH, ver, output) + if ver < git_req_ver: + log.error('Kallithea detected %s version %s, which is too old ' + 'for the system to function properly. ' + 'Please upgrade to version %s or later. ' + 'If you strictly need Mercurial repositories, you can ' + 'clear the "git_path" setting in the ini file.', + settings.GIT_EXECUTABLE_PATH, ver, git_req_ver) + log.error("Terminating ...") + sys.exit(1) + else: + ver = StrictVersion('0.0.0') + log.warning('Error finding version number in "%s --version" stdout:\n%s', + settings.GIT_EXECUTABLE_PATH, output) + + return ver diff -r 710512deb83d -r 8f5bc94959de kallithea/model/db.py --- a/kallithea/model/db.py Sun Nov 01 23:50:29 2020 +0100 +++ b/kallithea/model/db.py Sun Nov 01 22:53:30 2020 +0100 @@ -47,7 +47,8 @@ import kallithea from kallithea.lib import ext_json, ssh, webutils from kallithea.lib.exceptions import DefaultUserException -from kallithea.lib.utils2 import asbool, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, urlreadable +from kallithea.lib.utils2 import (asbool, ascii_bytes, aslist, check_git_version, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, + safe_str, urlreadable) from kallithea.lib.vcs import get_repo from kallithea.lib.vcs.backends.base import BaseChangeset, EmptyChangeset from kallithea.lib.vcs.utils import author_email, author_name @@ -309,7 +310,6 @@ import pkg_resources - from kallithea.lib.utils import check_git_version mods = [(p.project_name, p.version) for p in pkg_resources.working_set] info = { 'modules': sorted(mods, key=lambda k: k[0].lower()),