fix_swig_imports.py 1.36 KB
Newer Older
1
#!/usr/bin/env python
Miguel Angel Ajo's avatar
Miguel Angel Ajo committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

# 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 "   fixswigimports.py file.py"
    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

33
if (len(lines)<4000):
34 35 36
    print "still building"
    exit(0)

37
txt = ""
38

Miguel Angel Ajo's avatar
Miguel Angel Ajo committed
39 40 41 42 43 44
for l in lines:
    if l.startswith("if version_info >= (2,6,0):"):
        l = l.replace("version_info >= (2,6,0)","False")
        doneOk = True
    elif l.startswith("if False:"):  # it was already patched?
        doneOk = True
45
    txt = txt + l
Miguel Angel Ajo's avatar
Miguel Angel Ajo committed
46

47 48
f = open(filename,"wb")
f.write(txt)
Miguel Angel Ajo's avatar
Miguel Angel Ajo committed
49 50 51 52 53 54 55 56 57
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: fixswigimports.py"
    exit(2)

58

Miguel Angel Ajo's avatar
Miguel Angel Ajo committed
59
exit(0)
60 61


Miguel Angel Ajo's avatar
Miguel Angel Ajo committed
62