This is a very simplistic script, but I was getting tired of renaming the wx
and wxPython directories in order to test something with 2.4.x, then 2.5.x
and then switching back to 2.4.x... This could be pretty easily extended to
support any number of versions of wxPython in the site-packages or
PYTHONPATH directory by changing how the current version is identified, but
additional input args would have to be provided to indicate which version
you want to switch to. You should obviously change the strings in the
versions list below to match the suffixes you like to use to identify each
version. I was tempted to just use the version string from wx.VERSION_STRING
for the suffixes, but I'll leave that as an exercise for the reader.
I used wx.__file__ rather than hard-coding the path so the script would work
regardless of platform or whether you were using a PYTHONPATH or
site-packages for the various versions of wxPython.
Use at your own risk
ka
···
---
import os
import wx
basepath = os.path.split(os.path.split(wx.__file__)[0])[0]
dirs = ['wx', 'wxPython']
versions = ['24', '25']
# it is assumed that there will be active wxPython
# packages named wx and wxPython
# as well as a non-active distribution with
# one of the versions strings above
# otherwise the script does nothing
for name in dirs:
path = os.path.join(basepath, name)
if not os.path.exists(path):
print path, "missing - aborting..."
sys.exit()
# now see whether 2.4.x or 2.5.x is active
path = os.path.join(basepath, dirs[0] + versions[0])
if os.path.exists(path):
current = versions[1]
backup = versions[0]
else:
current = versions[0]
backup = versions[1]
#print "current", current
#print "backup", backup
for name in dirs:
path = os.path.join(basepath, name)
backupcurrent = os.path.join(basepath, name + current)
switchpath = os.path.join(basepath, name + backup)
# backup current
os.rename(path, backupcurrent)
# make other version active
os.rename(switchpath, path)
reload(wx)
print wx.VERSION_STRING, "is now active"