From 4294c2b4a183a0c87c9e06f58596c192b5734939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Schneider?= Date: Wed, 8 Oct 2014 11:38:04 +0200 Subject: [PATCH] test if pdftk binary exists before using it Closes #5650 --- calebasse/pdftk.py | 11 ++++------- calebasse/settings.py | 7 +++++++ requirements.txt | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/calebasse/pdftk.py b/calebasse/pdftk.py index 598cd33b..5afdfb69 100644 --- a/calebasse/pdftk.py +++ b/calebasse/pdftk.py @@ -1,16 +1,13 @@ import os import subprocess -import tempfile + +from calebasse import settings class PdfTk(object): - def __init__(self, pdftk_path=None, prefix='tmp'): - self._pdftk_path = pdftk_path + def __init__(self, prefix='tmp'): + self.pdftk_path = settings.PDFTK_PATH self.prefix = prefix - @property - def pdftk_path(self): - return self._pdftk_path or '/usr/bin/pdftk' - def do(self, args, wait=True): args = [self.pdftk_path] + args proc = subprocess.Popen(args) diff --git a/calebasse/settings.py b/calebasse/settings.py index b18d2a8e..053fe199 100644 --- a/calebasse/settings.py +++ b/calebasse/settings.py @@ -3,6 +3,7 @@ # Django settings for calebasse project. import os +from django.core.exceptions import ImproperlyConfigured from logging.handlers import SysLogHandler PROJECT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'calebasse') @@ -305,6 +306,9 @@ SERVICE_SETTINGS = {} # - age_format: string, string (default: None, alternative behaviour to have # age always displayed in months: "months_only") +# Pdftk binary path (pdftk is used to complete CERFA) +PDFTK_PATH = '/usr/bin/pdftk' + #CSV_ENCODING = 'cp1252' #For windows : windows-1252/Winlatin1 #CSVPROFILE = {\ @@ -353,6 +357,9 @@ except ImportError: import sys sys.exit(1) +if not os.path.exists(PDFTK_PATH): + raise ImproperlyConfigured("pdftk %r binary not found" % PDFTK_PATH) + if RAVEN_CONFIG: INSTALLED_APPS += ('raven.contrib.django.raven_compat', ) LOGGING['handlers']['sentry'] = { diff --git a/requirements.txt b/requirements.txt index fb00c3e4..aa22262f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,5 +19,6 @@ raven >= 3.5.2, < 3.6 M2Crypto --allow-external pycairo django_select2 < 4.3 -#PyGTK doesn't work with pip django-journal +#PyGTK doesn't work with pip +#pdftk we need the binary