diff --git a/cd06-aceduc/.gitignore b/cd06-aceduc/.gitignore new file mode 100644 index 0000000..ef3b909 --- /dev/null +++ b/cd06-aceduc/.gitignore @@ -0,0 +1 @@ +courriers.pdf diff --git a/cd06-aceduc/Makefile b/cd06-aceduc/Makefile new file mode 100644 index 0000000..da170bd --- /dev/null +++ b/cd06-aceduc/Makefile @@ -0,0 +1,19 @@ +TENANT=demarches-departement06.test.entrouvert.org + +HOST=wcs.node1.test-hds.saas.entrouvert + +SCRIPT=concat_pdf.py + +SLUG=ac-educ-etablissement + +OUTPUT=/tmp/courriers.pdf + +all: + rm -f `basename $(OUTPUT)` + scp $(SCRIPT) $(HOST):/tmp + ssh $(HOST) sudo -u wcs wcs-manage runscript -d $(TENANT) /tmp/$(SCRIPT) $(SLUG) $(OUTPUT) + scp $(HOST):$(OUTPUT) . + evince `basename $(OUTPUT)` + +shell: + ssh $(HOST) diff --git a/cd06-aceduc/README b/cd06-aceduc/README new file mode 100644 index 0000000..e408f8a --- /dev/null +++ b/cd06-aceduc/README @@ -0,0 +1,19 @@ +Script pour produire la concaténation de courriers PDF +====================================================== + +Cf. https://dev.entrouvert.org/issues/64719 + +Exécution en recette: +--------------------- + + make + +Le résultat se trouve dans courriers.pdf + + +Exécution en production: +------------------------ + + make HOST=wcs.node1.hds.saas.entrouvert TENANT=demarches.mesdemarches06.fr + +Le résultat se trouve dans courriers.pdf diff --git a/cd06-aceduc/concat_pdf.py b/cd06-aceduc/concat_pdf.py new file mode 100644 index 0000000..7982544 --- /dev/null +++ b/cd06-aceduc/concat_pdf.py @@ -0,0 +1,32 @@ +import sys +from pathlib import Path +from subprocess import PIPE, CalledProcessError, check_output + +from wcs.carddef import CardDef + +SLUG = sys.argv[1] +output_path = sys.argv[2] + +try: + carddef = CardDef.get_by_slug(SLUG) +except KeyError: + print(f'Pas de formdef nommé "{SLUG}"') + raise SystemExit(1) + +field = [field for field in carddef.workflow.backoffice_fields_formdef.fields if field.varname == "courrier"][ + 0 +] + +uploads = [] +for card in carddef.data_class().select(): + if card.data.get(field.id): + uploads.append(Path(card.data[field.id].get_fs_filename())) + +try: + check_output( + ["/usr/bin/pdftk"] + [str(path) for path in uploads] + ["cat", "output", output_path], + stderr=PIPE, + ) +except CalledProcessError as e: + print(f"Error: {e}\nStdout:\n{e.output.decode()}\nStderr:\n{e.stderr.decode()}") + raise SystemExit(1)