diff options
author | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2018-03-01 23:47:31 +0100 |
---|---|---|
committer | Alexandru Avadanii <Alexandru.Avadanii@enea.com> | 2018-03-01 23:53:17 +0100 |
commit | 87325878949d5a315535720828af5185ebaa7a9f (patch) | |
tree | a7e663a8d94635034e80b0ac6aeb2538dd9f20f0 | |
parent | 47bd97b8cf09c26619e106874eab6c84b5060f67 (diff) |
generate_config: New `-i` arg for j2 includes dir
jinja2 does not support imports from parent directories, so in order
for j2 to be able to use '{% from <some>.j2 import ... %}' constructs
with included j2 residing on a separate dirpath than current j2, add
support for explicitly adding directories to the templater search
path.
This also allows calling generate_config with only file basename as
'-j' arg value, as long as the dirname is passed via '-i' (can be
extended later to parsing multiple j2 files at once).
Change-Id: I943fda9262a6f7de5ee6fcc3e7bc9828c339651a
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
-rwxr-xr-x | config/utils/generate_config.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/config/utils/generate_config.py b/config/utils/generate_config.py index 6adbb44e..1387ed12 100755 --- a/config/utils/generate_config.py +++ b/config/utils/generate_config.py @@ -21,10 +21,11 @@ from jinja2 import Environment, FileSystemLoader PARSER = argparse.ArgumentParser() PARSER.add_argument("--yaml", "-y", type=str, required=True) PARSER.add_argument("--jinja2", "-j", type=str, required=True) +PARSER.add_argument("--includesdir", "-i", type=str, action='append') ARGS = PARSER.parse_args() ENV = Environment( - loader=FileSystemLoader(os.path.dirname(ARGS.jinja2)), + loader=FileSystemLoader([os.path.dirname(ARGS.jinja2)] + ARGS.includesdir), extensions=['jinja2.ext.do'] ) gen_config_lib.load_custom_filters(ENV) |