Changed selectNewest to ensureMinimal. If the default version is >=

the minimum then use it, otherwise find an installed version that is
>= minimum, or will display a message and bail out.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30131 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2004-10-27 23:59:43 +00:00
parent 153fe6e7dd
commit 6be3fd57c6

View File

@@ -124,43 +124,52 @@ def select(versions):
#---------------------------------------------------------------------- #----------------------------------------------------------------------
def selectNewest(minVersion):
def ensureMinimal(minVersion):
""" """
Selects a version of wxPython that has a version number greater Checks to see if the default version of wxPython is greater-than
than or equal to the version given. If a matching version is not or equal to `minVersion`. If not then it will try to find an
found then instead of raising an exception like select() does this installed version that is >= minVersion. If none are available
function will inform the user of that fact with a message dialog, then a message is displayed that will inform the user and will
open the system's default web browser to the wxPython download offer to open their web browser to the wxPython downloads page,
page, and then will exit the application. and will then exit the application.
""" """
assert type(minVersion) == str assert type(minVersion) == str
# ensure that wxPython hasn't been imported yet. # ensure that wxPython hasn't been imported yet.
if sys.modules.has_key('wx') or sys.modules.has_key('wxPython'): if sys.modules.has_key('wx') or sys.modules.has_key('wxPython'):
raise VersionError("wxversion.selectNewest() must be called before wxPython is imported") raise VersionError("wxversion.ensureMinimal() must be called before wxPython is imported")
bestMatch = None
installed = _find_installed(True)
minv = _wxPackageInfo(minVersion)
if installed: bestMatch = None
# The list is in reverse sorted order, so if the first one is minv = _wxPackageInfo(minVersion)
# big enough then choose it defaultPath = _find_default()
if installed[0] >= minv: if defaultPath:
bestMatch = installed[0] defv = _wxPackageInfo(defaultPath, True)
if defv >= minv:
bestMatch = defv
if bestMatch is None:
installed = _find_installed()
if installed:
# The list is in reverse sorted order, so if the first one is
# big enough then choose it
if installed[0] >= minv:
bestMatch = installed[0]
if bestMatch is None: if bestMatch is None:
import wx, webbrowser import wx, webbrowser
versions = "\n".join([" "+ver for ver in getInstalled()]) versions = "\n".join([" "+ver for ver in getInstalled()])
app = wx.PySimpleApp() app = wx.PySimpleApp()
wx.MessageBox("This application requires a version of wxPython " result = wx.MessageBox("This application requires a version of wxPython "
"greater than or equal to %s but a matching version " "greater than or equal to %s, but a matching version "
"was not found.\n\n" "was not found.\n\n"
"You currently have these version(s) installed:\n%s" "You currently have these version(s) installed:\n%s\n\n"
% (minVersion, versions), "Would you like to download a new version of wxPython?\n"
"wxPython Upgrade Needed", style=wx.OK) % (minVersion, versions),
"wxPython Upgrade Needed", style=wx.YES_NO)
if result == wx.YES:
webbrowser.open("http://sourceforge.net/project/showfiles.php?group_id=10718")
app.MainLoop() app.MainLoop()
webbrowser.open("http://sourceforge.net/project/showfiles.php?group_id=10718")
sys.exit() sys.exit()
sys.path.insert(0, bestMatch.pathname) sys.path.insert(0, bestMatch.pathname)
@@ -254,6 +263,35 @@ def _find_installed(removeExisting=False):
return installed return installed
# 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
class _wxPackageInfo(object): class _wxPackageInfo(object):
def __init__(self, pathname, stripFirst=False): def __init__(self, pathname, stripFirst=False):
self.pathname = pathname self.pathname = pathname
@@ -305,9 +343,9 @@ class _wxPackageInfo(object):
if __name__ == '__main__': if __name__ == '__main__':
import pprint import pprint
#selectNewest('2.5') #ensureMinimal('2.5')
#print sys.path[0] #pprint.pprint(sys.path)
#sys.exit() #sys.exit()
@@ -318,8 +356,8 @@ if __name__ == '__main__':
#test #test
select(version) select(version)
print "Asked for %s:\t got: %s" % (version, sys.path[0]) print "Asked for %s:\t got: %s" % (version, sys.path[0])
#pprint.pprint(sys.path) pprint.pprint(sys.path)
#print print
# reset # reset
sys.path = savepath[:] sys.path = savepath[:]
@@ -349,6 +387,10 @@ if __name__ == '__main__':
print checkInstalled("2.4") print checkInstalled("2.4")
print checkInstalled("2.5-unicode") print checkInstalled("2.5-unicode")
print checkInstalled("2.99-bogus") print checkInstalled("2.99-bogus")
print "Current sys.path:"
pprint.pprint(sys.path)
print
test("2.4") test("2.4")
test("2.5") test("2.5")
test("2.5-gtk2") test("2.5-gtk2")