Merge lp:~camptocamp/c2c-financial-addons/trunk-fix1003563 into lp:c2c-financial-addons

Proposed by Alexandre Fayolle - camptocamp
Status: Merged
Merged at revision: 30
Proposed branch: lp:~camptocamp/c2c-financial-addons/trunk-fix1003563
Merge into: lp:c2c-financial-addons
Diff against target: 61 lines (+27/-16)
1 file modified
account_financial_report_webkit/report/webkit_parser_header_fix.py (+27/-16)
To merge this branch: bzr merge lp:~camptocamp/c2c-financial-addons/trunk-fix1003563
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp Approve
Nicolas Bessi - Camptocamp Pending
Review via email: mp+116489@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Approved as well as the 6.1 version

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_financial_report_webkit/report/webkit_parser_header_fix.py'
2--- account_financial_report_webkit/report/webkit_parser_header_fix.py 2012-03-30 12:55:19 +0000
3+++ account_financial_report_webkit/report/webkit_parser_header_fix.py 2012-07-24 14:39:18 +0000
4@@ -80,7 +80,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@@ -116,22 +116,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- if status :
22- raise except_osv(
23- _('Webkit raise an error' ),
24- status
25- )
26- except Exception:
27- for f_to_del in file_to_del :
28- os.unlink(f_to_del)
29-
30- pdf = file(out_filename, 'rb').read()
31- for f_to_del in file_to_del :
32- os.unlink(f_to_del)
33-
34- os.unlink(out_filename)
35+ status = subprocess.call(command, stderr=stderr_fd)
36+ os.close(stderr_fd) # force flush
37+ stderr_fd = None # avoid closing again in finally
38+ fobj = open(stderr_path, 'r')
39+ error_message = fobj.read()
40+ fobj.close()
41+ if not error_message:
42+ error_message = _('No diagnosis message was provided')
43+ else:
44+ error_message = _('The following diagnosis message was provided:\n') + error_message
45+ if status:
46+ raise except_osv(_('Webkit error' ),
47+ _("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
48+ pdf_file = open(out_filename, 'rb')
49+ pdf = pdf_file.read()
50+ pdf_file.close()
51+ finally:
52+ if stderr_fd is not None:
53+ os.close(stderr_fd)
54+ for f_to_del in file_to_del:
55+ try:
56+ os.unlink(f_to_del)
57+ except (OSError, IOError), exc:
58+ _logger.error('cannot remove file %s: %s', f_to_del, exc)
59 return pdf
60
61 # override needed to keep the attachments' storing procedure

Subscribers

People subscribed via source and target branches

to all changes: