X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/85245f48ad351409d50cbecfab874827eb0f719b..95af070abdb43183bb131f7b78ce03b553cdcb34:/wxPython/distrib/mac/uninstall_wxPython.py diff --git a/wxPython/distrib/mac/uninstall_wxPython.py b/wxPython/distrib/mac/uninstall_wxPython.py index 80373c232e..c99d301535 100755 --- a/wxPython/distrib/mac/uninstall_wxPython.py +++ b/wxPython/distrib/mac/uninstall_wxPython.py @@ -13,42 +13,68 @@ yourself. """ import sys, os, glob +from fnmatch import fnmatchcase import cPickle, urllib RCPTDIR = "/Library/Receipts" RSRCDIR = "Contents/Resources" -# only clean up dirs that have one of these as a prefix. We do this -# because the file list returned from lsbom will include /, /usr, -# /usr/local, etc. +# Only completly clean out dirs that have one of these as a prefix. +# We do this because the file list returned from lsbom will include /, +# /usr, /usr/local, etc. PREFIXES = [ '/Library/Python/2.3/', '/Library/Python/2.4/', + '/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/', + '/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/', '/usr/local/lib/', ] +# The files that match one of the items in this list will only be +# removed if the last installation of wxPython on the system is being +# uninstalled. +COMMON_FILES = [ '/usr/local/bin/*', + 'wx.pth', + 'wxversion.py', + ] + + class AccessError(Exception): pass +class ReceiptError(Exception): + pass + class InstalledReceipt(object): def __init__(self, rcptPath): self.rcptPath = rcptPath self.rsrcPath = os.path.join(rcptPath, RSRCDIR) - self.bomFile = glob.glob(os.path.join(self.rsrcPath, "*.bom"))[0] + bf = glob.glob(os.path.join(self.rsrcPath, "*.bom")) + if bf: + self.bomFile = bf[0] + else: + print "WARNING: Unable to find %s/*.bom" % self.rsrcPath + raise ReceiptError self.findMetaData() def findMetaData(self): # TODO: Make this be able to also look at Info.plist files - infoFile = glob.glob(os.path.join(self.rsrcPath, "*.info"))[0] - self.mdata = {} - for line in open(infoFile, "r").readlines(): - line = line.strip() - if line and line[0] != '#': - ls = line.split() - self.mdata[ls[0]] = line[len(ls[0])+1:] - + infoFiles = glob.glob(os.path.join(self.rsrcPath, "*.info")) + if infoFiles: + # there should be only one + infoFile = infoFiles[0] + self.mdata = {} + for line in open(infoFile, "r").readlines(): + line = line.strip() + if line and line[0] != '#': + ls = line.split() + self.mdata[ls[0]] = line[len(ls[0])+1:] + else: + print "WARNING: Unable to find %s/*.info" % self.rsrcPath + raise ReceiptError + def getFileList(self): p = os.popen("lsbom -s %s" % self.bomFile, "r") @@ -87,10 +113,18 @@ class InstalledReceipt(object): handleDir(dirpath) + def testCommon(self, name): + for cmn in COMMON_FILES: + if fnmatchcase(name, cmn) or fnmatchcase(os.path.basename(name), cmn): + return True + return False + def showFiles(self): def show(name): if os.path.exists(name): + if not self.lastInstall and self.testCommon(name): + return print "Will remove:", name self.walkFiles(show, show) @@ -98,6 +132,8 @@ class InstalledReceipt(object): def testUninstallAccess(self): def testFile(name): if os.path.exists(name): + if not self.lastInstall and self.testCommon(name): + return if not os.access(name, os.W_OK): raise AccessError(name) self.walkFiles(testFile, testFile) @@ -106,13 +142,15 @@ class InstalledReceipt(object): def doUninstall(self): def removeFile(name): if os.path.exists(name): + if not self.lastInstall and self.testCommon(name): + return print "Removing:", name os.unlink(name) def removeDir(name): print "Removing:", name if os.path.exists(name): hasFiles = os.listdir(name) - if hasFiles: # perhaps some left over symlinks, or .pyc files + if hasFiles: # perhaps some stale symlinks, or .pyc files for file in hasFiles: os.unlink(os.path.join(name, file)) os.rmdir(name) @@ -131,8 +169,11 @@ class InstalledReceipt(object): def findInstalled(): installed = [] for name in glob.glob(os.path.join(RCPTDIR, "wxPython*")): - ir = InstalledReceipt(name) - installed.append(ir) + try: + ir = InstalledReceipt(name) + installed.append(ir) + except ReceiptError: + pass # just skip it... return installed @@ -160,13 +201,14 @@ def main(): sys.exit() for i, inst in enumerate(installed): - print " %d. %s \t%s" % (i+1, inst.mdata["Title"], inst.mdata["Version"]) + print " %2d. %-40s %s" % (i+1, inst.mdata["Title"], inst.mdata["Version"]) print ans = raw_input("Enter the number of the install to examine or 'Q' to quit: ") if ans in ['Q', 'q']: sys.exit() inst = installed[int(ans) - 1] + inst.lastInstall = len(installed) == 1 while True: print