From 2a8d7548f78795d1fd807aa924cf1e9646c33a0a Mon Sep 17 00:00:00 2001 From: Chris Biersbach Date: Thu, 7 Mar 2013 09:55:05 +0100 Subject: [PATCH] [FIX] Document: Does no longer generate an error when trying to send a quotation by email when pdftotext is not available. This case is handled more gracefully (a warning in the log). Also changes the default return when generating the index using antiword to be more consistent. lp bug: https://launchpad.net/bugs/1094423 fixed bzr revid: cbi@openerp.com-20130307085505-v9vwo788ios8244u --- addons/document/content_index.py | 4 ++-- addons/document/std_index.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/addons/document/content_index.py b/addons/document/content_index.py index 399541e1f59..cde05987f25 100644 --- a/addons/document/content_index.py +++ b/addons/document/content_index.py @@ -181,11 +181,11 @@ class contentIndex(object): res = (mime, fobj.indexContent(content,filename,fname or realfname) ) else: _logger.debug("Have no object, return (%s, None).", mime) - res = (mime, None ) + res = (mime, '') except Exception: _logger.exception("Cannot index file %s (%s).", filename, fname or realfname) - res = None + res = (mime, '') # If we created a tmp file, unlink it now if not realfname and fname: diff --git a/addons/document/std_index.py b/addons/document/std_index.py index b20874e72f8..dda776b1ec3 100644 --- a/addons/document/std_index.py +++ b/addons/document/std_index.py @@ -105,7 +105,7 @@ class DocIndex(indexer): _logger.warning("Failed attempt to execute antiword (MS Word reader). Antiword is necessary to index the file %s of MIME type %s. Detailed error available at DEBUG level.", fname, self._getMimeTypes()[0]) _logger.debug("Trace of the failed file indexing attempt.", exc_info=True) - return False + return u'' cntIndex.register(DocIndex()) @@ -166,9 +166,14 @@ class PdfIndex(indexer): return ['.pdf'] def _doIndexFile(self, fname): - pop = Popen(['pdftotext', '-enc', 'UTF-8', '-nopgbrk', fname, '-'], shell=False, stdout=PIPE) - (data, _) = pop.communicate() - return _to_unicode(data) + try: + pop = Popen(['pdftotext', '-enc', 'UTF-8', '-nopgbrk', fname, '-'], shell=False, stdout=PIPE) + (data, _) = pop.communicate() + return _to_unicode(data) + except OSError: + _logger.warning("Failed attempt to execute pdftotext. This program is necessary to index the file %s of MIME type %s. Detailed error available at DEBUG level.", fname, self._getMimeTypes()[0]) + _logger.debug("Trace of the failed file indexing attempt.", exc_info=True) + return u'' cntIndex.register(PdfIndex())