From 34c15580bfdf37cf1041e0c2cfdd0aff3b0fdbda Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Tue, 13 Jan 2015 11:19:56 +0100 Subject: [PATCH] [FIX] tools: `find_in_path` exceptions shadowing This commit changes the default behavior of `find_in_path`: it doesn't shallow the IOError exceptions anymore. It especially allows the asset bundle mechanism to handle the absence of the binaries used to compile sass/less to css. * ir_qweb: fallback the value of `get_command` to allow QWeb to display a message like "Could not execute command lessc" * ir_qweb: use of `find_in_path` to fetch binaries, allowing to look for binaries in `bin_path` (Windows releases) * fixed call of `find_in_path` by `_check_external_dependencies` in module.py * fixed call of `find_in_path` by report.py (it was manually raising an IOError) --- addons/report/models/report.py | 5 +---- openerp/addons/base/ir/ir_qweb.py | 21 +++++++++++++-------- openerp/addons/base/module/module.py | 4 +++- openerp/tools/misc.py | 5 +---- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/addons/report/models/report.py b/addons/report/models/report.py index 21ea84ab01d..855bc5f56a0 100644 --- a/addons/report/models/report.py +++ b/addons/report/models/report.py @@ -49,10 +49,7 @@ from pyPdf import PdfFileWriter, PdfFileReader _logger = logging.getLogger(__name__) def _get_wkhtmltopdf_bin(): - wkhtmltopdf_bin = find_in_path('wkhtmltopdf') - if wkhtmltopdf_bin is None: - raise IOError - return wkhtmltopdf_bin + return find_in_path('wkhtmltopdf') #-------------------------------------------------------------------------- diff --git a/openerp/addons/base/ir/ir_qweb.py b/openerp/addons/base/ir/ir_qweb.py index dd67c4fe9bf..909f5dc46b4 100644 --- a/openerp/addons/base/ir/ir_qweb.py +++ b/openerp/addons/base/ir/ir_qweb.py @@ -29,7 +29,8 @@ import openerp.tools.lru from openerp.http import request from openerp.tools.safe_eval import safe_eval as eval from openerp.osv import osv, orm, fields -from openerp.tools import html_escape as escape, which +from openerp.tools import html_escape as escape +from openerp.tools.misc import find_in_path from openerp.tools.translate import _ _logger = logging.getLogger(__name__) @@ -1526,18 +1527,22 @@ class SassStylesheetAsset(PreprocessedCSS): return "/*! %s */\n%s" % (self.id, content) def get_command(self): - defpath = os.environ.get('PATH', os.defpath).split(os.pathsep) - sass = which('sass', path=os.pathsep.join(defpath)) + try: + sass = find_in_path('sass') + except IOError: + sass = 'sass' return [sass, '--stdin', '-t', 'compressed', '--unix-newlines', '--compass', '-r', 'bootstrap-sass'] class LessStylesheetAsset(PreprocessedCSS): def get_command(self): - defpath = os.environ.get('PATH', os.defpath).split(os.pathsep) - if os.name == 'nt': - lessc = which('lessc.cmd', path=os.pathsep.join(defpath)) - else: - lessc = which('lessc', path=os.pathsep.join(defpath)) + try: + if os.name == 'nt': + lessc = find_in_path('lessc.cmd') + else: + lessc = find_in_path('lessc') + except IOError: + lessc = 'lessc' webpath = openerp.http.addons_manifest['web']['addons_path'] lesspath = os.path.join(webpath, 'web', 'static', 'lib', 'bootstrap', 'less') return [lessc, '-', '--clean-css', '--no-js', '--no-color', '--include-path=%s' % lesspath] diff --git a/openerp/addons/base/module/module.py b/openerp/addons/base/module/module.py index 132ed25b166..e9b3dd7f925 100644 --- a/openerp/addons/base/module/module.py +++ b/openerp/addons/base/module/module.py @@ -363,7 +363,9 @@ class module(osv.osv): raise ImportError('No module named %s' % (pydep,)) for binary in depends.get('bin', []): - if tools.find_in_path(binary) is None: + try: + tools.find_in_path(binary) + except IOError: raise Exception('Unable to find %r in path' % (binary,)) @classmethod diff --git a/openerp/tools/misc.py b/openerp/tools/misc.py index 3c0d81ba164..743bba5ab52 100644 --- a/openerp/tools/misc.py +++ b/openerp/tools/misc.py @@ -69,10 +69,7 @@ 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(path)) - except IOError: - return None + return which(name, path=os.pathsep.join(path)) def find_pg_tool(name): path = None