# Path: turbulenz_tools/tools/toolsexception.py
# class ToolsException(Exception):
#     pass


from jinja2 import Environment, FileSystemLoader, ChoiceLoader
from jinja2 import TemplateNotFound, TemplateSyntaxError, BaseLoader
from logging import getLogger
from turbulenz_tools.tools.toolsexception import ToolsException
import os
import re
    for t in options.templatedirs:
        LOG.info(" - '%s'", t)

    loaders = [ UTF8FileSystemLoader(t) for t in options.templatedirs ]
    if default_template is not None:
        loaders.append(DefaultTemplateLoader('default', default_template))

    _loader = ChoiceLoader(loaders)
    env = Environment(loader = _loader,
                      block_start_string = '/*{%',
                      block_end_string = '%}*/',
                      variable_start_string = '/*{{',
                      variable_end_string = '}}*/',
                      comment_start_string = '/*{#',
                      comment_end_string = '#}*/')
    return env

############################################################

def env_load_template(env, in_file):
    """
    Load a single template into the environment, handling the
    appropriate errors.  Returns the loaded template
    """

    try:
        return env.get_template(in_file)
    except TemplateNotFound as e:
        raise ToolsException('template not found: %s' % str(e))
    except TemplateSyntaxError as e:

# Path: turbulenz_tools/tools/toolsexception.py
# class ToolsException(Exception):
#     pass


# Path: turbulenz_tools/tools/templates.py
from jinja2 import Environment, FileSystemLoader, ChoiceLoader
from jinja2 import TemplateNotFound, TemplateSyntaxError, BaseLoader
from logging import getLogger
from turbulenz_tools.tools.toolsexception import ToolsException
import os
import re

    for t in options.templatedirs:
        LOG.info(" - '%s'", t)

    loaders = [ UTF8FileSystemLoader(t) for t in options.templatedirs ]
    if default_template is not None:
        loaders.append(DefaultTemplateLoader('default', default_template))

    _loader = ChoiceLoader(loaders)
    env = Environment(loader = _loader,
                      block_start_string = '/*{%',
                      block_end_string = '%}*/',
                      variable_start_string = '/*{{',
                      variable_end_string = '}}*/',
                      comment_start_string = '/*{#',
                      comment_end_string = '#}*/')
    return env

############################################################

def env_load_template(env, in_file):
    """
    Load a single template into the environment, handling the
    appropriate errors.  Returns the loaded template
    """

    try:
        return env.get_template(in_file)
    except TemplateNotFound as e:
        raise ToolsException('template not found: %s' % str(e))
    except TemplateSyntaxError as e:

        raise ToolsException('template syntax error: %s' % str(e))