Some shutil don't have the .which method.

Directly calling subprocess.Popen without checking the presence of the
program is the optimal solution because:
1) Avoids race condition, where the program disappears between the
  check and the Popen call.
2) Popen will raise exception if the program is absent anyway,
  no race condition here.
This commit is contained in:
GUAN Xin
2021-07-19 14:12:03 +08:00
parent 2aeba3674a
commit bab49f88ef

View File

@@ -203,14 +203,15 @@ def convertToDxf(dwgfilename):
"""
import os, tempfile, subprocess, sys
import shutil
if shutil.which("dwg2dxf"):
try:
outdir = tempfile.mkdtemp()
basename = os.path.basename(dwgfilename)
result = outdir + os.sep + os.path.splitext(basename)[0] + ".dxf"
proc = subprocess.Popen(("dwg2dxf", dwgfilename, "-o", result))
proc.communicate()
return result
except:
pass
teigha = getTeighaConverter()
if teigha: