aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-06-05 11:28:48 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2019-06-05 11:28:48 +0200
commitaa6697f9d669c821896c26bc8597ed68c79619c5 (patch)
treec797f709b6fa291e455341ea75ab6b8c163cb4d1
parent50e1475eb6e1200365e0fca40ba73847ad70e440 (diff)
downloadee-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.
-rwxr-xr-xsrc/ee/tools/kicad_gerber.py40
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)