2004-09-29 00:11:17 +00:00
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Name: wxversion
|
|
|
|
# Purpose: Allows a wxPython program to search for alternate
|
|
|
|
# installations of the wxPython packages and modify sys.path
|
|
|
|
# so they will be found when "import wx" is done.
|
|
|
|
#
|
|
|
|
# Author: Robin Dunn
|
|
|
|
#
|
|
|
|
# Created: 24-Sept-2004
|
|
|
|
# RCS-ID: $Id$
|
|
|
|
# Copyright: (c) 2004 by Total Control Software
|
|
|
|
# Licence: wxWindows license
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
"""
|
|
|
|
If you have more than one version of wxPython installed this module
|
|
|
|
allows your application to choose which version of wxPython will be
|
2005-05-17 00:36:18 +00:00
|
|
|
imported when it does 'import wx'. The main function of this module
|
|
|
|
is `select` and you use it like this::
|
2004-09-29 00:11:17 +00:00
|
|
|
|
|
|
|
import wxversion
|
2004-10-24 00:58:11 +00:00
|
|
|
wxversion.select('2.4')
|
|
|
|
import wx
|
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
Or additional build options can also be selected, although they will
|
|
|
|
not be required if they are not installed, like this::
|
2004-10-24 00:58:11 +00:00
|
|
|
|
|
|
|
import wxversion
|
|
|
|
wxversion.select('2.5.3-unicode')
|
2004-09-29 00:11:17 +00:00
|
|
|
import wx
|
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
Or you can require an exact match on the build options like this::
|
|
|
|
|
|
|
|
import wxversion
|
|
|
|
wxversion.select('2.5.3-unicode', optionsRequired=True)
|
|
|
|
import wx
|
|
|
|
|
|
|
|
Finally you can also specify a collection of versions that are allowed
|
|
|
|
by your application, like this::
|
|
|
|
|
|
|
|
import wxversion
|
|
|
|
wxversion.select(['2.5.4', '2.5.5', '2.6'])
|
|
|
|
import wx
|
|
|
|
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
Of course the default wxPython version can also be controlled by
|
|
|
|
setting PYTHONPATH or by editing the wx.pth path configuration file,
|
|
|
|
but using wxversion will allow an application to manage the version
|
|
|
|
selection itself rather than depend on the user to setup the
|
|
|
|
environment correctly.
|
|
|
|
|
|
|
|
It works by searching the sys.path for directories matching wx-* and
|
2004-10-26 21:55:25 +00:00
|
|
|
then comparing them to what was passed to the select function. If a
|
2004-09-29 00:11:17 +00:00
|
|
|
match is found then that path is inserted into sys.path.
|
2004-10-24 00:58:11 +00:00
|
|
|
|
|
|
|
NOTE: If you are making a 'bundle' of your application with a tool
|
|
|
|
like py2exe then you should *not* use the wxversion module since it
|
2004-10-26 21:55:25 +00:00
|
|
|
looks at the filesystem for the directories on sys.path, it will fail
|
|
|
|
in a bundled environment. Instead you should simply ensure that the
|
2004-10-24 00:58:11 +00:00
|
|
|
version of wxPython that you want is found by default on the sys.path
|
|
|
|
when making the bundled version by setting PYTHONPATH. Then that
|
|
|
|
version will be included in your bundle and your app will work as
|
|
|
|
expected. Py2exe and the others usually have a way to tell at runtime
|
|
|
|
if they are running from a bundle or running raw, so you can check
|
|
|
|
that and only use wxversion if needed. For example, for py2exe::
|
|
|
|
|
|
|
|
if not hasattr(sys, 'frozen'):
|
|
|
|
import wxversion
|
|
|
|
wxversion.select('2.5')
|
|
|
|
import wx
|
|
|
|
|
2004-10-25 22:53:36 +00:00
|
|
|
More documentation on wxversion and multi-version installs can be
|
|
|
|
found at: http://wiki.wxpython.org/index.cgi/MultiVersionInstalls
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
"""
|
|
|
|
|
2006-01-20 17:32:43 +00:00
|
|
|
import re, sys, os, glob, fnmatch
|
2004-09-29 00:11:17 +00:00
|
|
|
|
|
|
|
|
2004-10-22 05:53:49 +00:00
|
|
|
_selected = None
|
2004-10-24 00:58:11 +00:00
|
|
|
class VersionError(Exception):
|
2004-10-22 05:53:49 +00:00
|
|
|
pass
|
2004-09-29 00:11:17 +00:00
|
|
|
|
2004-10-24 00:58:11 +00:00
|
|
|
#----------------------------------------------------------------------
|
2004-09-29 00:11:17 +00:00
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
def select(versions, optionsRequired=False):
|
2004-09-29 00:11:17 +00:00
|
|
|
"""
|
2004-10-24 00:58:11 +00:00
|
|
|
Search for a wxPython installation that matches version. If one
|
|
|
|
is found then sys.path is modified so that version will be
|
|
|
|
imported with a 'import wx', otherwise a VersionError exception is
|
|
|
|
raised. This funciton should only be caled once at the begining
|
|
|
|
of the application before wxPython is imported.
|
2004-09-29 00:11:17 +00:00
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
:param versions: Specifies the version to look for, it can
|
|
|
|
either be a string or a list of strings. Each string is
|
|
|
|
compared to the installed wxPythons and the best match is
|
|
|
|
inserted into the sys.path, allowing an 'import wx' to
|
|
|
|
find that version.
|
|
|
|
|
|
|
|
The version string is composed of the dotted version
|
|
|
|
number (at least 2 of the 4 components) optionally
|
|
|
|
followed by hyphen ('-') separated options (wx port,
|
|
|
|
unicode/ansi, flavour, etc.) A match is determined by how
|
|
|
|
much of the installed version matches what is given in the
|
|
|
|
version parameter. If the version number components don't
|
|
|
|
match then the score is zero, otherwise the score is
|
|
|
|
increased for every specified optional component that is
|
|
|
|
specified and that matches.
|
|
|
|
|
|
|
|
Please note, however, that it is possible for a match to
|
|
|
|
be selected that doesn't exactly match the versions
|
|
|
|
requested. The only component that is required to be
|
|
|
|
matched is the version number. If you need to require a
|
|
|
|
match on the other components as well, then please use the
|
|
|
|
optional ``optionsRequired`` parameter described next.
|
|
|
|
|
|
|
|
:param optionsRequired: Allows you to specify that the other
|
|
|
|
components of the version string (such as the port name
|
|
|
|
or character type) are also required to be present for an
|
|
|
|
installed version to be considered a match. Using this
|
|
|
|
parameter allows you to change the selection from a soft,
|
|
|
|
as close as possible match to a hard, exact match.
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
"""
|
|
|
|
if type(versions) == str:
|
|
|
|
versions = [versions]
|
2004-10-22 05:53:49 +00:00
|
|
|
|
|
|
|
global _selected
|
|
|
|
if _selected is not None:
|
|
|
|
# A version was previously selected, ensure that it matches
|
|
|
|
# this new request
|
|
|
|
for ver in versions:
|
2005-05-17 00:36:18 +00:00
|
|
|
if _selected.Score(_wxPackageInfo(ver), optionsRequired) > 0:
|
2004-10-22 05:53:49 +00:00
|
|
|
return
|
|
|
|
# otherwise, raise an exception
|
2004-10-24 00:58:11 +00:00
|
|
|
raise VersionError("A previously selected wx version does not match the new request.")
|
2004-10-22 05:53:49 +00:00
|
|
|
|
2004-10-25 22:53:36 +00:00
|
|
|
# If we get here then this is the first time wxversion is used,
|
|
|
|
# ensure that wxPython hasn't been imported yet.
|
2004-10-22 05:53:49 +00:00
|
|
|
if sys.modules.has_key('wx') or sys.modules.has_key('wxPython'):
|
2004-10-26 21:55:25 +00:00
|
|
|
raise VersionError("wxversion.select() must be called before wxPython is imported")
|
|
|
|
|
2004-10-22 05:53:49 +00:00
|
|
|
# Look for a matching version and manipulate the sys.path as
|
|
|
|
# needed to allow it to be imported.
|
2004-10-26 21:55:25 +00:00
|
|
|
installed = _find_installed(True)
|
2005-05-17 00:36:18 +00:00
|
|
|
bestMatch = _get_best_match(installed, versions, optionsRequired)
|
2004-10-24 00:58:11 +00:00
|
|
|
|
|
|
|
if bestMatch is None:
|
|
|
|
raise VersionError("Requested version of wxPython not found")
|
|
|
|
|
|
|
|
sys.path.insert(0, bestMatch.pathname)
|
2006-01-20 17:32:43 +00:00
|
|
|
# q.v. Bug #1409256
|
|
|
|
path64 = re.sub('/lib/','/lib64/',bestMatch.pathname)
|
|
|
|
if os.path.isdir(path64):
|
|
|
|
sys.path.insert(0, path64)
|
2004-10-24 00:58:11 +00:00
|
|
|
_selected = bestMatch
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2004-10-28 20:34:52 +00:00
|
|
|
UPDATE_URL = "http://wxPython.org/"
|
|
|
|
#UPDATE_URL = "http://sourceforge.net/project/showfiles.php?group_id=10718"
|
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
_EM_DEBUG=0
|
2004-10-27 23:59:43 +00:00
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
def ensureMinimal(minVersion, optionsRequired=False):
|
2004-10-26 21:55:25 +00:00
|
|
|
"""
|
2004-10-27 23:59:43 +00:00
|
|
|
Checks to see if the default version of wxPython is greater-than
|
|
|
|
or equal to `minVersion`. If not then it will try to find an
|
|
|
|
installed version that is >= minVersion. If none are available
|
|
|
|
then a message is displayed that will inform the user and will
|
|
|
|
offer to open their web browser to the wxPython downloads page,
|
|
|
|
and will then exit the application.
|
2004-10-26 21:55:25 +00:00
|
|
|
"""
|
|
|
|
assert type(minVersion) == str
|
|
|
|
|
|
|
|
# ensure that wxPython hasn't been imported yet.
|
|
|
|
if sys.modules.has_key('wx') or sys.modules.has_key('wxPython'):
|
2004-10-27 23:59:43 +00:00
|
|
|
raise VersionError("wxversion.ensureMinimal() must be called before wxPython is imported")
|
|
|
|
|
2004-10-26 21:55:25 +00:00
|
|
|
bestMatch = None
|
|
|
|
minv = _wxPackageInfo(minVersion)
|
2005-05-17 00:36:18 +00:00
|
|
|
|
|
|
|
# check the default version first
|
2004-10-27 23:59:43 +00:00
|
|
|
defaultPath = _find_default()
|
|
|
|
if defaultPath:
|
|
|
|
defv = _wxPackageInfo(defaultPath, True)
|
2005-05-17 00:36:18 +00:00
|
|
|
if defv >= minv and minv.CheckOptions(defv, optionsRequired):
|
2004-10-27 23:59:43 +00:00
|
|
|
bestMatch = defv
|
2004-10-26 21:55:25 +00:00
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
# if still no match then check look at all installed versions
|
2004-10-27 23:59:43 +00:00
|
|
|
if bestMatch is None:
|
|
|
|
installed = _find_installed()
|
2005-05-17 00:36:18 +00:00
|
|
|
# The list is in reverse sorted order, so find the first
|
|
|
|
# one that is big enough and optionally matches the
|
|
|
|
# options
|
|
|
|
for inst in installed:
|
|
|
|
if inst >= minv and minv.CheckOptions(inst, optionsRequired):
|
|
|
|
bestMatch = inst
|
|
|
|
break
|
|
|
|
|
|
|
|
# if still no match then prompt the user
|
2004-10-26 21:55:25 +00:00
|
|
|
if bestMatch is None:
|
2005-05-17 00:36:18 +00:00
|
|
|
if _EM_DEBUG: # We'll do it this way just for the test code below
|
|
|
|
raise VersionError("Requested version of wxPython not found")
|
|
|
|
|
2004-10-26 21:55:25 +00:00
|
|
|
import wx, webbrowser
|
|
|
|
versions = "\n".join([" "+ver for ver in getInstalled()])
|
|
|
|
app = wx.PySimpleApp()
|
2004-10-27 23:59:43 +00:00
|
|
|
result = wx.MessageBox("This application requires a version of wxPython "
|
|
|
|
"greater than or equal to %s, but a matching version "
|
|
|
|
"was not found.\n\n"
|
|
|
|
"You currently have these version(s) installed:\n%s\n\n"
|
|
|
|
"Would you like to download a new version of wxPython?\n"
|
|
|
|
% (minVersion, versions),
|
|
|
|
"wxPython Upgrade Needed", style=wx.YES_NO)
|
|
|
|
if result == wx.YES:
|
2004-10-28 20:34:52 +00:00
|
|
|
webbrowser.open(UPDATE_URL)
|
2004-10-26 21:55:25 +00:00
|
|
|
app.MainLoop()
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
sys.path.insert(0, bestMatch.pathname)
|
2006-01-20 17:32:43 +00:00
|
|
|
# q.v. Bug #1409256
|
|
|
|
path64 = re.sub('/lib/','/lib64/',bestMatch.pathname)
|
|
|
|
if os.path.isdir(path64):
|
|
|
|
sys.path.insert(0, path64)
|
2005-05-05 00:11:33 +00:00
|
|
|
global _selected
|
2004-10-26 21:55:25 +00:00
|
|
|
_selected = bestMatch
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
def checkInstalled(versions, optionsRequired=False):
|
2004-10-24 00:58:11 +00:00
|
|
|
"""
|
|
|
|
Check if there is a version of wxPython installed that matches one
|
|
|
|
of the versions given. Returns True if so, False if not. This
|
|
|
|
can be used to determine if calling `select` will succeed or not.
|
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
:param versions: Same as in `select`, either a string or a list
|
|
|
|
of strings specifying the version(s) to check for.
|
|
|
|
|
|
|
|
:param optionsRequired: Same as in `select`.
|
2004-10-24 00:58:11 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
if type(versions) == str:
|
|
|
|
versions = [versions]
|
2004-10-26 21:55:25 +00:00
|
|
|
installed = _find_installed()
|
2005-05-17 00:36:18 +00:00
|
|
|
bestMatch = _get_best_match(installed, versions, optionsRequired)
|
2004-10-24 00:58:11 +00:00
|
|
|
return bestMatch is not None
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
|
|
|
def getInstalled():
|
|
|
|
"""
|
|
|
|
Returns a list of strings representing the installed wxPython
|
|
|
|
versions that are found on the system.
|
|
|
|
"""
|
2004-10-26 21:55:25 +00:00
|
|
|
installed = _find_installed()
|
|
|
|
return [os.path.basename(p.pathname)[3:] for p in installed]
|
2004-10-24 00:58:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# private helpers...
|
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
def _get_best_match(installed, versions, optionsRequired):
|
2004-10-24 00:58:11 +00:00
|
|
|
bestMatch = None
|
|
|
|
bestScore = 0
|
2004-10-26 21:55:25 +00:00
|
|
|
for pkg in installed:
|
2004-09-29 00:11:17 +00:00
|
|
|
for ver in versions:
|
2005-05-17 00:36:18 +00:00
|
|
|
score = pkg.Score(_wxPackageInfo(ver), optionsRequired)
|
2004-09-29 00:11:17 +00:00
|
|
|
if score > bestScore:
|
|
|
|
bestMatch = pkg
|
|
|
|
bestScore = score
|
2004-10-24 00:58:11 +00:00
|
|
|
return bestMatch
|
2004-09-29 00:11:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
_pattern = "wx-[0-9].*"
|
2004-10-24 00:58:11 +00:00
|
|
|
def _find_installed(removeExisting=False):
|
2004-09-29 00:11:17 +00:00
|
|
|
installed = []
|
2004-10-19 04:04:27 +00:00
|
|
|
toRemove = []
|
2004-09-29 00:11:17 +00:00
|
|
|
for pth in sys.path:
|
|
|
|
|
|
|
|
# empty means to look in the current dir
|
|
|
|
if not pth:
|
|
|
|
pth = '.'
|
|
|
|
|
|
|
|
# skip it if it's not a package dir
|
|
|
|
if not os.path.isdir(pth):
|
|
|
|
continue
|
|
|
|
|
|
|
|
base = os.path.basename(pth)
|
|
|
|
|
2004-10-19 04:04:27 +00:00
|
|
|
# if it's a wx path that's already in the sys.path then mark
|
|
|
|
# it for removal and then skip it
|
2004-09-29 00:11:17 +00:00
|
|
|
if fnmatch.fnmatchcase(base, _pattern):
|
2004-10-19 04:04:27 +00:00
|
|
|
toRemove.append(pth)
|
2004-09-29 00:11:17 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
# now look in the dir for matching subdirs
|
|
|
|
for name in glob.glob(os.path.join(pth, _pattern)):
|
|
|
|
# make sure it's a directory
|
|
|
|
if not os.path.isdir(name):
|
|
|
|
continue
|
|
|
|
# and has a wx subdir
|
|
|
|
if not os.path.exists(os.path.join(name, 'wx')):
|
|
|
|
continue
|
|
|
|
installed.append(_wxPackageInfo(name, True))
|
|
|
|
|
2004-10-24 00:58:11 +00:00
|
|
|
if removeExisting:
|
|
|
|
for rem in toRemove:
|
|
|
|
del sys.path[sys.path.index(rem)]
|
2004-10-19 04:04:27 +00:00
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
installed.sort()
|
|
|
|
installed.reverse()
|
|
|
|
return installed
|
|
|
|
|
|
|
|
|
2004-10-27 23:59:43 +00:00
|
|
|
# Scan the sys.path looking for either a directory matching _pattern,
|
|
|
|
# or a wx.pth file
|
|
|
|
def _find_default():
|
|
|
|
for pth in sys.path:
|
|
|
|
# empty means to look in the current dir
|
|
|
|
if not pth:
|
|
|
|
pth = '.'
|
|
|
|
|
|
|
|
# skip it if it's not a package dir
|
|
|
|
if not os.path.isdir(pth):
|
|
|
|
continue
|
|
|
|
|
|
|
|
# does it match the pattern?
|
|
|
|
base = os.path.basename(pth)
|
|
|
|
if fnmatch.fnmatchcase(base, _pattern):
|
|
|
|
return pth
|
|
|
|
|
|
|
|
for pth in sys.path:
|
|
|
|
if not pth:
|
|
|
|
pth = '.'
|
|
|
|
if not os.path.isdir(pth):
|
|
|
|
continue
|
|
|
|
if os.path.exists(os.path.join(pth, 'wx.pth')):
|
|
|
|
base = open(os.path.join(pth, 'wx.pth')).read()
|
|
|
|
return os.path.join(pth, base)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
class _wxPackageInfo(object):
|
|
|
|
def __init__(self, pathname, stripFirst=False):
|
|
|
|
self.pathname = pathname
|
|
|
|
base = os.path.basename(pathname)
|
|
|
|
segments = base.split('-')
|
|
|
|
if stripFirst:
|
|
|
|
segments = segments[1:]
|
|
|
|
self.version = tuple([int(x) for x in segments[0].split('.')])
|
|
|
|
self.options = segments[1:]
|
|
|
|
|
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
def Score(self, other, optionsRequired):
|
2004-09-29 00:11:17 +00:00
|
|
|
score = 0
|
2004-10-24 00:58:11 +00:00
|
|
|
|
2004-10-25 22:53:36 +00:00
|
|
|
# whatever number of version components given in other must
|
|
|
|
# match exactly
|
2004-10-24 00:58:11 +00:00
|
|
|
minlen = min(len(self.version), len(other.version))
|
|
|
|
if self.version[:minlen] != other.version[:minlen]:
|
|
|
|
return 0
|
2004-10-25 22:53:36 +00:00
|
|
|
score += 1
|
2005-05-17 00:36:18 +00:00
|
|
|
|
|
|
|
# check for matching options, if optionsRequired then the
|
|
|
|
# options are not optional ;-)
|
2004-09-29 00:11:17 +00:00
|
|
|
for opt in other.options:
|
|
|
|
if opt in self.options:
|
|
|
|
score += 1
|
2005-05-17 00:36:18 +00:00
|
|
|
elif optionsRequired:
|
|
|
|
return 0
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
return score
|
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
|
|
|
|
def CheckOptions(self, other, optionsRequired):
|
|
|
|
# if options are not required then this always succeeds
|
|
|
|
if not optionsRequired:
|
|
|
|
return True
|
|
|
|
# otherwise, if we have any option not present in other, then
|
|
|
|
# the match fails.
|
|
|
|
for opt in self.options:
|
|
|
|
if opt not in other.options:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2004-10-26 21:55:25 +00:00
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
def __lt__(self, other):
|
2004-10-26 21:55:25 +00:00
|
|
|
return self.version < other.version or \
|
|
|
|
(self.version == other.version and self.options < other.options)
|
|
|
|
def __le__(self, other):
|
|
|
|
return self.version <= other.version or \
|
|
|
|
(self.version == other.version and self.options <= other.options)
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
def __gt__(self, other):
|
2004-10-26 21:55:25 +00:00
|
|
|
return self.version > other.version or \
|
|
|
|
(self.version == other.version and self.options > other.options)
|
|
|
|
def __ge__(self, other):
|
|
|
|
return self.version >= other.version or \
|
|
|
|
(self.version == other.version and self.options >= other.options)
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
def __eq__(self, other):
|
2004-10-26 21:55:25 +00:00
|
|
|
return self.version == other.version and self.options == other.options
|
2004-09-29 00:11:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2004-10-24 00:58:11 +00:00
|
|
|
#----------------------------------------------------------------------
|
2004-09-29 00:11:17 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2004-10-19 04:04:27 +00:00
|
|
|
import pprint
|
2004-10-27 23:59:43 +00:00
|
|
|
|
|
|
|
#ensureMinimal('2.5')
|
|
|
|
#pprint.pprint(sys.path)
|
2004-10-26 21:55:25 +00:00
|
|
|
#sys.exit()
|
|
|
|
|
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
def test(version, optionsRequired=False):
|
2004-10-22 05:53:49 +00:00
|
|
|
# setup
|
2004-09-29 00:11:17 +00:00
|
|
|
savepath = sys.path[:]
|
2004-10-22 05:53:49 +00:00
|
|
|
|
|
|
|
#test
|
2005-05-17 00:36:18 +00:00
|
|
|
select(version, optionsRequired)
|
|
|
|
print "Asked for %s, (%s):\t got: %s" % (version, optionsRequired, sys.path[0])
|
|
|
|
|
|
|
|
# reset
|
|
|
|
sys.path = savepath[:]
|
|
|
|
global _selected
|
|
|
|
_selected = None
|
|
|
|
|
|
|
|
|
|
|
|
def testEM(version, optionsRequired=False):
|
|
|
|
# setup
|
|
|
|
savepath = sys.path[:]
|
|
|
|
|
|
|
|
#test
|
|
|
|
ensureMinimal(version, optionsRequired)
|
|
|
|
print "EM: Asked for %s, (%s):\t got: %s" % (version, optionsRequired, sys.path[0])
|
2004-10-22 05:53:49 +00:00
|
|
|
|
|
|
|
# reset
|
2004-09-29 00:11:17 +00:00
|
|
|
sys.path = savepath[:]
|
2004-10-22 05:53:49 +00:00
|
|
|
global _selected
|
|
|
|
_selected = None
|
2004-09-29 00:11:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
# make some test dirs
|
2005-05-17 00:36:18 +00:00
|
|
|
names = ['wx-2.4-gtk-ansi',
|
|
|
|
'wx-2.5.2-gtk2-unicode',
|
|
|
|
'wx-2.5.3-gtk-ansi',
|
|
|
|
'wx-2.6-gtk2-unicode',
|
|
|
|
'wx-2.6-gtk2-ansi',
|
|
|
|
'wx-2.6-gtk-ansi',
|
|
|
|
'wx-2.7.1-gtk2-ansi',
|
|
|
|
]
|
2004-09-29 00:11:17 +00:00
|
|
|
for name in names:
|
|
|
|
d = os.path.join('/tmp', name)
|
|
|
|
os.mkdir(d)
|
|
|
|
os.mkdir(os.path.join(d, 'wx'))
|
|
|
|
|
|
|
|
# setup sys.path to see those dirs
|
|
|
|
sys.path.append('/tmp')
|
|
|
|
|
|
|
|
|
|
|
|
# now run some tests
|
2004-10-24 00:58:11 +00:00
|
|
|
pprint.pprint( getInstalled())
|
|
|
|
print checkInstalled("2.4")
|
|
|
|
print checkInstalled("2.5-unicode")
|
|
|
|
print checkInstalled("2.99-bogus")
|
2004-10-27 23:59:43 +00:00
|
|
|
print "Current sys.path:"
|
|
|
|
pprint.pprint(sys.path)
|
|
|
|
print
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
test("2.4")
|
|
|
|
test("2.5")
|
|
|
|
test("2.5-gtk2")
|
|
|
|
test("2.5.2")
|
|
|
|
test("2.5-ansi")
|
|
|
|
test("2.5-unicode")
|
2005-05-17 00:36:18 +00:00
|
|
|
test("2.6")
|
|
|
|
test("2.6-ansi")
|
|
|
|
test(["2.6-unicode", "2.7-unicode"])
|
|
|
|
test(["2.6", "2.7"])
|
|
|
|
test(["2.6-unicode", "2.7-unicode"], optionsRequired=True)
|
|
|
|
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
|
|
|
|
# There isn't a unicode match for this one, but it will give the best
|
|
|
|
# available 2.4. Should it give an error instead? I don't think so...
|
|
|
|
test("2.4-unicode")
|
|
|
|
|
2004-10-22 05:53:49 +00:00
|
|
|
# Try asking for multiple versions
|
2005-05-17 00:36:18 +00:00
|
|
|
test(["2.5.2", "2.5.3", "2.6"])
|
2004-10-22 05:53:49 +00:00
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
try:
|
|
|
|
# expecting an error on this one
|
2005-05-17 00:36:18 +00:00
|
|
|
test("2.9")
|
2004-10-24 00:58:11 +00:00
|
|
|
except VersionError, e:
|
2005-05-17 00:36:18 +00:00
|
|
|
print "Asked for 2.9:\t got Exception:", e
|
2004-09-29 00:11:17 +00:00
|
|
|
|
2004-10-22 05:53:49 +00:00
|
|
|
# check for exception when incompatible versions are requested
|
|
|
|
try:
|
2004-10-24 00:58:11 +00:00
|
|
|
select("2.4")
|
|
|
|
select("2.5")
|
|
|
|
except VersionError, e:
|
2004-10-22 05:53:49 +00:00
|
|
|
print "Asked for incompatible versions, got Exception:", e
|
2004-09-29 00:11:17 +00:00
|
|
|
|
2005-05-17 00:36:18 +00:00
|
|
|
_EM_DEBUG=1
|
|
|
|
testEM("2.6")
|
|
|
|
testEM("2.6-unicode")
|
|
|
|
testEM("2.6-unicode", True)
|
|
|
|
try:
|
|
|
|
testEM("2.9")
|
|
|
|
except VersionError, e:
|
|
|
|
print "EM: Asked for 2.9:\t got Exception:", e
|
|
|
|
|
2004-09-29 00:11:17 +00:00
|
|
|
# cleanup
|
|
|
|
for name in names:
|
|
|
|
d = os.path.join('/tmp', name)
|
|
|
|
os.rmdir(os.path.join(d, 'wx'))
|
|
|
|
os.rmdir(d)
|
|
|
|
|
|
|
|
|