Skip to content

Commit

Permalink
Tasks cleanup (#8838)
Browse files Browse the repository at this point in the history
* Pretty print and typo fix

* Improved output

* Improve logging
  • Loading branch information
SchrodingersGat authored Jan 5, 2025
1 parent 0614f01 commit 40cff05
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/backend/InvenTree/InvenTree/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,9 @@

# Append directory for sample plugin static content (if in debug mode)
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'))

print('-', STATICFILES_DIRS[-1])

# Database backup options
# Ref: https://django-dbbackup.readthedocs.io/en/master/configuration.html
DBBACKUP_SEND_EMAIL = False
Expand Down Expand Up @@ -1037,7 +1035,9 @@
validator = URLValidator()
validator(SITE_URL)
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)

else:
Expand Down
42 changes: 24 additions & 18 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def checkPythonVersion():
valid = False

if not valid:
print(f'The installed python version ({version}) is not supported!')
print(f'InvenTree requires Python {REQ_MAJOR}.{REQ_MINOR} or above')
error(f'The installed python version ({version}) is not supported!')
error(f'InvenTree requires Python {REQ_MAJOR}.{REQ_MINOR} or above')
sys.exit(1)


Expand Down Expand Up @@ -254,15 +254,15 @@ def check(cmd):

# Print a warning if node is available but yarn is not
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.'
)

# Return the result
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.
Args:
Expand All @@ -276,7 +276,7 @@ def check_file_existance(filename: Path, overwrite: bool = False):
response = str(response).strip().lower()

if response not in ['y', 'yes']:
print('Cancelled export operation')
error('Cancelled export operation')
sys.exit(1)


Expand Down Expand Up @@ -522,7 +522,7 @@ def restore(
base_cmd += f' -I {path}'

if ignore_database:
print('Skipping database archive...')
info('Skipping database archive...')
else:
info('Restoring InvenTree database')
cmd = f'dbrestore {base_cmd}'
Expand All @@ -533,7 +533,7 @@ def restore(
manage(c, cmd)

if ignore_media:
print('Skipping media restore...')
info('Skipping media restore...')
else:
info('Restoring InvenTree media files')
cmd = f'mediarestore {base_cmd}'
Expand Down Expand Up @@ -615,7 +615,11 @@ def update(
# - INVENTREE_DOCKER is set (by the docker image eg.) and not overridden by `--frontend` flag
# - `--no-frontend` flag is set
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
no_frontend = True
else:
Expand Down Expand Up @@ -678,7 +682,7 @@ def export_records(

info(f"Exporting database records to file '{target}'")

check_file_existance(target, overwrite)
check_file_existence(target, overwrite)

tmpfile = f'{target}.tmp'

Expand Down Expand Up @@ -723,7 +727,7 @@ def export_records(
f_out.write(json.dumps(data_out, indent=2))

if not retain_temp:
print('Removing temporary files')
info('Removing temporary files')
os.remove(tmpfile)

success('Data export completed')
Expand Down Expand Up @@ -1122,7 +1126,7 @@ def schema(
):
"""Export current API schema."""
filename = Path(filename).resolve()
check_file_existance(filename, overwrite)
check_file_existence(filename, overwrite)

info(f"Exporting schema file to '{filename}'")

Expand Down Expand Up @@ -1154,7 +1158,7 @@ def schema(
def export_settings_definitions(c, filename='inventree_settings.json', overwrite=False):
"""Export settings definition to a JSON file."""
filename = Path(filename).resolve()
check_file_existance(filename, overwrite)
check_file_existence(filename, overwrite)

info(f"Exporting settings definition to '{filename}'...")
manage(c, f'export_settings_definitions {filename}', pty=True)
Expand Down Expand Up @@ -1382,10 +1386,10 @@ def check_already_current(tag=None, sha=None):
current_content = current.read_text().strip()
ref_value = tag or sha
if current_content == ref_value:
print(f'Frontend {ref} is already `{ref_value}`')
info(f'Frontend {ref} is already `{ref_value}`')
return True
else:
print(
info(
f'Frontend {ref} is not expected `{ref_value}` but `{current_content}` - new version will be downloaded'
)
return False
Expand Down Expand Up @@ -1418,7 +1422,7 @@ def check_already_current(tag=None, sha=None):
and content['INVENTREE_PKG_INSTALLER'] == 'PKG'
):
ref = content.get('INVENTREE_COMMIT_SHA')
print(
info(
f'[INFO] Running in package environment, got commit "{ref}" from VERSION file'
)
else:
Expand Down Expand Up @@ -1459,7 +1463,8 @@ def check_already_current(tag=None, sha=None):
if not (qc_run := find_resource(workflow_runs['workflow_runs'], 'name', 'QC')):
error(f'ERROR: Cannot find any workflow runs for current SHA {ref}')
return
print(

info(
f'Found workflow {qc_run["name"]} (run {qc_run["run_number"]}-{qc_run["run_attempt"]})'
)

Expand All @@ -1472,9 +1477,10 @@ def check_already_current(tag=None, sha=None):
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
print(

info(
f'Found artifact {frontend_artifact["name"]} with id {frontend_artifact["id"]} ({frontend_artifact["size_in_bytes"] / 1e6:.2f}MB).'
)

Expand Down

0 comments on commit 40cff05

Please sign in to comment.