50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
#!/usr/bin/env python
|
|
# encoding: utf-8
|
|
|
|
import logging
|
|
import jinja2
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
__all__ = ["texenv"]
|
|
|
|
# Definition of jinja syntax for latex
|
|
texenv = jinja2.Environment(
|
|
block_start_string='\Block{',
|
|
block_end_string='}',
|
|
variable_start_string='\Var{',
|
|
variable_end_string='}',
|
|
comment_start_string='\#{',
|
|
comment_end_string='}',
|
|
line_statement_prefix='%-',
|
|
line_comment_prefix='%#',
|
|
loader=jinja2.ChoiceLoader([
|
|
# jinja2.PackageLoader("notes_tools.reports", "templates"),
|
|
jinja2.FileSystemLoader(['./']),
|
|
]),
|
|
extensions=['jinja2.ext.do']
|
|
)
|
|
|
|
def feed_template(target, datas, template):
|
|
""" Get the template and feed it to create reports
|
|
|
|
:param target: path where the report will be saved
|
|
:param datas: dictonnary to feed the template
|
|
:param template: the template
|
|
"""
|
|
logger.info("Getting template {}".format(template))
|
|
report = texenv.get_template(template)
|
|
|
|
path_to_target = target.dirname()
|
|
if not path_to_target.exists():
|
|
path_to_target.mkdir()
|
|
|
|
with open(target, "w") as f:
|
|
f.write(report.render(**datas, directory=path_to_target))
|
|
logger.info("{} est construit! Ya plus qu'à compiler!".format(target))
|
|
|
|
# -----------------------------
|
|
# Reglages pour 'vim'
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
# cursor: 16 del
|