diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-06-05 11:28:48 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-06-05 11:28:48 +0200 |
commit | aa6697f9d669c821896c26bc8597ed68c79619c5 (patch) | |
tree | c797f709b6fa291e455341ea75ab6b8c163cb4d1 /src/ee/tools | |
parent | 50e1475eb6e1200365e0fca40ba73847ad70e440 (diff) | |
download | ee-python-aa6697f9d669c821896c26bc8597ed68c79619c5.tar.gz ee-python-aa6697f9d669c821896c26bc8597ed68c79619c5.tar.bz2 ee-python-aa6697f9d669c821896c26bc8597ed68c79619c5.tar.xz ee-python-aa6697f9d669c821896c26bc8597ed68c79619c5.zip |
o Better detection of old/new python support for KiCAD.
Diffstat (limited to 'src/ee/tools')
-rwxr-xr-x | src/ee/tools/kicad_gerber.py | 40 |
1 files changed, 27 insertions, 13 deletions
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) |