Skip to content
This repository was archived by the owner on Jun 26, 2018. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions anytree/exporter/dotexporter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import codecs
from os import path
from os import path, unlink
from subprocess import check_call
from tempfile import NamedTemporaryFile
from sys import platform

from anytree import PreOrderIter

Expand Down Expand Up @@ -221,9 +222,17 @@ def to_picture(self, filename):
*`graphviz` needs to be installed, before usage of this method.*
"""
fileformat = path.splitext(filename)[1][1:]
with NamedTemporaryFile("wb") as dotfile:

# on windows/cygwin, NamedTemporaryFile needs the argument delete=False
deleteFile = False if platform == "win32" or platform == "cygwin" else True
with NamedTemporaryFile("wb", delete=deleteFile) as dotfile:
for line in self:
dotfile.write(("%s\n" % line).encode("utf-8"))
dotfile.flush()
cmd = ["dot", dotfile.name, "-T", fileformat, "-o", filename]
cmd = ["dot", dotfile.name, "-T", fileformat, "-o", filename, ]
check_call(cmd)

tempFileName = dotfile.name

# on windows/cygwin, need to unlink the NamedTemporaryFile after use
if path.exists(tempFileName): unlink(tempFileName)