cd06-aceduc: script pour concaténer les fichiers courriers
This commit is contained in:
parent
bcba0f150b
commit
362d6321ef
|
@ -0,0 +1 @@
|
|||
courriers.pdf
|
|
@ -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)
|
|
@ -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
|
|
@ -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)
|
Loading…
Reference in New Issue