Skip to content

Commit

Permalink
ADCM-2684 Add 'include_raw' for parsing template (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
a-alferov committed Apr 11, 2022
1 parent d1ec31e commit eb9a391
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/adcm_client/packer/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import string
from itertools import chain

import jinja2
import yaml
from docker import from_env
from docker.client import DockerClient
from docker.errors import ImageNotFound
from docker.models.containers import Container # pylint: disable=unused-import
from docker.models.images import Image
from jinja2.environment import Environment
from jinja2.loaders import FileSystemLoader
from jinja2.runtime import StrictUndefined
from markupsafe import Markup


class NoModulesToInstall(Exception):
Expand Down Expand Up @@ -195,9 +198,15 @@ def python_mod_req(source_path, workspace, **kwargs):


def splitter(*args, **kwargs):
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(args[0]), undefined=jinja2.StrictUndefined
)
loader = FileSystemLoader(args[0])
env = Environment(loader=loader, undefined=StrictUndefined)

def include_raw(name):
"""Format: {{ include_raw('<template_name>') }}"""
return Markup(loader.get_source(env, name)[0])

env.globals['include_raw'] = include_raw

for file in kwargs['files']:
tmpl = env.get_template(file)
with codecs.open(os.path.join(args[0], (os.path.splitext(file)[0])), 'w', 'utf-8') as f:
Expand Down

0 comments on commit eb9a391

Please sign in to comment.