documentation, build.sh script, options to specify paths

This commit is contained in:
Emmanuel Viennet 2021-04-10 17:35:40 +02:00
parent 6247885300
commit 907575c634
9 changed files with 534 additions and 41 deletions

319
.gitignore vendored Normal file
View File

@ -0,0 +1,319 @@
# ---> LyX
# Ignore LyX backup and autosave files
# http://www.lyx.org/
*.lyx~
*.lyx#
# ---> TeX
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb
## Intermediate documents:
*.dvi
*.xdv
*-converted-to.*
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf
## Generated if empty string is given at "Please type another file name for output:"
.pdf
## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
## Build tool directories for auxiliary files
# latexrun
latex.out/
## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa
# achemso
acs-*.bib
# amsthm
*.thm
# beamer
*.nav
*.pre
*.snm
*.vrb
# changes
*.soc
# comment
*.cut
# cprotect
*.cpt
# elsarticle (documentclass of Elsevier journals)
*.spl
# endnotes
*.ent
# fixme
*.lox
# feynmf/feynmp
*.mf
*.mp
*.t[1-9]
*.t[1-9][0-9]
*.tfm
#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R
# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs
*.lzo
*.lzs
# uncomment this for glossaries-extra (will ignore makeindex's style files!)
# *.ist
# gnuplottex
*-gnuplottex-*
# gregoriotex
*.gaux
*.gtex
# htlatex
*.4ct
*.4tc
*.idv
*.lg
*.trc
*.xref
# hyperref
*.brf
# knitr
*-concordance.tex
# TODO Uncomment the next line if you use knitr and want to ignore its generated tikz files
# *.tikz
*-tikzDictionary
# listings
*.lol
# luatexja-ruby
*.ltjruby
# makeidx
*.idx
*.ilg
*.ind
# minitoc
*.maf
*.mlf
*.mlt
*.mtc[0-9]*
*.slf[0-9]*
*.slt[0-9]*
*.stc[0-9]*
# minted
_minted*
*.pyg
# morewrites
*.mw
# nomencl
*.nlg
*.nlo
*.nls
# pax
*.pax
# pdfpcnotes
*.pdfpc
# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd
# scrwfile
*.wrt
# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/
# pdfcomment
*.upa
*.upb
# pythontex
*.pytxcode
pythontex-files-*/
# tcolorbox
*.listing
# thmtools
*.loe
# TikZ & PGF
*.dpth
*.md5
*.auxlock
# todonotes
*.tdo
# vhistory
*.hst
*.ver
# easy-todo
*.lod
# xcolor
*.xcp
# xmpincl
*.xmpi
# xindy
*.xdy
# xypic precompiled matrices and outlines
*.xyc
*.xyd
# endfloat
*.ttt
*.fff
# Latexian
TSWLatexianTemp*
## Editors:
# WinEdt
*.bak
*.sav
# Texpad
.texpadtmp
# LyX
*.lyx~
# Kile
*.backup
# gummi
.*.swp
# KBibTeX
*~[0-9]*
# TeXnicCenter
*.tps
# auto folder when using emacs and auctex
./auto/*
*.el
# expex forward references with \gathertags
*-tags.tex
# standalone packages
*.sta
# Makeindex log files
*.lpz
# xwatermark package
*.xwm
# REVTeX puts footnotes in the bibliography by default, unless the nofootinbib
# option is specified. Footnotes are the stored in a file with suffix Notes.bib.
# Uncomment the next line to have this generated file ignored.
#*Notes.bib
# MacOS
.DS_Store?
ehthumbs.db
Icon?
Thumbs.db
*.DS_Store
# Emacs
*~
\#*\#
/.emacs.desktop
/.emacs.desktop.lock
*.elc
auto-save-list
tramp
.\#*
# Python
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# VS Code
.vscode/
*.code-workspace

View File

@ -1 +1,47 @@
# Referentiels # Référentiel de formation R&T
## Installation sur Mac
Avec Anaconda:
conda install pypandoc
conda install ruamel
conda install ruamel.yaml
pip install docx2python
Sans Anaconda, remplacer `conda` par `pip`.
## Utilisation
Les sources sont les fichiers GoogleDoc (drive), réunis par un script Apps Scripts (`FusionneFiches`) qui permet d'obtenir deux documents: l'un réunissant les fiches ressources, l'autre les fiches SAÉ.
### Extraction des informations
Les fichiers `.docx` sont analysés pour créer les documents `yaml`. On a un script pour les ressource et un autre pour les SAÉ.
#### Ressources
cd python
python export_docx_to_yaml.py [nom du fichier docx]
par exemple:
python export_docx_to_yaml.py import/compilation-ressources\ 2021-04-10T07_38_45.782Z.docx
#### SAÉs
python export_sae_docx_to_yaml.py import/compilation-saes\ 2021-04-10T07_37_48.302Z.docx
### Génération du LaTeX
cd python
python export_yaml_to_latex.py --full
### Génération de PDF
cd latex
pdflatex pn_formation
pdflatex pn_formation
Le résultat est `pn_formation.pdf`.

33
build.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# Reconstruit tout !
ressources="$1"
saes="$2"
die() {
echo
echo "Erreur: $1"
echo
exit 1
}
[ "$ressources" ] || die "Usage: $0 doc_ressources doc_sae"
[ "$saes" ] || die "Usage: $0 doc_ressources doc_sae"
[ -d python ] || die "repertoire manquant: python"
[ -d latex ] || die "repertoire manquant: latex"
[ -d python/export ] || mkdir "python/export" || die "creating python/export directory"
python python/export_docx_to_yaml.py "$ressources" -o "python/export" -r . || die "echec de export_docx_to_yaml.py"
python python/export_sae_docx_to_yaml.py "$saes" -o "python/export" -r . || die "echec de export_sae_docx_to_yaml.py"
python python/export_yaml_to_latex.py -a -r . || die "echec de export_yaml_to_latex.py"
cd latex
pdflatex pn_formation
pdflatex pn_formation
echo "Done."
echo "Resultat: latex/pn_formation.pdf"

8
python/config.py Normal file
View File

@ -0,0 +1,8 @@
"""Configuration (chemins)
"""
import os
class Config(object):
ROOT=".."

View File

@ -1,21 +1,49 @@
import sys
import argparse
import logging
import docx2python import docx2python
from ressource import get_matrices_ac_ressource from config import Config
from ressourcedocx import *
import tools
import logging
from tools import get_indice, get_indice_sans_accent_ni_espace
__LOGGER = logging.getLogger(__name__) __LOGGER = logging.getLogger(__name__)
REPERTOIRE = "import" REPERTOIRE = "import"
DOCUMENT = "ressources_v1"
parser = argparse.ArgumentParser(
description="Parse doc ressources et crée yaml",
usage='%(prog)s [options]'
)
parser.add_argument(
"DOCUMENT",
nargs="?",
default=REPERTOIRE + "/" + "ressources_v0" + ".docx"
)
parser.add_argument(
"-o",
"--outdir",
default="export",
help="repertoire resultat, defaut: export"
)
parser.add_argument(
"-r",
"--root",
default="..",
help="repertoire de base (racine) pour chercher les fichiers de données"
)
args = parser.parse_args()
Config.ROOT = args.root
__LOGGER.warning(f"{sys.argv[0]} processing {args.DOCUMENT}")
__LOGGER.warning(f"{sys.argv[0]} outputs to {args.outdir}")
# Ces imports doivent être faits après la config
import tools
from tools import get_indice, get_indice_sans_accent_ni_espace
from ressource import get_matrices_ac_ressource
from ressourcedocx import *
# Ouverture du document # Ouverture du document
docu = docx2python.docx2python(REPERTOIRE + "/" + DOCUMENT + ".docx") docu = docx2python.docx2python(args.DOCUMENT)
docu = docu.body docu = docu.body
docu[0] # Titre général docu[0] # Titre général
@ -161,7 +189,7 @@ for sem in ressources:
for r in ressources[sem]: for r in ressources[sem]:
output = r.to_yaml() output = r.to_yaml()
if WITH_EXPORT and r.code: if WITH_EXPORT and r.code:
fichier = "export/{}.yml".format(r.code) fichier = f"{args.outdir}/{r.code}.yml"
with open(fichier, "w", encoding="utf8") as fid: with open(fichier, "w", encoding="utf8") as fid:
fid.write(output) fid.write(output)

View File

@ -1,16 +1,47 @@
import docx2python import sys
from ressourcedocx import * import argparse
from tools import *
import logging import logging
__LOGGER = logging.getLogger(__name__) import docx2python
from config import Config
__LOGGER = logging.getLogger(__name__)
REPERTOIRE = "import" REPERTOIRE = "import"
DOCUMENT = "sae_v1"
parser = argparse.ArgumentParser(
description="Parse doc ressources et crée SAE",
usage='%(prog)s [options]'
)
parser.add_argument(
"DOCUMENT",
nargs="?",
default=REPERTOIRE + "/" + "ressources_v0" + ".docx"
)
parser.add_argument(
"-o",
"--outdir",
default="export",
help="repertoire resultat, defaut: export"
)
parser.add_argument(
"-r",
"--root",
default="..",
help="repertoire de base (racine) pour chercher les fichiers de données"
)
args = parser.parse_args()
Config.ROOT = args.root
__LOGGER.warning(f"{sys.argv[0]} processing {args.DOCUMENT}")
__LOGGER.warning(f"{sys.argv[0]} outputs to {args.outdir}")
# Ces imports doivent être faits après la config
from tools import *
from ressourcedocx import *
# Ouverture du document # Ouverture du document
docu = docx2python.docx2python(REPERTOIRE + "/" + DOCUMENT + ".docx") docu = docx2python.docx2python(args.DOCUMENT)
docu = docu.body docu = docu.body
docu[0] # Titre général docu[0] # Titre général
@ -200,7 +231,8 @@ for sem in saes:
for s in saes[sem]: for s in saes[sem]:
output = s.to_yaml() output = s.to_yaml()
if s.code: if s.code:
fichier = "export/{}.yml".format(s.code.replace("É", "E")) code_clean = s.code.replace("É", "E")
fichier = f"{args.outdir}/{code_clean}.yml"
with open(fichier, "w", encoding="utf8") as fid: with open(fichier, "w", encoding="utf8") as fid:
fid.write(output) fid.write(output)
@ -208,7 +240,8 @@ for sem in exemples:
for s in exemples[sem]: for s in exemples[sem]:
for (i, e) in enumerate(exemples[sem][s]): for (i, e) in enumerate(exemples[sem][s]):
output = e.to_yaml() output = e.to_yaml()
fichier = "export/{}_exemple{}.yml".format(s.replace("É", "E"), i+1) code_clean = s.replace("É", "E")
fichier = f"{args.outdir}/{code_clean}_exemple{i+1}.yml"
with open(fichier, "w", encoding="utf8") as fid: with open(fichier, "w", encoding="utf8") as fid:
fid.write(output) fid.write(output)

View File

@ -1,16 +1,38 @@
import ressource
from ressource import *
import os import os
import officiel import argparse
import logging import logging
from config import Config
__LOGGER = logging.getLogger(__name__) __LOGGER = logging.getLogger(__name__)
REPERTOIRE_TEMP = "export"
REPERTOIRE_RESSOURCES_DEFINITIVES = "../yaml/ressources" parser = argparse.ArgumentParser(description="Conversion des YAML en LaTeX")
REPERTOIRE_SAE_DEFINITIVES = "../yaml/saes" parser.add_argument(
REPERTOIRE_LATEX_RESSOURCES = "../latex/ressources" "-a",
REPERTOIRE_LATEX_SAES = "../latex/saes" "--all",
action="store_true",
help="exporte le LaTeX complet"
)
parser.add_argument(
"-r",
"--root",
default="..",
help="repertoire de base (racine) pour chercher les fichiers de données"
)
args = parser.parse_args()
Config.ROOT = args.root
import ressource
from ressource import *
import officiel
REPERTOIRE_TEMP = Config.ROOT + "/python/export"
REPERTOIRE_RESSOURCES_DEFINITIVES = Config.ROOT + "/yaml/ressources"
REPERTOIRE_SAE_DEFINITIVES = Config.ROOT + "/yaml/saes"
REPERTOIRE_LATEX_RESSOURCES = Config.ROOT + "/latex/ressources"
REPERTOIRE_LATEX_SAES = Config.ROOT + "/latex/saes"
REPERTOIRE_SYNTHESE = Config.ROOT + "/latex/synthese"
# Chargement des ressources : depuis les versions définitives du répertoire yaml d'abord, # Chargement des ressources : depuis les versions définitives du répertoire yaml d'abord,
# puis dans python/export si manquantes # puis dans python/export si manquantes
@ -73,7 +95,6 @@ for sem in ["S1", "S2"]:
print(str_matrice(M1, saes, ressources, sem)) print(str_matrice(M1, saes, ressources, sem))
chaine = ressource.to_latex_matrice_acs(M1, saes, ressources, sem) chaine = ressource.to_latex_matrice_acs(M1, saes, ressources, sem)
REPERTOIRE_SYNTHESE = "../latex/synthese"
fichierlatex = REPERTOIRE_SYNTHESE + "/" + f"{sem}_acs_vs_saes_ressources.tex" fichierlatex = REPERTOIRE_SYNTHESE + "/" + f"{sem}_acs_vs_saes_ressources.tex"
with open(fichierlatex, "w", encoding="utf8") as fid: with open(fichierlatex, "w", encoding="utf8") as fid:
fid.write(chaine) fid.write(chaine)
@ -94,8 +115,10 @@ for sem in ["S1", "S2"]:
fid.write(chaine) fid.write(chaine)
print(f"Export de {fichierlatex}") print(f"Export de {fichierlatex}")
## Export latex divers ## Export latex divers (désactivé par défaut pour gagner du temps)
if False: if not args.all:
__LOGGER.warning(f"{sys.argv[0]}: reduced version (use -a to get full docs)")
else:
# Export latex des ressources # Export latex des ressources
for sem in ressources: for sem in ressources:
for r in ressources[sem]: for r in ressources[sem]:

View File

@ -1,23 +1,24 @@
import logging, yaml import logging, yaml
import unicodedata import unicodedata
from config import Config
__LOGGER = logging.getLogger(__name__) __LOGGER = logging.getLogger(__name__)
# Récupère les informations officielles # Récupère les informations officielles
## Les ressources ## Les ressources
with open("pn/ressources.yml", 'r', encoding="utf8") as fid: with open(Config.ROOT+"/python/pn/ressources.yml", 'r', encoding="utf8") as fid:
DATA_RESSOURCES = yaml.load(fid.read(), Loader=yaml.Loader) DATA_RESSOURCES = yaml.load(fid.read(), Loader=yaml.Loader)
## Les ACS ## Les ACS
with open("pn/acs.yml", 'r', encoding="utf8") as fid: with open(Config.ROOT+"/python/pn/acs.yml", 'r', encoding="utf8") as fid:
DATA_ACS = yaml.load(fid.read(), Loader=yaml.Loader) DATA_ACS = yaml.load(fid.read(), Loader=yaml.Loader)
## Les SAEs ## Les SAEs
with open("pn/saes.yml", 'r', encoding="utf8") as fid: with open(Config.ROOT+"/python/pn/saes.yml", 'r', encoding="utf8") as fid:
DATA_SAES = yaml.load(fid.read(), Loader=yaml.Loader) DATA_SAES = yaml.load(fid.read(), Loader=yaml.Loader)
## Les compétences ## Les compétences
with open("../yaml/competences/RT123.yml", 'r', encoding="utf8") as fid: with open(Config.ROOT+"/yaml/competences/RT123.yml", 'r', encoding="utf8") as fid:
DATA_COMPETENCES = yaml.load(fid.read(), Loader=yaml.Loader) DATA_COMPETENCES = yaml.load(fid.read(), Loader=yaml.Loader)
## Les abbréviations ## Les abbréviations
with open("../yaml/abbreviations.yml", "r", encoding="utf8") as fid: with open(Config.ROOT+"/yaml/abbreviations.yml", "r", encoding="utf8") as fid:
DATA_ABBREVIATIONS = yaml.load(fid.read(), Loader=yaml.Loader) DATA_ABBREVIATIONS = yaml.load(fid.read(), Loader=yaml.Loader)
def supprime_accent_espace(chaine): def supprime_accent_espace(chaine):

View File

@ -3,6 +3,8 @@ import string
import pypandoc import pypandoc
import ruamel.yaml import ruamel.yaml
from config import Config
from modeles import get_modele, TemplateLatex from modeles import get_modele, TemplateLatex
from officiel import * from officiel import *
from ressourcedocx import remove_ligne_vide from ressourcedocx import remove_ligne_vide
@ -22,7 +24,7 @@ class Ressource():
except: except:
Ressource.__LOGGER.warning(f"Pb de chargement de {fichieryaml}") Ressource.__LOGGER.warning(f"Pb de chargement de {fichieryaml}")
def to_latex(self, modele="pn/modele_ressource.tex"): def to_latex(self, modele=Config.ROOT+"/python/pn/modele_ressource.tex"):
"""Génère le code latex décrivant la ressource""" """Génère le code latex décrivant la ressource"""
modlatex = get_modele(modele) #"pn/modele_ressource.tex") modlatex = get_modele(modele) #"pn/modele_ressource.tex")
@ -149,7 +151,7 @@ class SAE():
def to_latex(self, modele="pn/modele_sae.tex"): def to_latex(self, modele=Config.ROOT+"/python/pn/modele_sae.tex"):
"""Génère le code latex décrivant la ressource""" """Génère le code latex décrivant la ressource"""
modlatex = get_modele(modele) #"pn/modele_ressource.tex") modlatex = get_modele(modele) #"pn/modele_ressource.tex")
@ -233,7 +235,7 @@ class ExempleSAE():
except: except:
Ressource.__LOGGER.warning(f"Pb de chargement de {fichieryaml}") Ressource.__LOGGER.warning(f"Pb de chargement de {fichieryaml}")
def to_latex(self, modele="pn/modele_exemple_sae.tex"): def to_latex(self, modele=Config.ROOT+"/python/pn/modele_exemple_sae.tex"):
"""Génère le code latex décrivant la ressource""" """Génère le code latex décrivant la ressource"""
modlatex = get_modele(modele) #"pn/modele_ressource.tex") modlatex = get_modele(modele) #"pn/modele_ressource.tex")