From 7eb2151d87db8d2b1d384a734918dfc923e3210c Mon Sep 17 00:00:00 2001 From: Lafrite Date: Wed, 3 Sep 2014 19:30:09 +0200 Subject: [PATCH] Manage csv file now --- DS_gene.py | 19 ++++++++++++++----- example/csv_example.csv | 25 +++++++++++++++++++++++++ example/tpl_example.tex | 2 +- 3 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 example/csv_example.csv diff --git a/DS_gene.py b/DS_gene.py index a9f549c..c0a9371 100755 --- a/DS_gene.py +++ b/DS_gene.py @@ -4,6 +4,7 @@ import os import sys import optparse +import csv from path import path from texenv import texenv @@ -24,17 +25,23 @@ def main(options): # Template should be named tpl_... tpl will replace by the number/name of the version output = path(template_file.dirname()) / path(template_file.name[3:]) + if not options.csv_file: + list_infos = [{num: i+1} for i in range(options.num_subj)] + else: + with open(options.csv_file, 'r', encoding = 'ISO-8859-1') as f: + list_infos = list(csv.DictReader(f, delimiter=";")) + for (i,a) in enumerate(list_infos): + a['num'] = i+1 + if output.dirname() != "": output.dirname().cd() output = output.name - - for subj in range(options.num_subj): - subj = subj+1 - dest = path(str(subj) + output) + for infos in list_infos: + dest = path(str(infos['num']) + output) with open( dest, 'w') as f: - f.write(template.render( RdExpression = RdExpression , infos = {"subj" : subj})) + f.write(template.render( RdExpression = RdExpression , infos = infos)) if not options.no_compil: os.system("pdflatex " + dest) @@ -50,10 +57,12 @@ if __name__ == '__main__': parser = optparse.OptionParser() parser.add_option("-t","--template",action="store",type="string",dest="template", help="File with the template. The name should have the following form tpl_... .") parser.add_option("-o","--output",action="store",type="string",dest="output",help="Base name for output )") + parser.add_option("-c","--csv", action="store", type="string", dest="csv_file", help="Filename of the csv file where informations are stored") parser.add_option("-N","--number_subjects", action="store",type="int", dest="num_subj", default = 1, help="The number of subjects to make") parser.add_option("-d","--dirty", action="store_true", dest="dirty", help="Do not clean after compilation") parser.add_option("-n","--no-compile", action="store_true", dest="no_compil", help="Do not compile source code") + (options, args) = parser.parse_args() if not options.template: diff --git a/example/csv_example.csv b/example/csv_example.csv new file mode 100644 index 0000000..d8aacc1 --- /dev/null +++ b/example/csv_example.csv @@ -0,0 +1,25 @@ +Classe;Nom;Prenom;identifiant;mdp +6A;ASSAOUA;Najwa;nassaoua;zajulu +6A;AUDINOT;Lea;laudinot;padito +6A;CARVALHO GOUVEIA;Ana Filipa;acarvalhogo;fekovo +6A;CASALTA;Marine;mcasalta9;wufuzu +6A;CASU;Stella-Maria;scasu;jixuyu +6A;DEBLY;Laura;ldebly;cazema +6A;ERNANDES;Carla;cernandes;kahisi +6A;ETIENNE;Melvin;metienne2;jimico +6A;GAILLARD;Dorian;dgaillard;lazofi +6A;GUIDONI;Dominique;dguidoni4;zojihi +6A;HAMMAMI;Oumaļma;ohammami;sugaga +6A;KHEZAMI;Mohamed;mkhezami2;pomeve +6A;KUREK-PINELLI;Ristituda;rkurekpinel;xawunu +6A;LARROQUE;Nino;nlarroque;jivanu +6A;MABIRE;Luca;lmabire;menazi +6A;MATIC;Veljko;vmatic;pijofa +6A;MOUAOU;Saād;smouaou;ruroyo +6A;PERRIN;Nicolas;nperrin4;xenige +6A;PIRES NASCIMENTO;Guillaume;gpiresnasci;yixone +6A;QUARDELLE;Olivier;oquardelle;yekezo +6A;RANCUREL;Fabio;francurel;dowabo +6A;SPINOSI;ALEXANDRE;aspinosi;pebidi +6A;VERBEKE;Hugo;hverbeke;xucibo +6A;WATIN;Anthony;awatin;sucavo diff --git a/example/tpl_example.tex b/example/tpl_example.tex index 3ed6c88..8d47867 100644 --- a/example/tpl_example.tex +++ b/example/tpl_example.tex @@ -9,7 +9,7 @@ % DS DSCorr DM DMCorr Corr \typedoc{DS} \duree{1 heure} -\sujet{\Var{infos.subj}} +\sujet{\Var{infos.Nom}} \begin{document}