Rewrite some code to work on Python 2.7 and 3+
This commit is contained in:
parent
e1f30a3b38
commit
de7b362695
|
@ -693,7 +693,7 @@ if( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES )
|
||||||
# Get the correct Python site package install path from the Python interpreter found by
|
# Get the correct Python site package install path from the Python interpreter found by
|
||||||
# FindPythonInterp unless the user specifically defined a custom path.
|
# FindPythonInterp unless the user specifically defined a custom path.
|
||||||
if( NOT PYTHON_SITE_PACKAGE_PATH )
|
if( NOT PYTHON_SITE_PACKAGE_PATH )
|
||||||
execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig;print\"%s\"%distutils.sysconfig.get_python_lib(plat_specific=0, standard_lib=0, prefix='')"
|
execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig;print(\"%s\"%distutils.sysconfig.get_python_lib(plat_specific=0, standard_lib=0, prefix=''))"
|
||||||
OUTPUT_VARIABLE PYTHON_SITE_PACKAGE_PATH
|
OUTPUT_VARIABLE PYTHON_SITE_PACKAGE_PATH
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
)
|
)
|
||||||
|
@ -724,7 +724,7 @@ if( KICAD_SCRIPTING OR KICAD_SCRIPTING_MODULES )
|
||||||
# Check to see if the correct version of wxPython is installed based on the version of
|
# Check to see if the correct version of wxPython is installed based on the version of
|
||||||
# wxWidgets found. At least the major an minor version should match.
|
# wxWidgets found. At least the major an minor version should match.
|
||||||
set( _wxpy_version "${wxWidgets_VERSION_MAJOR}.${wxWidgets_VERSION_MINOR}" )
|
set( _wxpy_version "${wxWidgets_VERSION_MAJOR}.${wxWidgets_VERSION_MINOR}" )
|
||||||
set( _py_cmd "import wxversion;print wxversion.checkInstalled('${_wxpy_version}')" )
|
set( _py_cmd "import wxversion;print(wxversion.checkInstalled('${_wxpy_version}'))" )
|
||||||
|
|
||||||
# Add user specified Python site package path.
|
# Add user specified Python site package path.
|
||||||
if( PYTHON_SITE_PACKAGE_PATH )
|
if( PYTHON_SITE_PACKAGE_PATH )
|
||||||
|
|
|
@ -9,15 +9,18 @@
|
||||||
# fix in the swig_import_helper
|
# fix in the swig_import_helper
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
from sys import argv,exit
|
from sys import argv,exit
|
||||||
|
|
||||||
|
|
||||||
if len(argv)<2:
|
if len(argv)<2:
|
||||||
print "usage:"
|
print("usage:")
|
||||||
print " fix_swig_imports.py file.py"
|
print(" fix_swig_imports.py file.py")
|
||||||
print ""
|
print("")
|
||||||
print " will fix the swig import code for working inside KiCad"
|
print(" will fix the swig import code for working inside KiCad")
|
||||||
print " where it happended that the external _pcbnew.so/dll was"
|
print(" where it happended that the external _pcbnew.so/dll was")
|
||||||
print " loaded too -and the internal _pcbnew module was to be used"
|
print(" loaded too -and the internal _pcbnew module was to be used")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,31 +34,31 @@ f.close()
|
||||||
doneOk = False
|
doneOk = False
|
||||||
|
|
||||||
if (len(lines)<4000):
|
if (len(lines)<4000):
|
||||||
print "still building"
|
print("still building")
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
txt = ""
|
txt = b""
|
||||||
|
|
||||||
for l in lines:
|
for l in lines:
|
||||||
if l.startswith("if _swig_python_version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.10
|
if l.startswith(b"if _swig_python_version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.10
|
||||||
l = l.replace("_swig_python_version_info >= (2, 7, 0)","False")
|
l = l.replace(b"_swig_python_version_info >= (2, 7, 0)", b"False")
|
||||||
doneOk = True
|
doneOk = True
|
||||||
elif l.startswith("elif _swig_python_version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.10
|
elif l.startswith(b"elif _swig_python_version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.10
|
||||||
l = l.replace("_swig_python_version_info >= (2, 6, 0)","False")
|
l = l.replace(b"_swig_python_version_info >= (2, 6, 0)", b"False")
|
||||||
doneOk = True
|
doneOk = True
|
||||||
if l.startswith("if version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.9
|
if l.startswith(b"if version_info >= (2, 7, 0):"): # ok with swig version >= 3.0.9
|
||||||
l = l.replace("version_info >= (2, 7, 0)","False")
|
l = l.replace(b"version_info >= (2, 7, 0)", b"False")
|
||||||
doneOk = True
|
doneOk = True
|
||||||
elif l.startswith("elif version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.9
|
elif l.startswith(b"elif version_info >= (2, 6, 0):"): # needed with swig version >= 3.0.9
|
||||||
l = l.replace("version_info >= (2, 6, 0)","False")
|
l = l.replace(b"version_info >= (2, 6, 0)", b"False")
|
||||||
doneOk = True
|
doneOk = True
|
||||||
elif l.startswith("if version_info >= (2,6,0):"): # ok with swig version <= 3.0.2
|
elif l.startswith(b"if version_info >= (2,6,0):"): # ok with swig version <= 3.0.2
|
||||||
l = l.replace("version_info >= (2,6,0)","False")
|
l = l.replace(b"version_info >= (2,6,0)", b"False")
|
||||||
doneOk = True
|
doneOk = True
|
||||||
elif l.startswith("if version_info >= (2, 6, 0):"): # needed with swig version 3.0.3
|
elif l.startswith(b"if version_info >= (2, 6, 0):"): # needed with swig version 3.0.3
|
||||||
l = l.replace("version_info >= (2, 6, 0)","False")
|
l = l.replace(b"version_info >= (2, 6, 0)", b"False")
|
||||||
doneOk = True
|
doneOk = True
|
||||||
elif l.startswith("if False:"): # it was already patched?
|
elif l.startswith(b"if False:"): # it was already patched?
|
||||||
doneOk = True
|
doneOk = True
|
||||||
txt = txt + l
|
txt = txt + l
|
||||||
|
|
||||||
|
@ -64,10 +67,10 @@ f.write(txt)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
if doneOk:
|
if doneOk:
|
||||||
print "swig_import_helper fixed for",filename
|
print("swig_import_helper fixed for", filename)
|
||||||
else:
|
else:
|
||||||
print "Error: the swig import helper was not fixed, check",filename
|
print("Error: the swig import helper was not fixed, check", filename)
|
||||||
print " and fix this script: fix_swig_imports.py"
|
print(" and fix this script: fix_swig_imports.py")
|
||||||
exit(2)
|
exit(2)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue