test if pdftk binary exists before using it

Closes #5650
This commit is contained in:
Jérôme Schneider 2014-10-08 11:38:04 +02:00
parent 0a4f779fa4
commit 4294c2b4a1
3 changed files with 13 additions and 8 deletions

View File

@ -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)

View File

@ -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'] = {

View File

@ -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