credativ team mailing list archive
-
credativ team
-
Mailing list archive
-
Message #05651
[Branch ~credativ/openobject-addons/6.1] Rev 7055: [MERGE] Merge with report_webkit subprocess exception handling fix.
Merge authors:
Tom Pickering <tpi@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
------------------------------------------------------------
revno: 7055 [merge]
committer: Tom Pickering <tpi@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
branch nick: addons-fixes-6.1
timestamp: Thu 2013-11-21 12:04:40 +0000
message:
[MERGE] Merge with report_webkit subprocess exception handling fix.
modified:
report_webkit/webkit_report.py
--
lp:~credativ/openobject-addons/6.1
https://code.launchpad.net/~credativ/openobject-addons/6.1
Your team credativ is subscribed to branch lp:~credativ/openobject-addons/6.1.
To unsubscribe from this branch go to https://code.launchpad.net/~credativ/openobject-addons/6.1/+edit-subscription
=== modified file 'report_webkit/webkit_report.py'
--- report_webkit/webkit_report.py 2013-06-11 15:12:55 +0000
+++ report_webkit/webkit_report.py 2013-11-21 11:32:58 +0000
@@ -51,7 +51,7 @@
from tools.translate import _
from osv.osv import except_osv
-logger = logging.getLogger('report_webkit')
+_logger = logging.getLogger('report_webkit')
def mako_template(text):
"""Build a Mako template.
@@ -107,7 +107,7 @@
tmp_dir = tempfile.gettempdir()
out_filename = tempfile.mktemp(suffix=".pdf", prefix="webkit.tmp.")
files = []
- file_to_del = []
+ file_to_del = [out_filename]
if comm_path:
command = [comm_path]
else:
@@ -160,22 +160,43 @@
file_to_del.append(html_file.name)
command.append(html_file.name)
command.append(out_filename)
- try:
- status = subprocess.call(command, stderr=subprocess.PIPE) # ignore stderr
- if status :
- raise except_osv(
- _('Webkit raise an error' ),
- status
- )
- except Exception:
- for f_to_del in file_to_del :
- os.unlink(f_to_del)
-
- pdf = file(out_filename, 'rb').read()
- for f_to_del in file_to_del :
- os.unlink(f_to_del)
-
- os.unlink(out_filename)
+ stderr_fd, stderr_path = tempfile.mkstemp(text=True)
+ file_to_del.append(stderr_path)
+ try:
+ status = subprocess.call(command, stderr=stderr_fd)
+ os.close(stderr_fd) # ensure flush before reading
+ stderr_fd = None # avoid closing again in finally block
+ fobj = open(stderr_path, 'r')
+ error_message = fobj.read()
+ fobj.close()
+ if not error_message:
+ error_message = _('No diagnosis message was provided')
+ else:
+ error_message = _('The following diagnosis message was provided:\n') + error_message
+ if status :
+ raise except_osv(_('Webkit error' ),
+ _("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
+ pdf_file = open(out_filename, 'rb')
+ pdf = pdf_file.read()
+ pdf_file.close()
+ except OSError as exc:
+ raise except_osv(_('Conversion to PDF failed at the OS level.'),
+ _('Please ensure both that wkhtmltopdf is installed on your' \
+ ' system (\'sudo apt-get install wkhtmltopdf\' or download from' \
+ ' http://code.google.com/p/wkhtmltopdf/downloads/list) and that the' \
+ ' the ir.config_parameter with the key \'webkit_path\' is set as' \
+ ' the correct path to wkhtmltopdf.' \
+ ' Minimal version is 0.9.9.' \
+ ' Error code ' + str(exc.errno) + ': ' + exc.strerror
+ ))
+ finally:
+ if stderr_fd is not None:
+ os.close(stderr_fd)
+ for f_to_del in file_to_del:
+ try:
+ os.unlink(f_to_del)
+ except (OSError, IOError), exc:
+ _logger.error('cannot remove file %s: %s', f_to_del, exc)
return pdf
def translate_call(self, src):
@@ -253,7 +274,7 @@
htmls.append(html)
except Exception, e:
msg = exceptions.text_error_template().render()
- logger.error(msg)
+ _logger.error(msg)
raise except_osv(_('Webkit render'), msg)
else:
try :
@@ -264,7 +285,7 @@
htmls.append(html)
except Exception, e:
msg = exceptions.text_error_template().render()
- logger.error(msg)
+ _logger.error(msg)
raise except_osv(_('Webkit render'), msg)
head_mako_tpl = mako_template(header)
try :
@@ -286,7 +307,7 @@
**self.parser_instance.localcontext)
except:
msg = exceptions.text_error_template().render()
- logger.error(msg)
+ _logger.error(msg)
raise except_osv(_('Webkit render'), msg)
if report_xml.webkit_debug :
try :
@@ -297,7 +318,7 @@
**self.parser_instance.localcontext)
except Exception, e:
msg = exceptions.text_error_template().render()
- logger.error(msg)
+ _logger.error(msg)
raise except_osv(_('Webkit render'), msg)
return (deb, 'html')
bin = self.get_lib(cursor, uid)