~camptocamp/openobject-addons/7.0-fix-1319095

« back to all changes in this revision

Viewing changes to report_webkit/webkit_report.py

  • Committer: Yannick Vaucher
  • Date: 2014-05-14 11:22:42 UTC
  • Revision ID: yannick.vaucher@camptocamp.com-20140514112242-2bwyz0azivhh93gw
Fix incompatibility with Windows using tempfile.

Show diffs side-by-side

added added

removed removed

Lines of Context:
105
105
        """Call webkit in order to generate pdf"""
106
106
        if not webkit_header:
107
107
            webkit_header = report_xml.webkit_header
108
 
        out_filename = tempfile.NamedTemporaryFile(suffix=".pdf",
109
 
                                                   prefix="webkit.tmp.",
110
 
                                                   delete=False)
111
 
        file_to_del = [out_filename.name]
 
108
        fd, out_filename = tempfile.mkstemp(suffix=".pdf",
 
109
                                            prefix="webkit.tmp.")
 
110
        file_to_del = [out_filename]
112
111
        if comm_path:
113
112
            command = [comm_path]
114
113
        else:
150
149
                html_file.write(self._sanitize_html(html))
151
150
            file_to_del.append(html_file.name)
152
151
            command.append(html_file.name)
153
 
        command.append(out_filename.name)
 
152
        command.append(out_filename)
154
153
        stderr_fd, stderr_path = tempfile.mkstemp(text=True)
155
154
        file_to_del.append(stderr_path)
156
155
        try:
167
166
            if status :
168
167
                raise except_osv(_('Webkit error' ),
169
168
                                 _("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
170
 
            with out_filename as pdf_file:
 
169
            with open(out_filename, 'rb') as pdf_file:
171
170
                pdf = pdf_file.read()
 
171
            os.close(fd)
172
172
        finally:
173
173
            if stderr_fd is not None:
174
174
                os.close(stderr_fd)