2016-11-08 08:07:03 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
import jinja2, os
|
2016-11-25 20:57:49 +00:00
|
|
|
from .filters import includegraphics
|
2016-11-08 08:07:03 +00:00
|
|
|
|
2016-11-26 14:40:35 +00:00
|
|
|
import logging
|
|
|
|
logger = logging.getLogger("generate_bilan")
|
|
|
|
|
2016-11-08 08:07:03 +00:00
|
|
|
__all__ = ["texenv"]
|
|
|
|
|
|
|
|
# Definition of jinja syntax for latex
|
|
|
|
texenv = jinja2.Environment(
|
|
|
|
block_start_string = '\Block{',
|
|
|
|
# Gros WTF!! Si on le met en maj ça ne marche pas alors que c'est en maj dans le template...
|
|
|
|
block_end_string = '}',
|
|
|
|
variable_start_string = '\Var{',
|
|
|
|
variable_end_string = '}',
|
2016-11-18 15:07:38 +00:00
|
|
|
comment_start_string = '\#{',
|
|
|
|
comment_end_string = '}',
|
|
|
|
line_statement_prefix = '%-',
|
|
|
|
line_comment_prefix = '%#',
|
2016-11-22 11:39:02 +00:00
|
|
|
loader = jinja2.ChoiceLoader([jinja2.PackageLoader("notes_tools.generate_bilan", "templates"),
|
|
|
|
jinja2.FileSystemLoader(['./']),
|
|
|
|
]),
|
2016-11-08 08:07:03 +00:00
|
|
|
extensions = ['jinja2.ext.do']
|
|
|
|
)
|
|
|
|
|
|
|
|
# Filters
|
|
|
|
|
2016-11-26 13:53:06 +00:00
|
|
|
from .filters import includegraphics
|
2016-11-25 20:57:49 +00:00
|
|
|
texenv.filters['includegraphics'] = includegraphics
|
2016-11-08 08:07:03 +00:00
|
|
|
|
2016-11-26 13:53:06 +00:00
|
|
|
from notes_tools.tools.marks_plottings import comp_radar, marks_hist
|
|
|
|
texenv.filters['comp_radar'] = comp_radar
|
|
|
|
texenv.filters['marks_hist'] = marks_hist
|
2016-11-08 08:07:03 +00:00
|
|
|
|
2016-11-26 14:40:35 +00:00
|
|
|
def feed_template(target, datas, template):
|
|
|
|
""" Get the template and feed it to create bilans
|
|
|
|
|
|
|
|
:param target: path where the bilan will be saved
|
|
|
|
:param datas: dictonnary to feed the template
|
|
|
|
:param template: the template
|
|
|
|
"""
|
|
|
|
logger.info("Getting template {}".format(template))
|
|
|
|
bilan = 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(bilan.render(**datas, directory=path_to_target))
|
|
|
|
logger.info("{} est construit! Ya plus qu'à compiler!".format(target))
|
2016-11-08 08:07:03 +00:00
|
|
|
if __name__ == '__main__':
|
2016-11-13 13:40:22 +00:00
|
|
|
print(texenv.list_templates())
|
|
|
|
texenv.get_template("tpl_bilan.tex")
|
2016-11-08 08:07:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
# Reglages pour 'vim'
|
|
|
|
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
|
|
|
|
# cursor: 16 del
|