[IMP] C2C iprovement of webkit in failed reports

bzr revid: fp@tinyerp.com-20120930125637-m1ydhij1aq7ludsv
This commit is contained in:
Fabien Pinckaers 2012-09-30 14:56:37 +02:00
commit 745a8ca4c2
1 changed files with 26 additions and 15 deletions

View File

@ -107,7 +107,7 @@ class WebKitParser(report_sxw):
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,33 @@ class WebKitParser(report_sxw):
file_to_del.append(html_file.name)
command.append(html_file.name)
command.append(out_filename)
stderr_fd, stderr_path = tempfile.mkstemp(text=True)
file_to_del.append(stderr_path)
try:
status = subprocess.call(command, stderr=subprocess.PIPE) # ignore stderr
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 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)
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()
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):