kicad/scripting/build_tools/fix_swig_imports.py

66 lines
1.6 KiB
Python
Raw Normal View History

#!/usr/bin/env python
2012-04-08 15:00:15 +00:00
# the purpose of this script is rewriting the swig_import_helper
# call so it will not load _xxxxx.so/dso from inside a kicad executable
# because the kicad executable itself sill provide an _xxxxx module
# that's linked inside itself.
#
# for the normal module import it should work the same way with this
# fix in the swig_import_helper
#
from sys import argv,exit
if len(argv)<2:
print "usage:"
print " fix_swig_imports.py file.py"
2012-04-08 15:00:15 +00:00
print ""
print " will fix the swig import code for working inside KiCad"
print " where it happended that the external _pcbnew.so/dll was"
print " loaded too -and the internal _pcbnew module was to be used"
exit(1)
filename = argv[1]
f = open(filename,"rb")
lines = f.readlines()
f.close()
doneOk = False
if (len(lines)<4000):
print "still building"
exit(0)
2012-07-06 19:10:55 +00:00
txt = ""
2012-04-08 15:00:15 +00:00
for l in lines:
2015-01-04 07:19:04 +00:00
if l.startswith("if version_info >= (2,6,0):"): # ok with swig version <= 3.0.2
2012-04-08 15:00:15 +00:00
l = l.replace("version_info >= (2,6,0)","False")
doneOk = True
2015-01-04 07:19:04 +00:00
elif l.startswith("if version_info >= (2, 6, 0):"): # needed with swig version 3.0.3
l = l.replace("version_info >= (2, 6, 0)","False")
doneOk = True
2012-04-08 15:00:15 +00:00
elif l.startswith("if False:"): # it was already patched?
doneOk = True
2012-07-06 19:10:55 +00:00
txt = txt + l
2012-04-08 15:00:15 +00:00
2012-07-06 19:10:55 +00:00
f = open(filename,"wb")
f.write(txt)
2012-04-08 15:00:15 +00:00
f.close()
if doneOk:
print "swig_import_helper fixed for",filename
else:
print "Error: the swig import helper was not fixed, check",filename
print " and fix this script: fix_swig_imports.py"
2012-04-08 15:00:15 +00:00
exit(2)
2012-04-08 15:00:15 +00:00
exit(0)
2012-04-08 15:00:15 +00:00