From 6b7bff1e12e65365cc814f412f21f65aa20de461 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 25 Jul 2005 09:19:32 +0000
Subject: [PATCH] Do some simple checks to make sure that pdftk is in path

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3498 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/PDFForm.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/product/ERP5Form/PDFForm.py b/product/ERP5Form/PDFForm.py
index fe89490f10..73d491c242 100755
--- a/product/ERP5Form/PDFForm.py
+++ b/product/ERP5Form/PDFForm.py
@@ -103,7 +103,8 @@ class PDFTk :
         """ returns the output of pdftk dump_data_fields as text, 
           pdf file is either the file object or its content"""
         return self._getOutput(
-                PDFTK_EXECUTABLE+" - dump_data_fields", pdfFile)
+                PDFTK_EXECUTABLE+" - dump_data_fields", pdfFile, 
+                assert_not_empty=0)
               
     def _parseDumpDataFields(self, data_fields_dump) :
         """ parses the output of pdftk X.pdf dump_data_fields and
@@ -121,17 +122,24 @@ class PDFTk :
                 fields+=[field]
         return fields
     
-    def _getOutput(self, command, input=None) :
+    def _getOutput(self, command, input=None, assert_not_empty=1) :
         """ returns the output of command with sending input through command's
         input stream (if input parameter is given) """
         stdout, stdin = popen2.popen2(command)
         if input:
             if hasattr(input, "read") :
                 input = input.read()
-            stdin.write(input)
+            try : 
+                stdin.write(input)
+            except IOError, e:
+                raise IOError, str(e) + " ( make sure "\
+                "%s exists and is in your $PATH )"%PDFTK_EXECUTABLE
         stdin.close()
         ret = stdout.read()
         stdout.close()
+        if assert_not_empty and len(ret) == 0 : 
+            raise IOError, "Got no output from external program, make sure"\
+                       " %s exists and is in your $PATH"%PDFTK_EXECUTABLE
         return ret
         
     def _escapeString(self, value) : 
-- 
2.30.9