File jinja2_fix.patch of Package cobbler.15445

From: Jens-U. Mozdzen <jmozdzen@nde.ag>
Subject: Jinja2 fix
References: bsc#1141661
Patch-Mainline: 
Git-commit: dd2e9fa471fb83aa78878f93dfd862f83bcd906a
Git-repo: https://github.com/thiller2018/cobbler.git.git

Jinja2 supports including files, i. e. for macro libraries or as content to be included in the template. This feature is only available if the Jinja2 environment is created with an according specification of the root directory from which to include such files. This patch adds an optional Cobbler configuration variable (included in config/settings, but commented out so not to alter the default behaviour of Cobbler) to specify such a directory, and the code to create the Jinja2 environment accordingly, if that configuration value is set.

Signed-off-by: Thomas Renninger <trenn@suse.com>

Index: cobbler-2.6.6/cobbler/templar.py
===================================================================
--- cobbler-2.6.6.orig/cobbler/templar.py	2019-07-17 14:34:00.291187426 +0200
+++ cobbler-2.6.6/cobbler/templar.py	2019-07-17 14:34:04.851187672 +0200
@@ -228,7 +228,10 @@ class Templar:
         """
 
         try:
-            template = jinja2.Template(raw_data)
+            if self.settings and self.settings.jinja2_includedir:
+                template = jinja2.Environment(loader=jinja2.FileSystemLoader(self.settings.jinja2_includedir)).from_string(raw_data)
+            else:
+                template = jinja2.Template(raw_data)
             data_out = template.render(search_table)
         except:
             data_out = "# EXCEPTION OCCURRED DURING JINJA2 TEMPLATE PROCESSING\n"
openSUSE Build Service is sponsored by