2013-02-11 00:41:49 +00:00
|
|
|
#!/usr/bin/env python
|
2012-04-08 15:00:15 +00:00
|
|
|
|
|
|
|
# the purpose of this script is rewriting the swig_import_helper
|
2022-10-20 15:12:57 +00:00
|
|
|
# call added by Swig version < 4.0 in pcbnew.py so it will not load
|
|
|
|
# _xxxxx.so/dso from inside a kicad executable
|
2012-04-08 15:00:15 +00:00
|
|
|
# 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
|
|
|
|
#
|
2022-10-20 15:12:57 +00:00
|
|
|
# For Swig version >= 4.0 this method does not exist so nothing useful is made
|
2012-04-08 15:00:15 +00:00
|
|
|
|
2018-08-03 11:33:16 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2012-04-08 15:00:15 +00:00
|
|
|
from sys import argv,exit
|
|
|
|
|
2018-08-03 11:33:16 +00:00
|
|
|
|
2012-04-08 15:00:15 +00:00
|
|
|
if len(argv)<2:
|
2018-08-03 11:33:16 +00:00
|
|
|
print("usage:")
|
|
|
|
print(" fix_swig_imports.py file.py")
|
|
|
|
print("")
|
|
|
|
print(" will fix the swig import code for working inside KiCad")
|
2021-06-09 19:32:58 +00:00
|
|
|
print(" where it happened that the external _pcbnew.so/dll was")
|
2018-08-03 11:33:16 +00:00
|
|
|
print(" loaded too -and the internal _pcbnew module was to be used")
|
2012-04-08 15:00:15 +00:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
filename = argv[1]
|
|
|
|
|
|
|
|
f = open(filename,"rb")
|
|
|
|
lines = f.readlines()
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
|
|
|
|
doneOk = False
|
|
|
|
|
2012-10-01 06:04:06 +00:00
|
|
|
if (len(lines)<4000):
|
2018-08-03 11:33:16 +00:00
|
|
|
print("still building")
|
2012-04-09 06:19:57 +00:00
|
|
|
exit(0)
|
|
|
|
|
2018-08-03 11:33:16 +00:00
|
|
|
txt = b""
|
2012-10-01 06:04:06 +00:00
|
|
|
|
2012-04-08 15:00:15 +00:00
|
|
|
for l in lines:
|
2019-05-09 07:53:46 +00:00
|
|
|
if l.startswith(b"if _swig_python_version_info < (2, 7, 0):"): # ok with swig version >= 4.0.0
|
|
|
|
l = l.replace(b"_swig_python_version_info < (2, 7, 0)", b"False")
|
|
|
|
doneOk = True
|
2018-08-03 11:33:16 +00:00
|
|
|
if l.startswith(b"if _swig_python_version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.10
|
|
|
|
l = l.replace(b"_swig_python_version_info >= (2, 7, 0)", b"False")
|
2016-06-20 13:32:59 +00:00
|
|
|
doneOk = True
|
2018-08-03 11:33:16 +00:00
|
|
|
elif l.startswith(b"elif _swig_python_version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.10
|
|
|
|
l = l.replace(b"_swig_python_version_info >= (2, 6, 0)", b"False")
|
2016-06-20 13:32:59 +00:00
|
|
|
doneOk = True
|
2018-08-03 11:33:16 +00:00
|
|
|
if l.startswith(b"if version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.9
|
|
|
|
l = l.replace(b"version_info >= (2, 7, 0)", b"False")
|
2016-06-13 17:50:29 +00:00
|
|
|
doneOk = True
|
2018-08-03 11:33:16 +00:00
|
|
|
elif l.startswith(b"elif version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.9
|
|
|
|
l = l.replace(b"version_info >= (2, 6, 0)", b"False")
|
2016-06-13 17:50:29 +00:00
|
|
|
doneOk = True
|
2018-08-03 11:33:16 +00:00
|
|
|
elif l.startswith(b"if version_info >= (2,6,0):"): # ok with swig version <= 3.0.2
|
|
|
|
l = l.replace(b"version_info >= (2,6,0)", b"False")
|
2012-04-08 15:00:15 +00:00
|
|
|
doneOk = True
|
2018-08-03 11:33:16 +00:00
|
|
|
elif l.startswith(b"if version_info >= (2, 6, 0):"): # needed with swig version 3.0.3
|
|
|
|
l = l.replace(b"version_info >= (2, 6, 0)", b"False")
|
2015-01-04 07:19:04 +00:00
|
|
|
doneOk = True
|
2018-08-03 11:33:16 +00:00
|
|
|
elif l.startswith(b"if False:"): # it was already patched?
|
2012-04-08 15:00:15 +00:00
|
|
|
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:
|
2018-08-03 11:33:16 +00:00
|
|
|
print("swig_import_helper fixed for", filename)
|
2012-04-08 15:00:15 +00:00
|
|
|
else:
|
2018-08-03 11:33:16 +00:00
|
|
|
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-10-01 06:04:06 +00:00
|
|
|
|
2012-04-08 15:00:15 +00:00
|
|
|
exit(0)
|
2012-10-01 06:04:06 +00:00
|
|
|
|
|
|
|
|
2012-04-08 15:00:15 +00:00
|
|
|
|