Skip to content

Commit

Permalink
Fix incompatibility with Windows using tempfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
yvaucher committed May 14, 2014
1 parent 494f168 commit 4ed3434
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions addons/report_webkit/webkit_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,9 @@ def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_
"""Call webkit in order to generate pdf"""
if not webkit_header:
webkit_header = report_xml.webkit_header
out_filename = tempfile.NamedTemporaryFile(suffix=".pdf",
prefix="webkit.tmp.",
delete=False)
file_to_del = [out_filename.name]
fd, out_filename = tempfile.mkstemp(suffix=".pdf",
prefix="webkit.tmp.")
file_to_del = [out_filename]
if comm_path:
command = [comm_path]
else:
Expand Down Expand Up @@ -150,7 +149,7 @@ def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_
html_file.write(self._sanitize_html(html))
file_to_del.append(html_file.name)
command.append(html_file.name)
command.append(out_filename.name)
command.append(out_filename)
stderr_fd, stderr_path = tempfile.mkstemp(text=True)
file_to_del.append(stderr_path)
try:
Expand All @@ -167,8 +166,9 @@ def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_
if status :
raise except_osv(_('Webkit error' ),
_("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
with out_filename as pdf_file:
with open(out_filename, 'rb') as pdf_file:
pdf = pdf_file.read()
os.close(fd)
finally:
if stderr_fd is not None:
os.close(stderr_fd)
Expand Down

0 comments on commit 4ed3434

Please sign in to comment.