[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)
This commit is contained in:
@@ -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')
|
||||
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user