]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/distrib/mac/uninstall_wxPython.py
3 This script will search for installed versions of wxPython on OSX and
4 allow the user to choose one to uninstall. It then will use the
5 metadata stored about the installed package to remove all the files
6 associated with that install.
8 Only the files installed by the main Installer Package will be
9 removed. This includes the Python modules and the wxWidgets shared
10 libraries. If you also installed the demo or docs by dragging them out
11 of the disk image, then you will need to drag them to the Trash
16 import cPickle
, urllib
18 RCPTDIR
= "/Library/Receipts"
19 RSRCDIR
= "Contents/Resources"
21 # only clean up dirs that have one of these as a prefix. We do this
22 # because the file list returned from lsbom will include /, /usr,
24 PREFIXES
= [ '/Library/Python/2.3/',
25 '/Library/Python/2.4/',
30 class AccessError(Exception):
34 class InstalledReceipt(object):
35 def __init__(self
, rcptPath
):
36 self
.rcptPath
= rcptPath
37 self
.rsrcPath
= os
.path
.join(rcptPath
, RSRCDIR
)
38 self
.bomFile
= glob
.glob(os
.path
.join(self
.rsrcPath
, "*.bom"))[0]
42 def findMetaData(self
):
43 # TODO: Make this be able to also look at Info.plist files
44 infoFile
= glob
.glob(os
.path
.join(self
.rsrcPath
, "*.info"))[0]
46 for line
in open(infoFile
, "r").readlines():
48 if line
and line
[0] != '#':
50 self
.mdata
[ls
[0]] = line
[len(ls
[0])+1:]
53 def getFileList(self
):
54 p
= os
.popen("lsbom -s %s" % self
.bomFile
, "r")
57 data
= filter(lambda s
: s
!='' and s
!='.', data
.split('\n'))
58 loc
= self
.mdata
['DefaultLocation']
59 return [loc
+item
for item
in data
]
62 def walkFiles(self
, handleFile
, handleDir
):
64 names
= self
.getFileList()
68 name
= os
.path
.abspath(name
)
69 if os
.path
.isdir(name
):
77 for prefix
in PREFIXES
:
78 if dir.startswith(prefix
):
82 # Finally, remove the Receipts package, bottom-up
83 for dirpath
, dirname
, filenames
in os
.walk(self
.rcptPath
, False):
84 for name
in filenames
:
85 name
= os
.path
.join(dirpath
, name
)
93 if os
.path
.exists(name
):
94 print "Will remove:", name
95 self
.walkFiles(show
, show
)
98 def testUninstallAccess(self
):
100 if os
.path
.exists(name
):
101 if not os
.access(name
, os
.W_OK
):
102 raise AccessError(name
)
103 self
.walkFiles(testFile
, testFile
)
106 def doUninstall(self
):
107 def removeFile(name
):
108 if os
.path
.exists(name
):
109 print "Removing:", name
112 print "Removing:", name
113 if os
.path
.exists(name
):
114 hasFiles
= os
.listdir(name
)
115 if hasFiles
: # perhaps some left over symlinks, or .pyc files
116 for file in hasFiles
:
117 os
.unlink(os
.path
.join(name
, file))
121 self
.testUninstallAccess()
122 except AccessError
, e
:
123 print "UNABLE TO UNINSTALL!\nNo permission to remove: ", e
.args
[0]
126 self
.walkFiles(removeFile
, removeDir
)
133 for name
in glob
.glob(os
.path
.join(RCPTDIR
, "wxPython*")):
134 ir
= InstalledReceipt(name
)
140 # Just in case a Python < 2.3 is used to run this
144 def enumerate(sequence
):
145 return zip(range(len(sequence
)), sequence
)
149 if len(sys
.argv
) > 1 and sys
.argv
[1] == "-doit":
150 inst
= cPickle
.loads(urllib
.unquote(sys
.argv
[2]))
155 installed
= findInstalled()
158 print "*** No wxPython installations found! ***"
159 raw_input("Press RETURN...")
162 for i
, inst
in enumerate(installed
):
163 print " %d. %s \t%s" % (i
+1, inst
.mdata
["Title"], inst
.mdata
["Version"])
166 ans
= raw_input("Enter the number of the install to examine or 'Q' to quit: ")
167 if ans
in ['Q', 'q']:
169 inst
= installed
[int(ans
) - 1]
176 Description: %(Description)s
179 ans
= raw_input("(U)ninstall, (S)how what will be removed, or (Q)uit? [u,s,q] ")
180 if ans
in ['Q', 'q']:
183 elif ans
in ['S', 's']:
186 elif ans
in ['U', 'u']:
188 print "Launching uninstaller with sudo, please enter your password if prompted:"
189 os
.system("sudo %s -doit %s" %
191 urllib
.quote(cPickle
.dumps(inst
))))
195 if __name__
== '__main__':