2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

Add more version information (#5014)

* Add info for installer, branch, publisher

* include version info

* fix permissions

* fix typo

* add more info

* use GH url

* fix node

* remove publisher

* remove more logging

* Add info to version view

* enable branch discovery when not set

* fix ref to github version

* add branch to about dialog

* use precise plattform information - if no env is set

* fix ref names

* load VERSION info

* rename plattform to target

* extend installer var

* add generic plattform info

* add docs for version info

* add more info

* add installer codes

* Ammend navigation
This commit is contained in:
Matthias Mair
2023-06-11 16:32:03 +02:00
committed by GitHub
parent f3a13fc625
commit 15ab911da6
11 changed files with 177 additions and 0 deletions

View File

@ -22,6 +22,7 @@ from django.http import Http404
from django.utils.translation import gettext_lazy as _
import moneyed
from dotenv import load_dotenv
from InvenTree.config import get_boolean_setting, get_custom_file, get_setting
from InvenTree.sentry import default_sentry_dsn, init_sentry
@ -65,6 +66,12 @@ BASE_DIR = config.get_base_dir()
# Load configuration data
CONFIG = config.load_config_data(set_cache=True)
# Load VERSION data if it exists
version_file = BASE_DIR.parent.joinpath('VERSION')
if version_file.exists():
print('load version from file')
load_dotenv(version_file)
# Default action is to run the system in Debug mode
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = get_boolean_setting('INVENTREE_DEBUG', 'debug', True)

View File

@ -5,11 +5,13 @@ Provides information on the current InvenTree version
import os
import pathlib
import platform
import re
from datetime import datetime as dt
from datetime import timedelta as td
import django
from django.conf import settings
from dulwich.repo import NotGitRepository, Repo
@ -130,3 +132,48 @@ def inventreeCommitDate():
commit_dt = dt.fromtimestamp(main_commit.commit_time) + td(seconds=main_commit.commit_timezone)
return str(commit_dt.date())
def inventreeInstaller():
"""Returns the installer for the running codebase - if set."""
# First look in the environment variables, e.g. if running in docker
installer = os.environ.get('INVENTREE_PKG_INSTALLER', '')
if installer:
return installer
elif settings.DOCKER:
return 'DOC'
elif main_commit is not None:
return 'GIT'
return None
def inventreeBranch():
"""Returns the branch for the running codebase - if set."""
# First look in the environment variables, e.g. if running in docker
branch = os.environ.get('INVENTREE_PKG_BRANCH', '')
if branch:
return branch
if main_commit is None:
return None
branch = main_repo.refs.follow(b'HEAD')[0][1].decode()
return branch.removeprefix('refs/heads/')
def inventreeTarget():
"""Returns the target platform for the running codebase - if set."""
# First look in the environment variables, e.g. if running in docker
return os.environ.get('INVENTREE_PKG_TARGET', None)
def inventreePlatform():
"""Returns the platform for the instance."""
return platform.platform(aliased=True)

View File

@ -287,6 +287,30 @@ def inventree_commit_date(*args, **kwargs):
return version.inventreeCommitDate()
@register.simple_tag()
def inventree_installer(*args, **kwargs):
"""Return InvenTree package installer string."""
return version.inventreeInstaller()
@register.simple_tag()
def inventree_branch(*args, **kwargs):
"""Return InvenTree git branch string."""
return version.inventreeBranch()
@register.simple_tag()
def inventree_target(*args, **kwargs):
"""Return InvenTree target string."""
return version.inventreeTarget()
@register.simple_tag()
def inventree_platform(*args, **kwargs):
"""Return InvenTree platform string."""
return version.inventreePlatform()
@register.simple_tag()
def inventree_github_url(*args, **kwargs):
"""Return URL for InvenTree github site."""

View File

@ -36,6 +36,13 @@
<td>{% trans "Commit Date" %}</td><td>{% render_date commit_date %}{% include "clip.html" %}</td>
</tr>
{% endif %}
{% inventree_branch as branch %}
{% if branch %}
<tr>
<td><span class='fas fa-code-branch'></span></td>
<td>{% trans "Commit Branch" %}</td><td>{{ branch }}{% include "clip.html" %}</td>
</tr>
{% endif %}
{% endif %}
<tr>
<td><span class='fas fa-book'></span></td>

View File

@ -3,7 +3,11 @@ InvenTree-Version: {% inventree_version %}
Django Version: {% django_version %}
{% inventree_commit_hash as hash %}{% if hash %}Commit Hash: {{ hash }}{% endif %}
{% inventree_commit_date as commit_date %}{% if commit_date %}Commit Date: {% render_date commit_date %}{% endif %}
{% inventree_branch as branch %}{% if branch %}Commit Branch: {{ branch }}{% endif %}
Database: {% inventree_db_engine %}
Debug-Mode: {% inventree_in_debug_mode %}
Deployed using Docker: {% inventree_docker_mode %}
Platform: {% inventree_platform %}
Installer: {% inventree_installer %}
{% inventree_target as target %}{% if target %}Target: {{ target }}{% endif %}
Active plugins: {% plugins_info %}