mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 03:26:45 +00:00
Tasks cleanup (#8838)
* Pretty print and typo fix * Improved output * Improve logging
This commit is contained in:
parent
0614f01247
commit
40cff05864
@ -219,11 +219,9 @@ if DEBUG and 'collectstatic' not in sys.argv:
|
|||||||
|
|
||||||
# Append directory for sample plugin static content (if in debug mode)
|
# Append directory for sample plugin static content (if in debug mode)
|
||||||
if PLUGINS_ENABLED:
|
if PLUGINS_ENABLED:
|
||||||
print('Adding plugin sample static content')
|
logger.info('Adding plugin sample static content')
|
||||||
STATICFILES_DIRS.append(BASE_DIR.joinpath('plugin', 'samples', 'static'))
|
STATICFILES_DIRS.append(BASE_DIR.joinpath('plugin', 'samples', 'static'))
|
||||||
|
|
||||||
print('-', STATICFILES_DIRS[-1])
|
|
||||||
|
|
||||||
# Database backup options
|
# Database backup options
|
||||||
# Ref: https://django-dbbackup.readthedocs.io/en/master/configuration.html
|
# Ref: https://django-dbbackup.readthedocs.io/en/master/configuration.html
|
||||||
DBBACKUP_SEND_EMAIL = False
|
DBBACKUP_SEND_EMAIL = False
|
||||||
@ -1037,7 +1035,9 @@ if SITE_URL:
|
|||||||
validator = URLValidator()
|
validator = URLValidator()
|
||||||
validator(SITE_URL)
|
validator(SITE_URL)
|
||||||
except Exception:
|
except Exception:
|
||||||
print(f"Invalid SITE_URL value: '{SITE_URL}'. InvenTree server cannot start.")
|
msg = f"Invalid SITE_URL value: '{SITE_URL}'. InvenTree server cannot start."
|
||||||
|
logger.error(msg)
|
||||||
|
print(msg)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
42
tasks.py
42
tasks.py
@ -80,8 +80,8 @@ def checkPythonVersion():
|
|||||||
valid = False
|
valid = False
|
||||||
|
|
||||||
if not valid:
|
if not valid:
|
||||||
print(f'The installed python version ({version}) is not supported!')
|
error(f'The installed python version ({version}) is not supported!')
|
||||||
print(f'InvenTree requires Python {REQ_MAJOR}.{REQ_MINOR} or above')
|
error(f'InvenTree requires Python {REQ_MAJOR}.{REQ_MINOR} or above')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ def node_available(versions: bool = False, bypass_yarn: bool = False):
|
|||||||
|
|
||||||
# Print a warning if node is available but yarn is not
|
# Print a warning if node is available but yarn is not
|
||||||
if node_version and not yarn_passes:
|
if node_version and not yarn_passes:
|
||||||
print(
|
warning(
|
||||||
'Node is available but yarn is not. Install yarn if you wish to build the frontend.'
|
'Node is available but yarn is not. Install yarn if you wish to build the frontend.'
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ def node_available(versions: bool = False, bypass_yarn: bool = False):
|
|||||||
return ret(yarn_passes and node_version, node_version, yarn_version)
|
return ret(yarn_passes and node_version, node_version, yarn_version)
|
||||||
|
|
||||||
|
|
||||||
def check_file_existance(filename: Path, overwrite: bool = False):
|
def check_file_existence(filename: Path, overwrite: bool = False):
|
||||||
"""Checks if a file exists and asks the user if it should be overwritten.
|
"""Checks if a file exists and asks the user if it should be overwritten.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -276,7 +276,7 @@ def check_file_existance(filename: Path, overwrite: bool = False):
|
|||||||
response = str(response).strip().lower()
|
response = str(response).strip().lower()
|
||||||
|
|
||||||
if response not in ['y', 'yes']:
|
if response not in ['y', 'yes']:
|
||||||
print('Cancelled export operation')
|
error('Cancelled export operation')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@ -522,7 +522,7 @@ def restore(
|
|||||||
base_cmd += f' -I {path}'
|
base_cmd += f' -I {path}'
|
||||||
|
|
||||||
if ignore_database:
|
if ignore_database:
|
||||||
print('Skipping database archive...')
|
info('Skipping database archive...')
|
||||||
else:
|
else:
|
||||||
info('Restoring InvenTree database')
|
info('Restoring InvenTree database')
|
||||||
cmd = f'dbrestore {base_cmd}'
|
cmd = f'dbrestore {base_cmd}'
|
||||||
@ -533,7 +533,7 @@ def restore(
|
|||||||
manage(c, cmd)
|
manage(c, cmd)
|
||||||
|
|
||||||
if ignore_media:
|
if ignore_media:
|
||||||
print('Skipping media restore...')
|
info('Skipping media restore...')
|
||||||
else:
|
else:
|
||||||
info('Restoring InvenTree media files')
|
info('Restoring InvenTree media files')
|
||||||
cmd = f'mediarestore {base_cmd}'
|
cmd = f'mediarestore {base_cmd}'
|
||||||
@ -615,7 +615,11 @@ def update(
|
|||||||
# - INVENTREE_DOCKER is set (by the docker image eg.) and not overridden by `--frontend` flag
|
# - INVENTREE_DOCKER is set (by the docker image eg.) and not overridden by `--frontend` flag
|
||||||
# - `--no-frontend` flag is set
|
# - `--no-frontend` flag is set
|
||||||
if (os.environ.get('INVENTREE_DOCKER', False) and not frontend) or no_frontend:
|
if (os.environ.get('INVENTREE_DOCKER', False) and not frontend) or no_frontend:
|
||||||
print('Skipping frontend update!')
|
if no_frontend:
|
||||||
|
info('Skipping frontend update (no_frontend flag set)')
|
||||||
|
else:
|
||||||
|
info('Skipping frontend update (INVENTREE_DOCKER flag set)')
|
||||||
|
|
||||||
frontend = False
|
frontend = False
|
||||||
no_frontend = True
|
no_frontend = True
|
||||||
else:
|
else:
|
||||||
@ -678,7 +682,7 @@ def export_records(
|
|||||||
|
|
||||||
info(f"Exporting database records to file '{target}'")
|
info(f"Exporting database records to file '{target}'")
|
||||||
|
|
||||||
check_file_existance(target, overwrite)
|
check_file_existence(target, overwrite)
|
||||||
|
|
||||||
tmpfile = f'{target}.tmp'
|
tmpfile = f'{target}.tmp'
|
||||||
|
|
||||||
@ -723,7 +727,7 @@ def export_records(
|
|||||||
f_out.write(json.dumps(data_out, indent=2))
|
f_out.write(json.dumps(data_out, indent=2))
|
||||||
|
|
||||||
if not retain_temp:
|
if not retain_temp:
|
||||||
print('Removing temporary files')
|
info('Removing temporary files')
|
||||||
os.remove(tmpfile)
|
os.remove(tmpfile)
|
||||||
|
|
||||||
success('Data export completed')
|
success('Data export completed')
|
||||||
@ -1122,7 +1126,7 @@ def schema(
|
|||||||
):
|
):
|
||||||
"""Export current API schema."""
|
"""Export current API schema."""
|
||||||
filename = Path(filename).resolve()
|
filename = Path(filename).resolve()
|
||||||
check_file_existance(filename, overwrite)
|
check_file_existence(filename, overwrite)
|
||||||
|
|
||||||
info(f"Exporting schema file to '{filename}'")
|
info(f"Exporting schema file to '{filename}'")
|
||||||
|
|
||||||
@ -1154,7 +1158,7 @@ def schema(
|
|||||||
def export_settings_definitions(c, filename='inventree_settings.json', overwrite=False):
|
def export_settings_definitions(c, filename='inventree_settings.json', overwrite=False):
|
||||||
"""Export settings definition to a JSON file."""
|
"""Export settings definition to a JSON file."""
|
||||||
filename = Path(filename).resolve()
|
filename = Path(filename).resolve()
|
||||||
check_file_existance(filename, overwrite)
|
check_file_existence(filename, overwrite)
|
||||||
|
|
||||||
info(f"Exporting settings definition to '{filename}'...")
|
info(f"Exporting settings definition to '{filename}'...")
|
||||||
manage(c, f'export_settings_definitions {filename}', pty=True)
|
manage(c, f'export_settings_definitions {filename}', pty=True)
|
||||||
@ -1382,10 +1386,10 @@ def frontend_download(
|
|||||||
current_content = current.read_text().strip()
|
current_content = current.read_text().strip()
|
||||||
ref_value = tag or sha
|
ref_value = tag or sha
|
||||||
if current_content == ref_value:
|
if current_content == ref_value:
|
||||||
print(f'Frontend {ref} is already `{ref_value}`')
|
info(f'Frontend {ref} is already `{ref_value}`')
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print(
|
info(
|
||||||
f'Frontend {ref} is not expected `{ref_value}` but `{current_content}` - new version will be downloaded'
|
f'Frontend {ref} is not expected `{ref_value}` but `{current_content}` - new version will be downloaded'
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
@ -1418,7 +1422,7 @@ def frontend_download(
|
|||||||
and content['INVENTREE_PKG_INSTALLER'] == 'PKG'
|
and content['INVENTREE_PKG_INSTALLER'] == 'PKG'
|
||||||
):
|
):
|
||||||
ref = content.get('INVENTREE_COMMIT_SHA')
|
ref = content.get('INVENTREE_COMMIT_SHA')
|
||||||
print(
|
info(
|
||||||
f'[INFO] Running in package environment, got commit "{ref}" from VERSION file'
|
f'[INFO] Running in package environment, got commit "{ref}" from VERSION file'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -1459,7 +1463,8 @@ Then try continuing by running: invoke frontend-download --file <path-to-downloa
|
|||||||
if not (qc_run := find_resource(workflow_runs['workflow_runs'], 'name', 'QC')):
|
if not (qc_run := find_resource(workflow_runs['workflow_runs'], 'name', 'QC')):
|
||||||
error(f'ERROR: Cannot find any workflow runs for current SHA {ref}')
|
error(f'ERROR: Cannot find any workflow runs for current SHA {ref}')
|
||||||
return
|
return
|
||||||
print(
|
|
||||||
|
info(
|
||||||
f'Found workflow {qc_run["name"]} (run {qc_run["run_number"]}-{qc_run["run_attempt"]})'
|
f'Found workflow {qc_run["name"]} (run {qc_run["run_number"]}-{qc_run["run_attempt"]})'
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1472,9 +1477,10 @@ Then try continuing by running: invoke frontend-download --file <path-to-downloa
|
|||||||
artifacts['artifacts'], 'name', 'frontend-build'
|
artifacts['artifacts'], 'name', 'frontend-build'
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
print('[ERROR] Cannot find frontend-build.zip attachment for current sha')
|
error('[ERROR] Cannot find frontend-build.zip attachment for current sha')
|
||||||
return
|
return
|
||||||
print(
|
|
||||||
|
info(
|
||||||
f'Found artifact {frontend_artifact["name"]} with id {frontend_artifact["id"]} ({frontend_artifact["size_in_bytes"] / 1e6:.2f}MB).'
|
f'Found artifact {frontend_artifact["name"]} with id {frontend_artifact["id"]} ({frontend_artifact["size_in_bytes"] / 1e6:.2f}MB).'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user