|
@@ -1,158 +0,0 @@
|
|
|
-#!/home/moi/ProtoMemoires/venv/bin/python
|
|
|
|
|
-import sys,pypandoc,os,re,subprocess,yaml
|
|
|
|
|
-#
|
|
|
|
|
-data_yml_mandatory_keys=['fichier', 'date', 'auteur', 'titre']
|
|
|
|
|
-data_yml_order=['date','type','auteur','statut','titre']
|
|
|
|
|
-def star_sec(l):
|
|
|
|
|
- # \section est transformée en \section* et on ne garde comme argument
|
|
|
|
|
- # que ce qui est nécessaire.
|
|
|
|
|
- it=iter(L)
|
|
|
|
|
- ret=[]
|
|
|
|
|
- passed= False
|
|
|
|
|
- for x in it:
|
|
|
|
|
- if "begin{document" in x:
|
|
|
|
|
- passed= True
|
|
|
|
|
- if passed and "section[" in x:
|
|
|
|
|
- s=x
|
|
|
|
|
- while "label" not in x:
|
|
|
|
|
- x=next(it)
|
|
|
|
|
- s=s+" "+x
|
|
|
|
|
-
|
|
|
|
|
- if not "}" in s:
|
|
|
|
|
- x=next(it)
|
|
|
|
|
- s=s+x
|
|
|
|
|
- k=s.find("]")
|
|
|
|
|
- r=(s[:k]+"}").replace("[","*{")+" "
|
|
|
|
|
- ret.append(r)
|
|
|
|
|
- ret.append("\n")
|
|
|
|
|
- else:
|
|
|
|
|
- ret.append(x)
|
|
|
|
|
- return ret
|
|
|
|
|
-#
|
|
|
|
|
-
|
|
|
|
|
-#-----------------------------------------------------------------------
|
|
|
|
|
-# Construire le titre à partir du fichier yml.
|
|
|
|
|
-#-----------------------------------------------------------------------
|
|
|
|
|
-with open("data.yml") as f:
|
|
|
|
|
- lt=yaml.safe_load(f)
|
|
|
|
|
-
|
|
|
|
|
-for x in data_yml_mandatory_keys: #vérifier la présence des clés obligatoires
|
|
|
|
|
- if not x in lt.keys():
|
|
|
|
|
- raise Exception(f"\n\n Il manque {x} dans data.yml\n\n")
|
|
|
|
|
-# si statut est défini, type doit l'être aussi:
|
|
|
|
|
-if "statut" in lt.keys():
|
|
|
|
|
- if "type" not in lt.keys():
|
|
|
|
|
- raise Exception(f"\n\n statut est défini, mais pas type\n\n")
|
|
|
|
|
- lt['statut']=", "+lt["statut"]
|
|
|
|
|
-else: # si statut n'est pas défini, on le définit à " " et type à "Conférence".
|
|
|
|
|
- lt["statut"]=" "
|
|
|
|
|
- lt["type"]="Conférence"
|
|
|
|
|
-# biblio ?
|
|
|
|
|
-has_bib= "biblio"in lt.keys()
|
|
|
|
|
-#
|
|
|
|
|
-# le fichier (docx, odt) qu'on va traiter:
|
|
|
|
|
-#
|
|
|
|
|
-fich=lt["fichier"].strip()
|
|
|
|
|
-#
|
|
|
|
|
-# fabriquer le titre à partir des données yml
|
|
|
|
|
-#
|
|
|
|
|
-titre_elements="}{".join([lt[x].replace("\n","") for x in data_yml_order])
|
|
|
|
|
-
|
|
|
|
|
-#le_titre="\\titre{"+titre_elements+"}"+"\n"
|
|
|
|
|
-le_titre= f"\\titre{{{titre_elements}}}\n"
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-#--------------------------------------------------------------------
|
|
|
|
|
-template="../tpl.tex" # le template
|
|
|
|
|
-#---------------------------------------------------------------------
|
|
|
|
|
-exten=fich.split(".")[-1]
|
|
|
|
|
-
|
|
|
|
|
-if exten=="docx" or exten=="odt":
|
|
|
|
|
- futurTex= fich.replace(exten,"tex")
|
|
|
|
|
-else:
|
|
|
|
|
- s=f"\n{fich} : extension incorrecte"
|
|
|
|
|
- raise Exception(s)
|
|
|
|
|
-
|
|
|
|
|
-#répertoire pour les images
|
|
|
|
|
-images= fich.split(".")[0]+"-media"
|
|
|
|
|
-print("Répertoire des images : ",images)
|
|
|
|
|
-if not os.path.isdir(images):
|
|
|
|
|
- os.mkdir(images)
|
|
|
|
|
-#
|
|
|
|
|
-# conversion en latex
|
|
|
|
|
-#
|
|
|
|
|
-#extra_args= ["-s",f"--template={template}",f"--extract-media={images}"]
|
|
|
|
|
-extra_args= ["-s",f"--template={template}",f"--extract-media={images}",
|
|
|
|
|
- f"--lof=true"]
|
|
|
|
|
-L = pypandoc.convert_file(fich, 'tex',
|
|
|
|
|
- extra_args=extra_args).splitlines()
|
|
|
|
|
-
|
|
|
|
|
-#-----------------------------------------------------------------------
|
|
|
|
|
-
|
|
|
|
|
-# section -> section*
|
|
|
|
|
-rechsec= r"section[{\[]"
|
|
|
|
|
-rechsecc=re.compile(rechsec)
|
|
|
|
|
-
|
|
|
|
|
-# pour modifier le latex en changeant le chemin vers les images.
|
|
|
|
|
-if exten=="docx":
|
|
|
|
|
- rechgra=r"includegraphics\[.*\]{media.*}"
|
|
|
|
|
- repPath=("media",f"{images}/word/media")
|
|
|
|
|
-elif exten=="odt":
|
|
|
|
|
- rechgra=r"includegraphics\[.*\]{Pictures.*}"
|
|
|
|
|
- repPath=("Pictures",f"{images}/Pictures")
|
|
|
|
|
-
|
|
|
|
|
-rechgrac=re.compile(rechgra)
|
|
|
|
|
-#
|
|
|
|
|
-# On crée le fichier tex
|
|
|
|
|
-#
|
|
|
|
|
-with open(futurTex,"w") as f:
|
|
|
|
|
- L1=star_sec(L)
|
|
|
|
|
-
|
|
|
|
|
- rp0,rp1= repPath
|
|
|
|
|
- for l in L1:
|
|
|
|
|
- if has_bib and "addbibresource{}" in l:
|
|
|
|
|
- bibfile=lt['biblio']
|
|
|
|
|
- l=l.replace("{","{"+bibfile)
|
|
|
|
|
- if "textsuperscript{e}" in l:
|
|
|
|
|
- print(l)
|
|
|
|
|
- l=l.replace("textsuperscript{e}","ieme{}")
|
|
|
|
|
- print(l)
|
|
|
|
|
- #ccc=input()
|
|
|
|
|
- while (q:=rechgrac.search(l)) != None:
|
|
|
|
|
- l=l.replace(rp0,rp1)
|
|
|
|
|
- # on supprime les "quote"
|
|
|
|
|
- l=l.replace("\\begin{quote}","")
|
|
|
|
|
- l=l.replace("\\end{quote}","")
|
|
|
|
|
- # subsection-> subsection*
|
|
|
|
|
- l=l.replace("subsection{","subsection*{")
|
|
|
|
|
-
|
|
|
|
|
- if "@@fin" in l:
|
|
|
|
|
- if has_bib:
|
|
|
|
|
- f.write("\\begin{center}\\textbf{Bibliographie}\\end{center}\n")
|
|
|
|
|
- f.write("\citeall[\\fullcite]\n")
|
|
|
|
|
- f.write("\FloatBarrier\n")
|
|
|
|
|
- f.write(l)
|
|
|
|
|
- f.write("\n")
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- if "@@debut" in l:
|
|
|
|
|
- f.write("\\fancyhead{}\n")
|
|
|
|
|
- f.write("\\fancyhead[CE]{Mémoires: 2\ieme{} partie}\n")
|
|
|
|
|
- aut= lt["auteur"]
|
|
|
|
|
- f.write(f"\\fancyhead[CO]{{{lt['auteur']}, {lt['titre']}}}\n")
|
|
|
|
|
- f.write(le_titre)
|
|
|
|
|
-
|
|
|
|
|
-#
|
|
|
|
|
-#---fin d'éciture du fichier tex
|
|
|
|
|
-#
|
|
|
|
|
-# lualatex, 2 fois:
|
|
|
|
|
-#
|
|
|
|
|
-
|
|
|
|
|
-subprocess.run(["/usr/bin/lualatex", futurTex])
|
|
|
|
|
-if has_bib:
|
|
|
|
|
- subprocess.run(["/usr/bin/biber", futurTex.replace(".tex","")])
|
|
|
|
|
- subprocess.run(["/usr/bin/lualatex", futurTex])
|
|
|
|
|
-subprocess.run(["/usr/bin/lualatex", futurTex])
|
|
|
|
|
-#--- fin
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|