From 93a9ce630f11bcb6fa300ee85f7932c39135c858 Mon Sep 17 00:00:00 2001 From: grisel-davy Date: Mon, 21 May 2018 22:05:31 +0200 Subject: [PATCH] Fichier dot temporaire --- topologie/views.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/topologie/views.py b/topologie/views.py index b66c8243..652ef475 100644 --- a/topologie/views.py +++ b/topologie/views.py @@ -48,7 +48,7 @@ from django.template import Context, Template, loader from django.db.models.signals import post_save from django.dispatch import receiver -import pprint +import tempfile from users.views import form from re2o.utils import re2o_paginator, SortTable @@ -1037,11 +1037,12 @@ def make_machine_graph(): dot_data=generate_dot(dico,'topologie/graph_switch.dot') # generate the dot file - fichier = open(MEDIA_ROOT + "/images/switchs.dot","w", encoding='utf-8') - fichier.write(dot_data) - fichier.close() + + f = tempfile.NamedTemporaryFile(mode='w+', encoding='utf-8', delete=False) # Create a temporary file to store the dot data + with f: + f.write(dot_data) unflatten = Popen( # unflatten the graph to make it look better - ["unflatten","-l", "3", MEDIA_ROOT + "/images/switchs.dot"], + ["unflatten","-l", "3", f.name], stdout=PIPE ) image = Popen( # pipe the result of the first command into the second