check git version and safe for runtime

This commit is contained in:
Matthias 2022-02-28 00:17:21 +01:00
parent c882d1f89b
commit bae290d605
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076
3 changed files with 25 additions and 0 deletions

View File

@ -10,6 +10,7 @@ from maintenance_mode.core import set_maintenance_mode
from InvenTree.ready import isImportingData
from plugin import registry
from plugin.helpers import check_git_version
logger = logging.getLogger('inventree')
@ -34,3 +35,6 @@ class PluginAppConfig(AppConfig):
# drop out of maintenance
# makes sure we did not have an error in reloading and maintenance is still active
set_maintenance_mode(False)
# check git version
registry.git_is_modern = check_git_version()

View File

@ -108,6 +108,26 @@ def get_git_log(path):
output = 7 * [''] # pragma: no cover
return {'hash': output[0], 'author': output[1], 'mail': output[2], 'date': output[3], 'message': output[4], 'verified': output[5], 'key': output[6]}
def check_git_version():
"""returns if the current git version supports modern features"""
# get version string
try:
output = str(subprocess.check_output(['git', '--version'], cwd=os.path.dirname(settings.BASE_DIR)), 'utf-8')
except subprocess.CalledProcessError: # pragma: no cover
return False
# process version string
try:
version = output[12:-1].split(".")
if len(version) > 1 and version[0] == '2':
if len(version) > 2 and int(version[1]) >= 22:
return True
except ValueError:
pass
return False
class GitStatus:
"""

View File

@ -52,6 +52,7 @@ class PluginsRegistry:
# flags
self.is_loading = False
self.apps_loading = True # Marks if apps were reloaded yet
self.git_is_modern = True # Is a modern version of git available
# integration specific
self.installed_apps = [] # Holds all added plugin_paths