From 39969777d83ddb62512261af1f908cbd784249a3 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sat, 26 Nov 2016 17:40:35 +0300 Subject: [PATCH] move feed_template to texenv --- notes_tools/generate_bilan/eval_bilan.py | 22 ++-------------------- notes_tools/generate_bilan/texenv.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/notes_tools/generate_bilan/eval_bilan.py b/notes_tools/generate_bilan/eval_bilan.py index 5cfdfd2..20373da 100755 --- a/notes_tools/generate_bilan/eval_bilan.py +++ b/notes_tools/generate_bilan/eval_bilan.py @@ -2,7 +2,7 @@ # encoding: utf-8 from notes_tools.tools import extract_flat_marks, get_class_ws, digest_flat_df, students_pov, select_eval -from .texenv import texenv +from .texenv import feed_template import pandas as pd import numpy as np import xlrd @@ -63,27 +63,9 @@ def eval_bilan(classe, evalname, path = Path('./'), template = "tpl_bilan_eval.t "quest_df":quest_df, "exo_df":exo_df, "eval_df":eval_df} target = build_target_name(classe, evalname, path) - feed_bilan(target, datas, template) + feed_template(target, datas, template) -def feed_bilan(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)) - # ----------------------------- # Reglages pour 'vim' # vim:set autoindent expandtab tabstop=4 shiftwidth=4: diff --git a/notes_tools/generate_bilan/texenv.py b/notes_tools/generate_bilan/texenv.py index 3cfe4ce..0a2459c 100644 --- a/notes_tools/generate_bilan/texenv.py +++ b/notes_tools/generate_bilan/texenv.py @@ -4,6 +4,9 @@ import jinja2, os from .filters import includegraphics +import logging +logger = logging.getLogger("generate_bilan") + __all__ = ["texenv"] # Definition of jinja syntax for latex @@ -32,6 +35,23 @@ from notes_tools.tools.marks_plottings import comp_radar, marks_hist texenv.filters['comp_radar'] = comp_radar texenv.filters['marks_hist'] = marks_hist +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)) if __name__ == '__main__': print(texenv.list_templates()) texenv.get_template("tpl_bilan.tex")