diff --git a/generate_bilan/__main__.py b/generate_bilan/__main__.py index ea72181..b57fb39 100644 --- a/generate_bilan/__main__.py +++ b/generate_bilan/__main__.py @@ -8,7 +8,7 @@ from path import Path # Defaults settings this_dir, this_filename = os.path.split(__file__) -default_template = Path(this_dir + "/tpl_bilan.tex") +default_template = "tpl_bilan.tex" parser = optparse.OptionParser() @@ -45,7 +45,7 @@ if not options.classe: if not options.ds_name: raise ValueError("Need to pass a evaluation name with -e. See -h for help") -build_bilan(options.classe, +generate_bilan(options.classe, options.ds_name, options.path, options.template) diff --git a/generate_bilan/generate_bilan.py b/generate_bilan/generate_bilan.py index c26379c..2b8af59 100755 --- a/generate_bilan/generate_bilan.py +++ b/generate_bilan/generate_bilan.py @@ -75,10 +75,9 @@ def build_target_name(classe, ds_name, path = Path("./")): >>> build_target_name("312", "DS1", Path("plop/")) Path('plop/312/bilan_DS1.tex') """ + return Path(path + classe + "/bilan_" + ds_name + ".tex") - return path + classe + "/bilan_" + ds_name + ".tex" - -def feed_bilan(target, datas, template = "./tpl_bilan.tex"): +def feed_bilan(target, datas, template = "tpl_bilan.tex"): """ Get the template and feed it to create bilans :param target: path where the bilan will be saved @@ -86,11 +85,16 @@ def feed_bilan(target, datas, template = "./tpl_bilan.tex"): :param template: the 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)) print("{} est construit! Ya plus qu'à compiler!".format(target)) -def generate_bilan(classe, ds_name, path = Path('./'), template = "./tpl_bilan.tex"): +def generate_bilan(classe, ds_name, path = Path('./'), template = "tpl_bilan.tex"): """ Generate the bilan of a evaluation for a class :param classe: the classe name @@ -113,7 +117,7 @@ def generate_bilan(classe, ds_name, path = Path('./'), template = "./tpl_bilan.t datas = {"ds_info": ds_info, "students":students_df} - target = build_target_name(classe, ds_name) + target = build_target_name(classe, ds_name, path) feed_bilan(target, datas, template) diff --git a/generate_bilan/tpl_bilan.tex b/generate_bilan/templates/tpl_bilan.tex similarity index 100% rename from generate_bilan/tpl_bilan.tex rename to generate_bilan/templates/tpl_bilan.tex diff --git a/generate_bilan/texenv.py b/generate_bilan/texenv.py index 4a35e68..536bec2 100644 --- a/generate_bilan/texenv.py +++ b/generate_bilan/texenv.py @@ -12,7 +12,7 @@ texenv = jinja2.Environment( block_end_string = '}', variable_start_string = '\Var{', variable_end_string = '}', - loader = jinja2.FileSystemLoader(os.path.abspath('.')), + loader = jinja2.PackageLoader("generate_bilan", "templates"), extensions = ['jinja2.ext.do'] ) @@ -41,9 +41,8 @@ texenv.filters['shuffle'] = shuffle if __name__ == '__main__': - from pymath.expression import Expression - exp = Expression("2/4 + 18") - print(do_calculus(exp.simplify())) + print(texenv.list_templates()) + texenv.get_template("tpl_bilan.tex")