From aa6697f9d669c821896c26bc8597ed68c79619c5 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 5 Jun 2019 11:28:48 +0200 Subject: o Better detection of old/new python support for KiCAD. --- src/ee/tools/kicad_gerber.py | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'src/ee') diff --git a/src/ee/tools/kicad_gerber.py b/src/ee/tools/kicad_gerber.py index 0389509..d9b0dc1 100755 --- a/src/ee/tools/kicad_gerber.py +++ b/src/ee/tools/kicad_gerber.py @@ -6,24 +6,38 @@ import sys try: from pcbnew import * -except ImportError: - +except ImportError as e: ee_hack = os.environ.get("EE_HACK", "0") print("ee_hack={}".format(ee_hack), file=sys.stderr) - try_p2 = sys.version_info.major == 2 and ee_hack != "1" + try_p2 = ee_hack == "0" + try_system = ee_hack == "1" print("Could not import 'pcbnew' module. Make sure you run this command with KiCAD's python.", file=sys.stderr) - argv = sys.argv[1:] - cmd = "python2 {} {}".format(__file__, " ".join(argv)) - print(cmd, file=sys.stderr) - - import subprocess + ret = 1 + try: + import subprocess + + if try_p2: + argv = sys.argv[1:] + # Try running explicitly with Python 2 + cmd = "/usr/bin/python2 {} {}".format(__file__, " ".join(argv)) + env = dict(os.environ) + env["EE_HACK"] = "1" + print(cmd, file=sys.stderr) + ret = subprocess.call(cmd, shell=True, env=env) + print("ret={}".format(ret), file=sys.stderr) + elif try_system: + argv = sys.argv[1:] + # Try with the OS's main python, hopefully the KiCAD packages support that + cmd = "/usr/bin/python3 {} {}".format(__file__, " ".join(argv)) + env = dict(os.environ) + env["EE_HACK"] = "2" + print(cmd, file=sys.stderr) + ret = subprocess.call(cmd, shell=True, env=env) + print("ret={}".format(ret), file=sys.stderr) + finally: + pass - subprocess.call("sleep 1", shell=True) - env = dict(os.environ) - env["EE_HACK"] = "1" - ret = subprocess.call(cmd, shell=True, env=env) - print("ret={}".format(ret), file=sys.stderr) sys.exit(ret) -- cgit v1.2.3