From 53c8c12298a0fd213c8108415e2088ea7abea50a Mon Sep 17 00:00:00 2001 From: Raimon Esteve Date: Thu, 16 Jan 2020 15:43:23 +0100 Subject: [PATCH] issue5907.diff # [trytond] Remove unoconv and call soffice directly --- issue5907.diff | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ series | 2 ++ 2 files changed, 74 insertions(+) create mode 100644 issue5907.diff diff --git a/issue5907.diff b/issue5907.diff new file mode 100644 index 0000000..4d560e0 --- /dev/null +++ b/issue5907.diff @@ -0,0 +1,72 @@ +diff --git a/trytond/trytond/report/report.py b/trytond/trytond/report/report.py +index 4ace05ea..fb93276d 100644 +--- a/trytond/trytond/report/report.py ++++ b/trytond/trytond/report/report.py +@@ -1,6 +1,7 @@ + # This file is part of Tryton. The COPYRIGHT file at the top level of + # this repository contains the full copyright notices and license terms. + import os ++import logging + import datetime + import tempfile + import warnings +@@ -13,13 +14,14 @@ try: + except ImportError: + Manifest, MANIFEST = None, None + from genshi.filters import Translator +-from trytond.config import config + from trytond.pool import Pool, PoolBase + from trytond.transaction import Transaction + from trytond.url import URLMixin + from trytond.rpc import RPC + from trytond.exceptions import UserError + ++logger = logging.getLogger(__name__) ++ + MIMETYPES = { + 'odt': 'application/vnd.oasis.opendocument.text', + 'odp': 'application/vnd.oasis.opendocument.presentation', +@@ -246,21 +248,32 @@ class Report(URLMixin, PoolBase): + if output_format in MIMETYPES: + return output_format, data + +- fd, path = tempfile.mkstemp(suffix=(os.extsep + input_format), +- prefix='trytond_') ++ dtemp = tempfile.mkdtemp(prefix='trytond_') ++ path = os.path.join( ++ dtemp, report.report_name + os.extsep + input_format) + oext = FORMAT2EXT.get(output_format, output_format) +- with os.fdopen(fd, 'wb+') as fp: ++ with open(path, 'wb+') as fp: + fp.write(data) +- cmd = ['unoconv', '--connection=%s' % config.get('report', 'unoconv'), +- '-f', oext, '--stdout', path] + try: +- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE) +- stdoutdata, stderrdata = proc.communicate() +- if proc.wait() != 0: +- raise Exception(stderrdata) +- return oext, stdoutdata ++ cmd = ['soffice', ++ '--headless', '--nolockcheck', '--nodefault', '--norestore', ++ '--convert-to', oext, '--outdir', dtemp, path] ++ output = os.path.splitext(path)[0] + os.extsep + oext ++ subprocess.check_call(cmd) ++ if os.path.exists(output): ++ with open(output, 'rb') as fp: ++ return oext, fp.read() ++ else: ++ logger.error( ++ 'fail to convert %s to %s', report.report_name, oext) ++ return input_format, data + finally: +- os.remove(path) ++ try: ++ os.remove(path) ++ os.remove(output) ++ os.rmdir(dtemp) ++ except OSError: ++ pass + + @classmethod + def format_date(cls, value, lang): diff --git a/series b/series index 897affa..e051e47 100644 --- a/series +++ b/series @@ -83,3 +83,5 @@ issue8058.diff # [stock_supply_production] Can't create productions from request issue8038.diff # [sale_supply_drop_shipment] Crash when process a purchase from purchase request created from a sale change_key_tax.diff # Change the key tax use to not separrete refunds and invoiceds on the same invocie, as in v5.2 do 038993.diff # [sale] Remove permission error when changing a supplier invoice to draft + +issue5907.diff # [trytond] Remove unoconv and call soffice directly