Projet

Général

Profil

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

Jérôme Schneider, 08 octobre 2014 15:20

Télécharger (2,5 ko)

Voir les différences:

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

Closes #5650
 calebasse/pdftk.py    | 12 +++++-------
 calebasse/settings.py |  7 +++++++
 requirements.txt      |  3 ++-
 3 files changed, 14 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
8 10
        self.prefix = prefix
9 11

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

  
14 12
    def do(self, args, wait=True):
15 13
        args = [self.pdftk_path] + args
16 14
        proc = subprocess.Popen(args)
calebasse/settings.py
3 3
# Django settings for calebasse project.
4 4

  
5 5
import os
6
from django.core.exceptions import ImproperlyConfigured
6 7
from logging.handlers import SysLogHandler
7 8

  
8 9
PROJECT_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'calebasse')
......
305 306
# - age_format: string, string (default: None, alternative behaviour to have
306 307
#   age always displayed in months: "months_only")
307 308

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

  
308 312

  
309 313
#CSV_ENCODING = 'cp1252' #For windows : windows-1252/Winlatin1
310 314
#CSVPROFILE = {\
......
353 357
    import sys
354 358
    sys.exit(1)
355 359

  
360
if not os.path.exists(PDFTK_PATH):
361
    raise ImproperlyConfigured("pdftk %r binary not found" % PDFTK_PATH)
362

  
356 363
if RAVEN_CONFIG:
357 364
    INSTALLED_APPS += ('raven.contrib.django.raven_compat', )
358 365
    LOGGING['handlers']['sentry'] = {
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
-