[FIX] tools: find_in_path: config is not ready at import time
authorSimon Lejeune <sle@openerp.com>
Sun, 23 Nov 2014 14:01:52 +0000 (15:01 +0100)
committerSimon Lejeune <sle@openerp.com>
Sun, 23 Nov 2014 14:22:02 +0000 (15:22 +0100)
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
openerp/tools/misc.py

index 0233af6..057d356 100644 (file)
@@ -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())
index c3f3b8b..ca835f3 100644 (file)
@@ -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