Add ORAN Python SDK first draft
[it/dep.git] / smo-install / test / pythonsdk / src / oransdk / utils / jinja.py
diff --git a/smo-install/test/pythonsdk/src/oransdk/utils/jinja.py b/smo-install/test/pythonsdk/src/oransdk/utils/jinja.py
new file mode 100644 (file)
index 0000000..f481cb6
--- /dev/null
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+# SPDX-License-Identifier: Apache-2.0
+"""Jinja module."""
+
+from jinja2 import Environment, PackageLoader, select_autoescape, ChoiceLoader
+
+
+def jinja_env() -> Environment:
+    """Create Jinja environment.
+
+    jinja_env allow to fetch simply jinja templates where they are.
+    by default jinja engine will look for templates in `templates` directory of
+    the package. So to load a template, you just have to do:
+
+    Example:
+    >>> template = jinja_env().get_template('vendor_create.json.j2')
+    >>> data = template.render(name="vendor")
+
+    See also:
+        SdcElement.create() for real use
+
+    Returns:
+        Environment: the Jinja environment to use
+
+    """
+    return Environment(autoescape=select_autoescape(['html', 'htm', 'xml']),
+                       loader=ChoiceLoader([
+                           PackageLoader("oransdk.a1sim"),
+                           PackageLoader("oransdk.dmaap"),
+                           PackageLoader("oransdk.enrichmentservice"),
+                           PackageLoader("oransdk.policy")
+                       ]))