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>
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)