mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 03:26:45 +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))
|
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)."""
|
"""Return the absolute path for the 'media' directory (where uploaded files are stored)."""
|
||||||
md = get_setting('INVENTREE_MEDIA_ROOT', 'media_root')
|
md = get_setting('INVENTREE_MEDIA_ROOT', 'media_root')
|
||||||
|
|
||||||
if not md:
|
if not md:
|
||||||
|
if error:
|
||||||
raise FileNotFoundError('INVENTREE_MEDIA_ROOT not specified')
|
raise FileNotFoundError('INVENTREE_MEDIA_ROOT not specified')
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
md = Path(md).resolve()
|
md = Path(md).resolve()
|
||||||
|
|
||||||
@ -253,12 +256,15 @@ def get_media_dir(create=True):
|
|||||||
return md
|
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)."""
|
"""Return the absolute path for the 'static' directory (where static files are stored)."""
|
||||||
sd = get_setting('INVENTREE_STATIC_ROOT', 'static_root')
|
sd = get_setting('INVENTREE_STATIC_ROOT', 'static_root')
|
||||||
|
|
||||||
if not sd:
|
if not sd:
|
||||||
|
if error:
|
||||||
raise FileNotFoundError('INVENTREE_STATIC_ROOT not specified')
|
raise FileNotFoundError('INVENTREE_STATIC_ROOT not specified')
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
sd = Path(sd).resolve()
|
sd = Path(sd).resolve()
|
||||||
|
|
||||||
@ -268,12 +274,15 @@ def get_static_dir(create=True):
|
|||||||
return sd
|
return sd
|
||||||
|
|
||||||
|
|
||||||
def get_backup_dir(create=True):
|
def get_backup_dir(create=True, error=True):
|
||||||
"""Return the absolute path for the backup directory."""
|
"""Return the absolute path for the backup directory."""
|
||||||
bd = get_setting('INVENTREE_BACKUP_DIR', 'backup_dir')
|
bd = get_setting('INVENTREE_BACKUP_DIR', 'backup_dir')
|
||||||
|
|
||||||
if not bd:
|
if not bd:
|
||||||
|
if error:
|
||||||
raise FileNotFoundError('INVENTREE_BACKUP_DIR not specified')
|
raise FileNotFoundError('INVENTREE_BACKUP_DIR not specified')
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
bd = Path(bd).resolve()
|
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
|
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):
|
def success(*args):
|
||||||
"""Print a success message to the console."""
|
"""Print a success message to the console."""
|
||||||
msg = ' '.join(map(str, args))
|
msg = ' '.join(map(str, args))
|
||||||
print(f'\033[92m{msg}\033[0m')
|
print(wrap_color(msg, '92'))
|
||||||
|
|
||||||
|
|
||||||
def error(*args):
|
def error(*args):
|
||||||
"""Print an error message to the console."""
|
"""Print an error message to the console."""
|
||||||
msg = ' '.join(map(str, args))
|
msg = ' '.join(map(str, args))
|
||||||
print(f'\033[91m{msg}\033[0m')
|
print(wrap_color(msg, '91'))
|
||||||
|
|
||||||
|
|
||||||
def warning(*args):
|
def warning(*args):
|
||||||
"""Print a warning message to the console."""
|
"""Print a warning message to the console."""
|
||||||
msg = ' '.join(map(str, args))
|
msg = ' '.join(map(str, args))
|
||||||
print(f'\033[93m{msg}\033[0m')
|
print(wrap_color(msg, '93'))
|
||||||
|
|
||||||
|
|
||||||
def info(*args):
|
def info(*args):
|
||||||
"""Print an informational message to the console."""
|
"""Print an informational message to the console."""
|
||||||
msg = ' '.join(map(str, args))
|
msg = ' '.join(map(str, args))
|
||||||
print(f'\033[94m{msg}\033[0m')
|
print(wrap_color(msg, '94'))
|
||||||
|
|
||||||
|
|
||||||
def checkInvokeVersion():
|
def checkInvokeVersion():
|
||||||
@ -1284,6 +1289,7 @@ def version(c):
|
|||||||
"""Show the current version of InvenTree."""
|
"""Show the current version of InvenTree."""
|
||||||
import src.backend.InvenTree.InvenTree.version as InvenTreeVersion
|
import src.backend.InvenTree.InvenTree.version as InvenTreeVersion
|
||||||
from src.backend.InvenTree.InvenTree.config import (
|
from src.backend.InvenTree.InvenTree.config import (
|
||||||
|
get_backup_dir,
|
||||||
get_config_file,
|
get_config_file,
|
||||||
get_media_dir,
|
get_media_dir,
|
||||||
get_static_dir,
|
get_static_dir,
|
||||||
@ -1292,6 +1298,10 @@ def version(c):
|
|||||||
# Gather frontend version information
|
# Gather frontend version information
|
||||||
_, node, yarn = node_available(versions=True)
|
_, node, yarn = node_available(versions=True)
|
||||||
|
|
||||||
|
# Special output messages
|
||||||
|
NOT_SPECIFIED = wrap_color('NOT SPECIFIED', '91')
|
||||||
|
NA = wrap_color('N/A', '93')
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"""
|
f"""
|
||||||
InvenTree - inventree.org
|
InvenTree - inventree.org
|
||||||
@ -1304,16 +1314,17 @@ Environment {sys.prefix}
|
|||||||
Installation paths:
|
Installation paths:
|
||||||
Base {localDir()}
|
Base {localDir()}
|
||||||
Config {get_config_file()}
|
Config {get_config_file()}
|
||||||
Media {get_media_dir()}
|
Media {get_media_dir(error=False) or NOT_SPECIFIED}
|
||||||
Static {get_static_dir()}
|
Static {get_static_dir(error=False) or NOT_SPECIFIED}
|
||||||
|
Backup {get_backup_dir(error=False) or NOT_SPECIFIED}
|
||||||
|
|
||||||
Versions:
|
Versions:
|
||||||
Python {python_version()}
|
Python {python_version()}
|
||||||
Django {InvenTreeVersion.inventreeDjangoVersion()}
|
Django {InvenTreeVersion.inventreeDjangoVersion()}
|
||||||
InvenTree {InvenTreeVersion.inventreeVersion()}
|
InvenTree {InvenTreeVersion.inventreeVersion()}
|
||||||
API {InvenTreeVersion.inventreeApiVersion()}
|
API {InvenTreeVersion.inventreeApiVersion()}
|
||||||
Node {node if node else 'N/A'}
|
Node {node if node else NA}
|
||||||
Yarn {yarn if yarn else 'N/A'}
|
Yarn {yarn if yarn else NA}
|
||||||
|
|
||||||
Commit hash: {InvenTreeVersion.inventreeCommitHash()}
|
Commit hash: {InvenTreeVersion.inventreeCommitHash()}
|
||||||
Commit date: {InvenTreeVersion.inventreeCommitDate()}"""
|
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'):
|
if len(sys.argv) == 1 and sys.argv[0].startswith('/opt/inventree/env/lib/python'):
|
||||||
print(
|
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 '--list' for a list of available commands
|
||||||
Use '--help' for help on a specific command"""
|
Use '--help' for help on a specific command"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user