Commit 90c6165c authored by Julien Muchembled's avatar Julien Muchembled

Do not use temporary files at all to render DWWorkflow graphes

parent 5abd0ffc
...@@ -75,7 +75,6 @@ from Products.DCWorkflowGraph import DCWorkflowGraph ...@@ -75,7 +75,6 @@ from Products.DCWorkflowGraph import DCWorkflowGraph
DCWorkflowGraph.getObjectTitle = getObjectTitle DCWorkflowGraph.getObjectTitle = getObjectTitle
from Products.DCWorkflowGraph.config import bin_search_path, DOT_EXE from Products.DCWorkflowGraph.config import bin_search_path, DOT_EXE
from tempfile import NamedTemporaryFile
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
import subprocess import subprocess
...@@ -102,37 +101,25 @@ def getGraph(self, wf_id="", format="png", REQUEST=None): ...@@ -102,37 +101,25 @@ def getGraph(self, wf_id="", format="png", REQUEST=None):
except AttributeError: except AttributeError:
# no portal_properties or site_properties, fallback to: # no portal_properties or site_properties, fallback to:
encoding = self.management_page_charset.lower() encoding = self.management_page_charset.lower()
pot = pot.encode(encoding) result = pot.encode(encoding)
result = None
with NamedTemporaryFile(suffix='.dot') as infile:
infile.write(pot)
infile.seek(0)
if REQUEST is None: if REQUEST is None:
REQUEST = self.REQUEST REQUEST = self.REQUEST
response = REQUEST.RESPONSE setHeader = REQUEST.RESPONSE.setHeader
if format != 'dot': if format != 'dot':
with NamedTemporaryFile(suffix='.%s' % format) as outfile: p = subprocess.Popen((DCWorkflowGraph.bin_search(DOT_EXE),
subprocess.call((DCWorkflowGraph.bin_search(DOT_EXE), '-Nfontname=IPAexGothic', '-Nfontsize=10',
'-Nfontname="IPAexGothic"', '-Efontname=IPAexGothic', '-Efontsize=10',
'-Nfontsize=10', '-T%s' % format),
'-Efontname="IPAexGothic"', stdin=subprocess.PIPE, stdout=subprocess.PIPE)
'-Efontsize=10', result = p.communicate(pot)[0]
'-T%s' % format,
'-o', setHeader('Content-Type', 'image/%s' % format)
outfile.name,
infile.name))
result = outfile.read()
response.setHeader('Content-Type', 'image/%s' % format)
else: else:
result = infile.read()
filename = wf_id or self.getId() filename = wf_id or self.getId()
response.setHeader('Content-Type', 'text/x-graphviz') setHeader('Content-Type', 'text/x-graphviz')
response.setHeader('Content-Disposition', setHeader('Content-Disposition', 'attachment; filename=%s.dot' % filename)
'attachment; filename=%s.dot' % filename)
if not result: if not result:
LOG("ERP5Type.patches.DCWorkflowGraph", WARNING, LOG("ERP5Type.patches.DCWorkflowGraph", WARNING,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment