summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Estabrook <jestabro@vyos.io>2024-05-06 11:26:41 -0500
committerGitHub <noreply@github.com>2024-05-06 11:26:41 -0500
commit05ee052d343a9f1d6d537f53595bc2a29bf36a84 (patch)
treed0378656a218e62240e4376c1b631ff9d19a2ea3
parenteef9874887fbe61006ab7bd861c3aa385fec7f71 (diff)
parent9aa8c3cd9bb4d11d247895576ab8f90f6a0e19b5 (diff)
downloadvyos-1x-05ee052d343a9f1d6d537f53595bc2a29bf36a84.tar.gz
vyos-1x-05ee052d343a9f1d6d537f53595bc2a29bf36a84.zip
Merge pull request #3415 from dmbaturin/T3664-no-env-var
vyos.template: T3664: use a module-level global variable for the default template directory
-rw-r--r--python/vyos/template.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py
index ac77e8a3d..fbc5f1456 100644
--- a/python/vyos/template.py
+++ b/python/vyos/template.py
@@ -25,6 +25,14 @@ from vyos.utils.file import makedir
from vyos.utils.permission import chmod
from vyos.utils.permission import chown
+# We use a mutable global variable for the default template directory
+# to make it possible to call scripts from this repository
+# outside of live VyOS systems.
+# If something (like the image build scripts)
+# want to call a script, they can modify the default location
+# to the repository path.
+DEFAULT_TEMPLATE_DIR = directories["templates"]
+
# Holds template filters registered via register_filter()
_FILTERS = {}
_TESTS = {}
@@ -35,18 +43,7 @@ def _get_environment(location=None):
from os import getenv
if location is None:
- # Sometimes functions that rely on templates need to be executed outside of VyOS installations:
- # for example, installer functions are executed for image builds,
- # and anything may be invoked for testing from a developer's machine.
- # This environment variable allows running any unmodified code
- # with a custom template location.
- location_env_var = getenv("VYOS_TEMPLATE_DIR")
- if location_env_var:
- print(f"Using environment variable {location_env_var}")
- template_dir = location_env_var
- else:
- template_dir = directories["templates"]
- loc_loader=FileSystemLoader(template_dir)
+ loc_loader=FileSystemLoader(DEFAULT_TEMPLATE_DIR)
else:
loc_loader=FileSystemLoader(location)
env = Environment(