Merge lp:~camptocamp/openobject-addons/trunk-fix1003819 into lp:openobject-addons/6.1

Proposed by Alexandre Fayolle - camptocamp on 2012-07-24
Status: Needs review
Proposed branch: lp:~camptocamp/openobject-addons/trunk-fix1003819
Merge into: lp:openobject-addons/6.1
Diff against target: 60 lines (+26/-15)
1 file modified
report_webkit/webkit_report.py (+26/-15)
To merge this branch: bzr merge lp:~camptocamp/openobject-addons/trunk-fix1003819
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) code review only 2012-07-24 Approve on 2014-05-01
Guewen Baconnier @ Camptocamp (community) 2012-07-24 Approve on 2012-07-24
OpenERP Core Team 2012-07-24 Pending
Review via email: mp+116470@code.launchpad.net

Description of the change

To post a comment you must log in.

We must merge your changeset :-)

review: Approve
6915. By Alexandre Fayolle @ camptocamp <email address hidden> on 2012-07-24

[FIX] report_webkit: ensure the temp file fd is always closed

I added related merge requests on the trunk/7.0 branch and on the 6.0 branch

LGTM

review: Approve (code review only)

Unmerged revisions

6915. By Alexandre Fayolle @ camptocamp <email address hidden> on 2012-07-24

[FIX] report_webkit: ensure the temp file fd is always closed

6914. By Alexandre Fayolle @ camptocamp <email address hidden> on 2012-07-24

[FIX] fix issue lp:1003819

* process the information that wkhtmltopdf can write on stderr
* cleanup the code handling file deletion to remove duplication
* provide information to the user about what went wrong

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'report_webkit/webkit_report.py'
2--- report_webkit/webkit_report.py 2012-02-16 10:58:58 +0000
3+++ report_webkit/webkit_report.py 2012-07-24 13:36:21 +0000
4@@ -107,7 +107,7 @@
5 tmp_dir = tempfile.gettempdir()
6 out_filename = tempfile.mktemp(suffix=".pdf", prefix="webkit.tmp.")
7 files = []
8- file_to_del = []
9+ file_to_del = [out_filename]
10 if comm_path:
11 command = [comm_path]
12 else:
13@@ -160,22 +160,33 @@
14 file_to_del.append(html_file.name)
15 command.append(html_file.name)
16 command.append(out_filename)
17+ stderr_fd, stderr_path = tempfile.mkstemp(text=True)
18+ file_to_del.append(stderr_path)
19 try:
20- status = subprocess.call(command, stderr=subprocess.PIPE) # ignore stderr
21+ status = subprocess.call(command, stderr=stderr_fd)
22+ os.close(stderr_fd) # ensure flush before reading
23+ stderr_fd = None # avoid closing again in finally block
24+ fobj = open(stderr_path, 'r')
25+ error_message = fobj.read()
26+ fobj.close()
27+ if not error_message:
28+ error_message = _('No diagnosis message was provided')
29+ else:
30+ error_message = _('The following diagnosis message was provided:\n') + error_message
31 if status :
32- raise except_osv(
33- _('Webkit raise an error' ),
34- status
35- )
36- except Exception:
37- for f_to_del in file_to_del :
38- os.unlink(f_to_del)
39-
40- pdf = file(out_filename, 'rb').read()
41- for f_to_del in file_to_del :
42- os.unlink(f_to_del)
43-
44- os.unlink(out_filename)
45+ raise except_osv(_('Webkit error' ),
46+ _("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
47+ pdf_file = open(out_filename, 'rb')
48+ pdf = pdf_file.read()
49+ pdf_file.close()
50+ finally:
51+ if stderr_fd is not None:
52+ os.close(stderr_fd)
53+ for f_to_del in file_to_del:
54+ try:
55+ os.unlink(f_to_del)
56+ except (OSError, IOError), exc:
57+ logger.error('cannot remove file %s: %s', f_to_del, exc)
58 return pdf
59
60 def translate_call(self, src):