Commit 6b7bff1e authored by Jérome Perrin's avatar Jérome Perrin

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
parent 3e0ae1e0
...@@ -103,7 +103,8 @@ class PDFTk : ...@@ -103,7 +103,8 @@ class PDFTk :
""" returns the output of pdftk dump_data_fields as text, """ returns the output of pdftk dump_data_fields as text,
pdf file is either the file object or its content""" pdf file is either the file object or its content"""
return self._getOutput( 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) : def _parseDumpDataFields(self, data_fields_dump) :
""" parses the output of pdftk X.pdf dump_data_fields and """ parses the output of pdftk X.pdf dump_data_fields and
...@@ -121,17 +122,24 @@ class PDFTk : ...@@ -121,17 +122,24 @@ class PDFTk :
fields+=[field] fields+=[field]
return fields 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 """ returns the output of command with sending input through command's
input stream (if input parameter is given) """ input stream (if input parameter is given) """
stdout, stdin = popen2.popen2(command) stdout, stdin = popen2.popen2(command)
if input: if input:
if hasattr(input, "read") : if hasattr(input, "read") :
input = input.read() input = input.read()
try :
stdin.write(input) stdin.write(input)
except IOError, e:
raise IOError, str(e) + " ( make sure "\
"%s exists and is in your $PATH )"%PDFTK_EXECUTABLE
stdin.close() stdin.close()
ret = stdout.read() ret = stdout.read()
stdout.close() 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 return ret
def _escapeString(self, value) : def _escapeString(self, value) :
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment