diff --git a/product/ERP5Type/patches/DCWorkflowGraph.py b/product/ERP5Type/patches/DCWorkflowGraph.py index 912936d54b956dabeeb5b821ca9f7d901ede8e5c..22bebeca9c8ff99ece24274a833c8451ae9f7062 100644 --- a/product/ERP5Type/patches/DCWorkflowGraph.py +++ b/product/ERP5Type/patches/DCWorkflowGraph.py @@ -75,7 +75,6 @@ from Products.DCWorkflowGraph import DCWorkflowGraph DCWorkflowGraph.getObjectTitle = getObjectTitle from Products.DCWorkflowGraph.config import bin_search_path, DOT_EXE -from tempfile import NamedTemporaryFile from zLOG import LOG, WARNING import subprocess @@ -102,37 +101,25 @@ def getGraph(self, wf_id="", format="png", REQUEST=None): except AttributeError: # no portal_properties or site_properties, fallback to: encoding = self.management_page_charset.lower() - pot = pot.encode(encoding) - result = None - with NamedTemporaryFile(suffix='.dot') as infile: - infile.write(pot) - infile.seek(0) - - if REQUEST is None: - REQUEST = self.REQUEST - response = REQUEST.RESPONSE - - if format != 'dot': - with NamedTemporaryFile(suffix='.%s' % format) as outfile: - subprocess.call((DCWorkflowGraph.bin_search(DOT_EXE), - '-Nfontname="IPAexGothic"', - '-Nfontsize=10', - '-Efontname="IPAexGothic"', - '-Efontsize=10', - '-T%s' % format, - '-o', - outfile.name, - infile.name)) - - result = outfile.read() - - response.setHeader('Content-Type', 'image/%s' % format) - else: - result = infile.read() - filename = wf_id or self.getId() - response.setHeader('Content-Type', 'text/x-graphviz') - response.setHeader('Content-Disposition', - 'attachment; filename=%s.dot' % filename) + result = pot.encode(encoding) + + if REQUEST is None: + REQUEST = self.REQUEST + setHeader = REQUEST.RESPONSE.setHeader + + if format != 'dot': + p = subprocess.Popen((DCWorkflowGraph.bin_search(DOT_EXE), + '-Nfontname=IPAexGothic', '-Nfontsize=10', + '-Efontname=IPAexGothic', '-Efontsize=10', + '-T%s' % format), + stdin=subprocess.PIPE, stdout=subprocess.PIPE) + result = p.communicate(pot)[0] + + setHeader('Content-Type', 'image/%s' % format) + else: + filename = wf_id or self.getId() + setHeader('Content-Type', 'text/x-graphviz') + setHeader('Content-Disposition', 'attachment; filename=%s.dot' % filename) if not result: LOG("ERP5Type.patches.DCWorkflowGraph", WARNING,