You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.4 KiB

14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
14 years ago
  1. #!/usr/bin/env python
  2. # the purpose of this script is rewriting the swig_import_helper
  3. # call so it will not load _xxxxx.so/dso from inside a kicad executable
  4. # because the kicad executable itself sill provide an _xxxxx module
  5. # that's linked inside itself.
  6. #
  7. # for the normal module import it should work the same way with this
  8. # fix in the swig_import_helper
  9. #
  10. from __future__ import print_function
  11. from sys import argv,exit
  12. if len(argv)<2:
  13. print("usage:")
  14. print(" fix_swig_imports.py file.py")
  15. print("")
  16. print(" will fix the swig import code for working inside KiCad")
  17. print(" where it happended that the external _pcbnew.so/dll was")
  18. print(" loaded too -and the internal _pcbnew module was to be used")
  19. exit(1)
  20. filename = argv[1]
  21. f = open(filename,"rb")
  22. lines = f.readlines()
  23. f.close()
  24. doneOk = False
  25. if (len(lines)<4000):
  26. print("still building")
  27. exit(0)
  28. txt = b""
  29. for l in lines:
  30. if l.startswith(b"if _swig_python_version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.10
  31. l = l.replace(b"_swig_python_version_info >= (2, 7, 0)", b"False")
  32. doneOk = True
  33. elif l.startswith(b"elif _swig_python_version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.10
  34. l = l.replace(b"_swig_python_version_info >= (2, 6, 0)", b"False")
  35. doneOk = True
  36. if l.startswith(b"if version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.9
  37. l = l.replace(b"version_info >= (2, 7, 0)", b"False")
  38. doneOk = True
  39. elif l.startswith(b"elif version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.9
  40. l = l.replace(b"version_info >= (2, 6, 0)", b"False")
  41. doneOk = True
  42. elif l.startswith(b"if version_info >= (2,6,0):"): # ok with swig version <= 3.0.2
  43. l = l.replace(b"version_info >= (2,6,0)", b"False")
  44. doneOk = True
  45. elif l.startswith(b"if version_info >= (2, 6, 0):"): # needed with swig version 3.0.3
  46. l = l.replace(b"version_info >= (2, 6, 0)", b"False")
  47. doneOk = True
  48. elif l.startswith(b"if False:"): # it was already patched?
  49. doneOk = True
  50. txt = txt + l
  51. f = open(filename,"wb")
  52. f.write(txt)
  53. f.close()
  54. if doneOk:
  55. print("swig_import_helper fixed for", filename)
  56. else:
  57. print("Error: the swig import helper was not fixed, check", filename)
  58. print(" and fix this script: fix_swig_imports.py")
  59. exit(2)
  60. exit(0)