aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)