mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-27 19:16:44 +00:00
[Setup] Enhance version information output (#9049)
* Improve output of 'invoke version' - Display backup path - Handle undefined paths without error * Provide colorized output
This commit is contained in:
parent
49824ddf31
commit
3a423c3e40
@ -238,12 +238,15 @@ def get_boolean_setting(env_var=None, config_key=None, default_value=False):
|
||||
return is_true(get_setting(env_var, config_key, default_value))
|
||||
|
||||
|
||||
def get_media_dir(create=True):
|
||||
def get_media_dir(create=True, error=True):
|
||||
"""Return the absolute path for the 'media' directory (where uploaded files are stored)."""
|
||||
md = get_setting('INVENTREE_MEDIA_ROOT', 'media_root')
|
||||
|
||||
if not md:
|
||||
raise FileNotFoundError('INVENTREE_MEDIA_ROOT not specified')
|
||||
if error:
|
||||
raise FileNotFoundError('INVENTREE_MEDIA_ROOT not specified')
|
||||
else:
|
||||
return None
|
||||
|
||||
md = Path(md).resolve()
|
||||
|
||||
@ -253,12 +256,15 @@ def get_media_dir(create=True):
|
||||
return md
|
||||
|
||||
|
||||
def get_static_dir(create=True):
|
||||
def get_static_dir(create=True, error=True):
|
||||
"""Return the absolute path for the 'static' directory (where static files are stored)."""
|
||||
sd = get_setting('INVENTREE_STATIC_ROOT', 'static_root')
|
||||
|
||||
if not sd:
|
||||
raise FileNotFoundError('INVENTREE_STATIC_ROOT not specified')
|
||||
if error:
|
||||
raise FileNotFoundError('INVENTREE_STATIC_ROOT not specified')
|
||||
else:
|
||||
return None
|
||||
|
||||
sd = Path(sd).resolve()
|
||||
|
||||
@ -268,12 +274,15 @@ def get_static_dir(create=True):
|
||||
return sd
|
||||
|
||||
|
||||
def get_backup_dir(create=True):
|
||||
def get_backup_dir(create=True, error=True):
|
||||
"""Return the absolute path for the backup directory."""
|
||||
bd = get_setting('INVENTREE_BACKUP_DIR', 'backup_dir')
|
||||
|
||||
if not bd:
|
||||
raise FileNotFoundError('INVENTREE_BACKUP_DIR not specified')
|
||||
if error:
|
||||
raise FileNotFoundError('INVENTREE_BACKUP_DIR not specified')
|
||||
else:
|
||||
return None
|
||||
|
||||
bd = Path(bd).resolve()
|
||||
|
||||
|
29
tasks.py
29
tasks.py
@ -49,28 +49,33 @@ def task_exception_handler(t, v, tb):
|
||||
sys.excepthook = task_exception_handler
|
||||
|
||||
|
||||
def wrap_color(text: str, color: str) -> str:
|
||||
"""Wrap text in a color code."""
|
||||
return f'\033[{color}m{text}\033[0m'
|
||||
|
||||
|
||||
def success(*args):
|
||||
"""Print a success message to the console."""
|
||||
msg = ' '.join(map(str, args))
|
||||
print(f'\033[92m{msg}\033[0m')
|
||||
print(wrap_color(msg, '92'))
|
||||
|
||||
|
||||
def error(*args):
|
||||
"""Print an error message to the console."""
|
||||
msg = ' '.join(map(str, args))
|
||||
print(f'\033[91m{msg}\033[0m')
|
||||
print(wrap_color(msg, '91'))
|
||||
|
||||
|
||||
def warning(*args):
|
||||
"""Print a warning message to the console."""
|
||||
msg = ' '.join(map(str, args))
|
||||
print(f'\033[93m{msg}\033[0m')
|
||||
print(wrap_color(msg, '93'))
|
||||
|
||||
|
||||
def info(*args):
|
||||
"""Print an informational message to the console."""
|
||||
msg = ' '.join(map(str, args))
|
||||
print(f'\033[94m{msg}\033[0m')
|
||||
print(wrap_color(msg, '94'))
|
||||
|
||||
|
||||
def checkInvokeVersion():
|
||||
@ -1284,6 +1289,7 @@ def version(c):
|
||||
"""Show the current version of InvenTree."""
|
||||
import src.backend.InvenTree.InvenTree.version as InvenTreeVersion
|
||||
from src.backend.InvenTree.InvenTree.config import (
|
||||
get_backup_dir,
|
||||
get_config_file,
|
||||
get_media_dir,
|
||||
get_static_dir,
|
||||
@ -1292,6 +1298,10 @@ def version(c):
|
||||
# Gather frontend version information
|
||||
_, node, yarn = node_available(versions=True)
|
||||
|
||||
# Special output messages
|
||||
NOT_SPECIFIED = wrap_color('NOT SPECIFIED', '91')
|
||||
NA = wrap_color('N/A', '93')
|
||||
|
||||
print(
|
||||
f"""
|
||||
InvenTree - inventree.org
|
||||
@ -1304,16 +1314,17 @@ Environment {sys.prefix}
|
||||
Installation paths:
|
||||
Base {localDir()}
|
||||
Config {get_config_file()}
|
||||
Media {get_media_dir()}
|
||||
Static {get_static_dir()}
|
||||
Media {get_media_dir(error=False) or NOT_SPECIFIED}
|
||||
Static {get_static_dir(error=False) or NOT_SPECIFIED}
|
||||
Backup {get_backup_dir(error=False) or NOT_SPECIFIED}
|
||||
|
||||
Versions:
|
||||
Python {python_version()}
|
||||
Django {InvenTreeVersion.inventreeDjangoVersion()}
|
||||
InvenTree {InvenTreeVersion.inventreeVersion()}
|
||||
API {InvenTreeVersion.inventreeApiVersion()}
|
||||
Node {node if node else 'N/A'}
|
||||
Yarn {yarn if yarn else 'N/A'}
|
||||
Node {node if node else NA}
|
||||
Yarn {yarn if yarn else NA}
|
||||
|
||||
Commit hash: {InvenTreeVersion.inventreeCommitHash()}
|
||||
Commit date: {InvenTreeVersion.inventreeCommitDate()}"""
|
||||
@ -1321,7 +1332,7 @@ Commit date: {InvenTreeVersion.inventreeCommitDate()}"""
|
||||
if len(sys.argv) == 1 and sys.argv[0].startswith('/opt/inventree/env/lib/python'):
|
||||
print(
|
||||
"""
|
||||
You are probably running the package installer / single-line installer. Please mentioned that in any bug reports!
|
||||
You are probably running the package installer / single-line installer. Please mention this in any bug reports!
|
||||
|
||||
Use '--list' for a list of available commands
|
||||
Use '--help' for help on a specific command"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user