~cristian-rocha/openerp-report-latex/trunk

« back to all changes in this revision

Viewing changes to addons/report_latex/latex_report.py

  • Committer: Cristian Sebastian Rocha
  • Date: 2014-06-09 13:24:22 UTC
  • Revision ID: crocha@kekkaishi.jjdiazarana.net-20140609132422-kuff00is6ec5jw5n
[FIX] If error dont remove temporal directory

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
        _logger.debug("Environment Variables: %s" % env)
139
139
 
140
140
        stderr_fd, stderr_path = tempfile.mkstemp(dir=tmp_dir,text=True)
 
141
        _errors = True
141
142
        try:
142
143
            rerun = True
143
144
            countrerun = 1
161
162
            pdf_file = open(os.path.join(tmp_dir, pdf_filename), 'rb')
162
163
            pdf = pdf_file.read()
163
164
            pdf_file.close()
 
165
            _errors = False
164
166
        except:
165
167
            raise osv.except_osv(_('Latex error'),
166
168
                  _("The command 'pdflatex' failed with error. Read logs."))
167
169
        finally:
168
170
            if stderr_fd is not None:
169
171
                os.close(stderr_fd)
170
 
            try:
171
 
                _logger.debug('Removing temporal directory: %s', tmp_dir)
172
 
                shutil.rmtree(tmp_dir)
173
 
            except (OSError, IOError), exc:
174
 
                _logger.error('Cannot remove dir %s: %s', tmp_dir, exc)
 
172
            if not _errors:
 
173
                try:
 
174
                    _logger.debug('Removing temporal directory: %s', tmp_dir)
 
175
                    shutil.rmtree(tmp_dir)
 
176
                except (OSError, IOError), exc:
 
177
                    _logger.error('Cannot remove dir %s: %s', tmp_dir, exc)
 
178
            else:
 
179
                pass
175
180
        return pdf
176
181
 
177
182
    def translate_call(self, src):