Projet

Général

Profil

0001-test-if-pdftk-binary-exists-before-using-it.patch

Jérôme Schneider, 08 octobre 2014 11:39

Télécharger (2,07 ko)

Voir les différences:

Subject: [PATCH] test if pdftk binary exists before using it

Closes #5650
 calebasse/pdftk.py    | 14 +++++++-------
 calebasse/settings.py |  3 +++
 requirements.txt      |  3 ++-
 3 files changed, 12 insertions(+), 8 deletions(-)
calebasse/pdftk.py
1 1
import os
2 2
import subprocess
3
import tempfile
3

  
4
from calebasse import settings
5
from django.core.exceptions import ImproperlyConfigured
4 6

  
5 7
class PdfTk(object):
6
    def __init__(self, pdftk_path=None, prefix='tmp'):
7
        self._pdftk_path = pdftk_path
8
    def __init__(self, prefix='tmp'):
9
        self.pdftk_path = settings.PDFTK_PATH
10
        if not os.path.exists(self.pdftk_path):
11
            raise ImproperlyConfigured("pdftk %r binary not found" % self.pdftk_path)
8 12
        self.prefix = prefix
9 13

  
10
    @property
11
    def pdftk_path(self):
12
        return self._pdftk_path or '/usr/bin/pdftk'
13

  
14 14
    def do(self, args, wait=True):
15 15
        args = [self.pdftk_path] + args
16 16
        proc = subprocess.Popen(args)
calebasse/settings.py
305 305
# - age_format: string, string (default: None, alternative behaviour to have
306 306
#   age always displayed in months: "months_only")
307 307

  
308
# Pdftk binary path (pdftk is used to complete CERFA)
309
PDFTK_PATH = '/usr/bin/pdftk'
310

  
308 311

  
309 312
#CSV_ENCODING = 'cp1252' #For windows : windows-1252/Winlatin1
310 313
#CSVPROFILE = {\
requirements.txt
19 19
M2Crypto
20 20
--allow-external pycairo
21 21
django_select2 < 4.3
22
#PyGTK doesn't work with pip
23 22
django-journal
23
#PyGTK doesn't work with pip
24
#pdftk we need the binary
24
-