Skip to content

Commit

Permalink
make OpenSCAD utilities working again with Py2
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jun 7, 2019
1 parent dbb4cc6 commit a261a55
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/Mod/OpenSCAD/OpenSCADUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def translate(context, text):
return QtGui.QApplication.translate(context, text, None)

import io
import sys
PY2 = sys.version_info.major == 2

try:
import FreeCAD
Expand Down Expand Up @@ -144,18 +146,23 @@ def callopenscad(inputfilename,outputfilename=None,outputext='csg',keepname=Fals
import FreeCAD,os,subprocess,tempfile,time
def check_output2(*args,**kwargs):
kwargs.update({'stdout':subprocess.PIPE,'stderr':subprocess.PIPE})
p=subprocess.Popen(*args,**kwargs)
if PY2:
p=subprocess.Popen(*args)
else:
p=subprocess.Popen(*args,**kwargs)
stdoutd,stderrd = p.communicate()
stdoutd = stdoutd.decode("utf8")
stderrd = stderrd.decode("utf8")
if not PY2:
stdoutd = stdoutd.decode("utf8")
stderrd = stderrd.decode("utf8")
if p.returncode != 0:
raise OpenSCADError('%s %s\n' % (stdoutd.strip(),stderrd.strip()))
#raise Exception,'stdout %s\n stderr%s' %(stdoutd,stderrd)
if stderrd.strip():
FreeCAD.Console.PrintWarning(stderrd+u'\n')
if stdoutd.strip():
FreeCAD.Console.PrintMessage(stdoutd+u'\n')
return stdoutd
if not PY2:
if stderrd.strip():
FreeCAD.Console.PrintWarning(stderrd+u'\n')
if stdoutd.strip():
FreeCAD.Console.PrintMessage(stdoutd+u'\n')
return stdoutd

osfilename = FreeCAD.ParamGet(\
"User parameter:BaseApp/Preferences/Mod/OpenSCAD").\
Expand All @@ -182,7 +189,10 @@ def callopenscadstring(scadstr,outputext='csg'):
dir1=tempfile.gettempdir()
inputfilename=os.path.join(dir1,'%s.scad' % next(tempfilenamegen))
inputfile = io.open(inputfilename,'w', encoding="utf8")
inputfile.write(scadstr)
if PY2:
inputfile.write(scadstr.decode('utf8'))
else:
inputfile.write(scadstr)
inputfile.close()
outputfilename = callopenscad(inputfilename,outputext=outputext,\
keepname=True)
Expand Down

0 comments on commit a261a55

Please sign in to comment.