From 467968b79a713d10f53b387d911dcdd6ef10ce11 Mon Sep 17 00:00:00 2001
From: Simon Lejeune <sle@openerp.com>
Date: Sun, 23 Nov 2014 15:01:52 +0100
Subject: [PATCH] [FIX] tools: find_in_path: config is not ready at import time

commit f76d4525a was not actually working: extra keys from
config files are not yet into the config options dict at
import time. The fix is to move the logic inside the method,
like in `find_pg_tool` just below.

Also fix the use of `find_in_path` in report.py: the subprocess
may also raise AttributeError exception, so instead of listing
all the possible ones just re-raise the IOError shallowed by
`find_in_path` when the result is None.

Fixes #3809 #3811
---
 addons/report/models/report.py | 7 +++++--
 openerp/tools/misc.py          | 9 ++++-----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/addons/report/models/report.py b/addons/report/models/report.py
index 0233af6312e8..057d3565abdd 100644
--- a/addons/report/models/report.py
+++ b/addons/report/models/report.py
@@ -49,7 +49,10 @@ from pyPdf import PdfFileWriter, PdfFileReader
 _logger = logging.getLogger(__name__)
 
 def _get_wkhtmltopdf_bin():
-    return find_in_path('wkhtmltopdf')
+    wkhtmltopdf_bin = find_in_path('wkhtmltopdf')
+    if wkhtmltopdf_bin is None:
+        raise IOError
+    return wkhtmltopdf_bin
 
 
 #--------------------------------------------------------------------------
@@ -60,7 +63,7 @@ try:
     process = subprocess.Popen(
         [_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE
     )
-except (OSError, IOError, ValueError):
+except (OSError, IOError):
     _logger.info('You need Wkhtmltopdf to print a pdf version of the reports.')
 else:
     _logger.info('Will use the Wkhtmltopdf binary at %s' % _get_wkhtmltopdf_bin())
diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py
index c3f3b8ba3f3e..ca835f33b010 100644
--- a/openerp/tools/misc.py
+++ b/openerp/tools/misc.py
@@ -65,13 +65,12 @@ _logger = logging.getLogger(__name__)
 # We include the *Base ones just in case, currently they seem to be subclasses of the _* ones.
 SKIPPED_ELEMENT_TYPES = (etree._Comment, etree._ProcessingInstruction, etree.CommentBase, etree.PIBase)
 
-DEFAULT_PATH = os.environ.get('PATH', os.defpath).split(os.pathsep)
-if config.get('bin_path'):
-    DEFAULT_PATH.append(config['bin_path'])
-
 def find_in_path(name):
+    path = os.environ.get('PATH', os.defpath).split(os.pathsep)
+    if config.get('bin_path') and config['bin_path'] != 'None':
+        path.append(config['bin_path'])
     try:
-        return which(name, path=os.pathsep.join(DEFAULT_PATH))
+        return which(name, path=os.pathsep.join(path))
     except IOError:
         return None
 
-- 
GitLab