diff options
| author | Stephane Wirtel <stw@openerp.com> | 2012-02-10 17:09:29 +0100 |
|---|---|---|
| committer | Stephane Wirtel <stw@openerp.com> | 2012-02-10 17:09:29 +0100 |
| commit | 7500c3976c7d3ed080243ff8b80e7eafbce8ae41 (patch) | |
| tree | 15e87e580355b3ab22f8cca745698ebc623980d1 | |
| parent | ba850c1d1b7b152762d1f83d9acf0704c6e1d55d (diff) | |
[FIX] report_webkit: Integration of WebkitHtmlToPdf
The system will read the default path from the webkit_path defined into the ir.config_parameter.
If there is no value, the system will use the PATH.
bzr revid: stw@openerp.com-20120210160929-thor1qik8i3ybnn2
| -rw-r--r-- | addons/report_webkit/company.py | 6 | ||||
| -rw-r--r-- | addons/report_webkit/company_view.xml | 1 | ||||
| -rw-r--r-- | addons/report_webkit/webkit_report.py | 59 |
3 files changed, 29 insertions, 37 deletions
diff --git a/addons/report_webkit/company.py b/addons/report_webkit/company.py index eaf3c02b50f..8be9b4005dd 100644 --- a/addons/report_webkit/company.py +++ b/addons/report_webkit/company.py @@ -50,12 +50,6 @@ class ResCompany(osv.osv): 'html_id', 'Available html', ), - 'lib_path' : fields.char('Webkit Executable Path', size=264, - help="Full path to the wkhtmltopdf executable file. " - "Version 0.9.9 is required. Install a static version " - "of the library if you experience missing header/footers " - "on Linux."), - } ResCompany() diff --git a/addons/report_webkit/company_view.xml b/addons/report_webkit/company_view.xml index 04c21037e8e..bf4c13db5d3 100644 --- a/addons/report_webkit/company_view.xml +++ b/addons/report_webkit/company_view.xml @@ -8,7 +8,6 @@ <field name="arch" type="xml"> <notebook position="inside"> <page string="Webkit"> - <field name="lib_path" colspan="4"/> <separator string="Images" colspan="4"/> <field name="header_image" colspan="4" nolabel="1"/> <separator string="Headers" colspan="4"/> diff --git a/addons/report_webkit/webkit_report.py b/addons/report_webkit/webkit_report.py index d3057e5a1ee..90a35db10dd 100644 --- a/addons/report_webkit/webkit_report.py +++ b/addons/report_webkit/webkit_report.py @@ -36,6 +36,7 @@ import report import tempfile import time import logging +import sys from mako.template import Template from mako.lookup import TemplateLookup @@ -71,35 +72,33 @@ class WebKitParser(report_sxw): report_sxw.__init__(self, name, table, rml, parser, header, store) - def get_lib(self, cursor, uid, company) : + def get_lib(self, cursor, uid): """Return the lib wkhtml path""" - #TODO Detect lib in system first - path = self.pool.get('res.company').read(cursor, uid, company, ['lib_path',]) - path = path['lib_path'] - if not path: - raise except_osv( - _('Wkhtmltopdf library path is not set in company'), - _('Please install executable on your system'+ - ' (sudo apt-get install wkhtmltopdf) or download it from here:'+ - ' http://code.google.com/p/wkhtmltopdf/downloads/list and set the'+ - ' path to the executable on the Company form.'+ - 'Minimal version is 0.9.9') - ) - if os.path.isabs(path) : - if (os.path.exists(path) and os.access(path, os.X_OK)\ - and os.path.basename(path).startswith('wkhtmltopdf')): - return path - else: - raise except_osv( - _('Wrong Wkhtmltopdf path set in company'+ - 'Given path is not executable or path is wrong'), - 'for path %s'%(path) - ) - else : - raise except_osv( - _('path to Wkhtmltopdf is not absolute'), - 'for path %s'%(path) - ) + + proxy = self.pool.get('ir.config_parameter') + webkit_path = proxy.get_param(cursor, uid, 'webkit_path') + + if not webkit_path: + try: + defpath = os.environ.get('PATH', os.defpath).split(os.pathsep) + if hasattr(sys, 'frozen'): + defpath.append(os.getcwd()) + webkit_path = tools.which('wkhtmltopdf', path=os.path.join(defpath)) + except IOError: + webkit_path = None + + if webkit_path: + return webkit_path + + raise except_osv( + _('Wkhtmltopdf library path is not set'), + _('Please install executable on your system' \ + ' (sudo apt-get install wkhtmltopdf) or download it from here:' \ + ' http://code.google.com/p/wkhtmltopdf/downloads/list and set the' \ + ' path in the ir.config_parameter with the webkit_path key.' \ + 'Minimal version is 0.9.9') + ) + def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_header=False): """Call webkit in order to generate pdf""" if not webkit_header: @@ -295,8 +294,8 @@ class WebKitParser(report_sxw): logger.error(msg) raise except_osv(_('Webkit render'), msg) return (deb, 'html') - bin = self.get_lib(cursor, uid, company.id) - pdf = self.generate_pdf(bin, report_xml, head, foot, htmls) + webkit_bin = self.get_lib(cursor, uid) + pdf = self.generate_pdf(webkit_bin, report_xml, head, foot, htmls) return (pdf, 'pdf') |
