mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
0bace3f3af
* moved docker files to /contrib/container * changed code owners to make more precise * updated CI to use new subdirs * added manual trigger for testing * moved ci files * moved assets into subdir * moved deploy template file to contrib * moved django files to src/backend * updated paths in scripts etc * updated reqs path * fixed version file path * fixed flake8 path * fixed path to node ressources * fixed task paths * added dep path for node * removed unused yarn lockfile * removed unused ci script * updated internal backend paths for tasks * updated translation stats path * fixed source path for coverage * fixed main commit repo path * fit in changes from testing * gather packager improvements (#149) * Matmair/issue5578 (#143) * moved docker files to /contrib/container * changed code owners to make more precise * updated CI to use new subdirs * added manual trigger for testing * moved ci files * moved assets into subdir * moved deploy template file to contrib * moved django files to src/backend * updated paths in scripts etc * updated reqs path * fixed version file path * fixed flake8 path * fixed path to node ressources * fixed task paths * added dep path for node * removed unused yarn lockfile * removed unused ci script * updated internal backend paths for tasks * updated translation stats path * fixed source path for coverage * fixed main commit repo path * fix docker path * use project dir * move project dir command * fixed docker paths * another fix? * seperate tasks out * remove tasks * some debugging * ci: add .deepsource.toml * Update .deepsource.toml * also ignore migrations * more debugging * fix path issues * remove debug script * fix style * change locale path * Fixed paths for requirements * Added dummy requirements to fool packager * fixed exec path * remove deepsource --------- Co-authored-by: deepsource-io[bot] <42547082+deepsource-io[bot]@users.noreply.github.com> * Added docs for file structure * Fixed style errors * updated deepsource paths * fix deepsource paths * fixed reqs * merge fixes * move newly added dirs too * fix reqs files * another dep fix * merge upstream/master * revert removal of tags * merge upstream * enabled detection of old config files * adapt coverage src * also detect and support old location for plugins.txt * style fix * fix ~/init.sh location * fix requirements path * fix config to current master * move new folders * fix import order * fix paths for qc_check * fix docs build * fix fix path * set docker project dir * just use a cd * set image path? * set file correct * fix copy path * fix tasks dir * fix init path * fix copy path * set prject dir * fix paths * remove old prod files * fix dev env path * set docker file * Fix devcontainer docker compose file * fix login attempt values * fix init.sh path * Fix pathing for Docker * Docker build fix - Set INVENTREE_BACKEND_DIR separately * Update init.sh * Fix path * Update requirements.txt * merge * fix rq merge * fix docker compose usage --------- Co-authored-by: deepsource-io[bot] <42547082+deepsource-io[bot]@users.noreply.github.com> Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
104 lines
2.6 KiB
Python
104 lines
2.6 KiB
Python
"""Test that the "translated" javascript files to not contain template tags which need to be determined at "run time".
|
|
|
|
This is because the "translated" javascript files are compiled into the "static" directory.
|
|
They should only contain template tags that render static information.
|
|
"""
|
|
|
|
import os
|
|
import pathlib
|
|
import re
|
|
import sys
|
|
|
|
here = os.path.abspath(os.path.dirname(__file__))
|
|
template_dir = os.path.abspath(os.path.join(here, '..', 'InvenTree', 'templates'))
|
|
|
|
# We only care about the 'translated' files
|
|
js_i18n_dir = os.path.join(template_dir, 'js', 'translated')
|
|
js_dynamic_dir = os.path.join(template_dir, 'js', 'dynamic')
|
|
|
|
errors = 0
|
|
|
|
print('=================================')
|
|
print('Checking static javascript files:')
|
|
print('=================================')
|
|
|
|
|
|
def check_invalid_tag(data):
|
|
"""Check for invalid tags."""
|
|
pattern = r'{%(\w+)'
|
|
|
|
err_count = 0
|
|
|
|
for idx, line in enumerate(data):
|
|
results = re.findall(pattern, line)
|
|
|
|
for result in results:
|
|
err_count += 1
|
|
|
|
print(f' - Error on line {idx + 1}: %{{{result[0]}')
|
|
|
|
return err_count
|
|
|
|
|
|
def check_prohibited_tags(data):
|
|
"""Check for prohibited tags."""
|
|
allowed_tags = [
|
|
'if',
|
|
'elif',
|
|
'else',
|
|
'endif',
|
|
'for',
|
|
'endfor',
|
|
'trans',
|
|
'load',
|
|
'include',
|
|
'url',
|
|
]
|
|
|
|
pattern = r'{% (\w+)\s'
|
|
|
|
err_count = 0
|
|
|
|
for idx, line in enumerate(data):
|
|
for tag in re.findall(pattern, line):
|
|
if tag not in allowed_tags:
|
|
print(f" > Line {idx + 1} contains prohibited template tag '{tag}'")
|
|
err_count += 1
|
|
|
|
return err_count
|
|
|
|
|
|
for filename in pathlib.Path(js_i18n_dir).rglob('*.js'):
|
|
print(f"Checking file 'translated/{os.path.basename(filename)}':")
|
|
|
|
with open(filename, 'r') as js_file:
|
|
data = js_file.readlines()
|
|
|
|
errors += check_invalid_tag(data)
|
|
errors += check_prohibited_tags(data)
|
|
|
|
for filename in pathlib.Path(js_dynamic_dir).rglob('*.js'):
|
|
print(f"Checking file 'dynamic/{os.path.basename(filename)}':")
|
|
|
|
# Check that the 'dynamic' files do not contains any translated strings
|
|
with open(filename, 'r') as js_file:
|
|
data = js_file.readlines()
|
|
|
|
invalid_tags = ['blocktrans', 'blocktranslate', 'trans', 'translate']
|
|
|
|
err_count = 0
|
|
|
|
for idx, line in enumerate(data):
|
|
for tag in invalid_tags:
|
|
tag = '{% ' + tag
|
|
if tag in line:
|
|
err_count += 1
|
|
|
|
print(f" > Error on line {idx + 1}: Prohibited tag '{tag}' found")
|
|
|
|
|
|
if errors > 0:
|
|
print(f'Found {errors} incorrect template tags')
|
|
|
|
sys.exit(errors)
|