f481cb6c8143cd7302222c70d62b07bbe3ee94a2
[it/dep.git] / smo-install / test / pythonsdk / src / oransdk / utils / jinja.py
1 # -*- coding: utf-8 -*-
2 # SPDX-License-Identifier: Apache-2.0
3 """Jinja module."""
4
5 from jinja2 import Environment, PackageLoader, select_autoescape, ChoiceLoader
6
7
8 def jinja_env() -> Environment:
9     """Create Jinja environment.
10
11     jinja_env allow to fetch simply jinja templates where they are.
12     by default jinja engine will look for templates in `templates` directory of
13     the package. So to load a template, you just have to do:
14
15     Example:
16     >>> template = jinja_env().get_template('vendor_create.json.j2')
17     >>> data = template.render(name="vendor")
18
19     See also:
20         SdcElement.create() for real use
21
22     Returns:
23         Environment: the Jinja environment to use
24
25     """
26     return Environment(autoescape=select_autoescape(['html', 'htm', 'xml']),
27                        loader=ChoiceLoader([
28                            PackageLoader("oransdk.a1sim"),
29                            PackageLoader("oransdk.dmaap"),
30                            PackageLoader("oransdk.enrichmentservice"),
31                            PackageLoader("oransdk.policy")
32                        ]))