|
|
@@ -1,8 +1,10 @@
|
|
|
#!./venv/bin/python
|
|
|
import sys,pypandoc,os,re,subprocess,yaml
|
|
|
#
|
|
|
-data_yml_manadatory_keys=['fichier', 'date', 'type', 'auteur', 'titre']
|
|
|
+data_yml_mandatory_keys=['fichier', 'date', 'auteur', '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
|
|
|
@@ -32,17 +34,28 @@ def star_sec(l):
|
|
|
#-----------------------------------------------------------------------
|
|
|
with open("data.yml") as f:
|
|
|
lt=yaml.safe_load(f)
|
|
|
-
|
|
|
-if not "statut" in lt.keys():
|
|
|
+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 dit 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")
|
|
|
+else: # si statut n'est pas défini, on le définit à "" et type à "Conférence".
|
|
|
lt["statut"]=" "
|
|
|
lt["type"]="Conférence"
|
|
|
+#
|
|
|
+# 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 lt.keys()
|
|
|
if x!="fichier"])
|
|
|
le_titre="\\titre{"+titre_elements+"}"+"\n"
|
|
|
-print(le_titre)
|
|
|
#--------------------------------------------------------------------
|
|
|
-template="../tpl.tex"
|
|
|
+template="../tpl.tex" # le template
|
|
|
#---------------------------------------------------------------------
|
|
|
exten=fich.split(".")[-1]
|
|
|
|
|
|
@@ -57,9 +70,9 @@ 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"--extract-media={images}"]
|
|
|
+#
|
|
|
extra_args= ["-s",f"--template={template}",f"--extract-media={images}"]
|
|
|
#extra_args= ["-s",f"--template={template}",f"--extract-media={images}",
|
|
|
# f"--lof=true"]
|
|
|
@@ -81,16 +94,18 @@ elif exten=="odt":
|
|
|
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:
|
|
|
|
|
|
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}","")
|
|
|
|
|
|
@@ -98,12 +113,13 @@ with open(futurTex,"w") as f:
|
|
|
f.write("\n")
|
|
|
|
|
|
|
|
|
- if "pagestyle" in l:
|
|
|
+ if "debut" in l:
|
|
|
f.write(le_titre)
|
|
|
-
|
|
|
+#
|
|
|
#---fin d'éciture du fichier tex
|
|
|
#
|
|
|
# lualatex, 2 fois:
|
|
|
+#
|
|
|
for i in {1,2}:
|
|
|
subprocess.run(["/usr/bin/lualatex", futurTex])
|
|
|
#--- fin
|