[ADD] tools: handling of bin_path key in find_in_path
authorSimon Lejeune <sle@openerp.com>
Fri, 21 Nov 2014 16:38:50 +0000 (17:38 +0100)
committerSimon Lejeune <sle@openerp.com>
Fri, 21 Nov 2014 17:08:12 +0000 (18:08 +0100)
The openerp-server.conf now generates the bin_path record, in order
to resolve calls to external binaries served in the thirdparty dir.

Adpated report.py to use find_in_path and not directly which.

addons/report/models/report.py
openerp/tools/misc.py
setup/win32/setup.nsi

index 55edb06..0233af6 100644 (file)
@@ -23,7 +23,8 @@ from openerp import api
 from openerp import SUPERUSER_ID
 from openerp.exceptions import AccessError
 from openerp.osv import osv
-from openerp.tools import config, which
+from openerp.tools import config
+from openerp.tools.misc import find_in_path
 from openerp.tools.translate import _
 from openerp.addons.web.http import request
 from openerp.tools.safe_eval import safe_eval as eval
@@ -48,8 +49,7 @@ from pyPdf import PdfFileWriter, PdfFileReader
 _logger = logging.getLogger(__name__)
 
 def _get_wkhtmltopdf_bin():
-    defpath = os.environ.get('PATH', os.defpath).split(os.pathsep)
-    return which('wkhtmltopdf', path=os.pathsep.join(defpath))
+    return find_in_path('wkhtmltopdf')
 
 
 #--------------------------------------------------------------------------
@@ -60,7 +60,7 @@ try:
     process = subprocess.Popen(
         [_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE
     )
-except (OSError, IOError):
+except (OSError, IOError, ValueError):
     _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 1f90207..c3f3b8b 100644 (file)
@@ -65,9 +65,13 @@ _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):
     try:
-        return which(name)
+        return which(name, path=os.pathsep.join(DEFAULT_PATH))
     except IOError:
         return None
 
index 73def65..992f921 100755 (executable)
@@ -249,6 +249,7 @@ Section $(TITLE_OpenERP_Server) SectionOpenERP_Server
     WriteIniStr "$INSTDIR\server\openerp-server.conf" "options" "db_port" $TextPostgreSQLPort\r
     # Fix the addons path\r
     WriteIniStr "$INSTDIR\server\openerp-server.conf" "options" "addons_path" "$INSTDIR\server\openerp\addons"\r
+    WriteIniStr "$INSTDIR\server\openerp-server.conf" "options" "bin_path" "$INSTDIR\thirdparty"\r
 \r
     # if we're going to install postgresql force it's path,\r
     # otherwise we consider it's always done and/or correctly tune by users\r