|
4190
|
1 """Uninstaller for Windows NT 3.5 and Windows 95.
|
|
|
2
|
|
|
3 Actions:
|
|
|
4
|
|
|
5 1. Remove our entries from the Registry:
|
|
|
6 - Software\Python\PythonCore\<winver>
|
|
|
7 - Software\Microsoft\Windows\CurrentVersion\Uninstall\Python<winver>
|
|
|
8 (Should we also remove the entry for .py and Python.Script?)
|
|
|
9
|
|
|
10 2. Remove the installation tree -- this is assumed to be the directory
|
|
|
11 whose path is both os.path.dirname(sys.argv[0]) and sys.path[0]
|
|
|
12
|
|
|
13 """
|
|
|
14
|
|
|
15 import sys
|
|
|
16 import nt
|
|
|
17 import os
|
|
|
18 import win32api
|
|
|
19 import win32con
|
|
|
20
|
|
|
21 def rmkey(parent, key, level=0):
|
|
|
22 sep = " "*level
|
|
|
23 try:
|
|
|
24 handle = win32api.RegOpenKey(parent, key)
|
|
|
25 except win32api.error, msg:
|
|
|
26 print sep + "No key", `key`
|
|
|
27 return
|
|
|
28 print sep + "Removing key", key
|
|
|
29 while 1:
|
|
|
30 try:
|
|
|
31 subkey = win32api.RegEnumKey(handle, 0)
|
|
|
32 except win32api.error, msg:
|
|
|
33 break
|
|
|
34 rmkey(handle, subkey, level+1)
|
|
|
35 win32api.RegCloseKey(handle)
|
|
|
36 win32api.RegDeleteKey(parent, key)
|
|
|
37 print sep + "Done with", key
|
|
|
38
|
|
|
39 roothandle = win32con.HKEY_LOCAL_MACHINE
|
|
|
40 pythonkey = "Software\\Python\\PythonCore\\" + sys.winver
|
|
|
41 rmkey(roothandle, pythonkey)
|
|
|
42 uninstallkey = \
|
|
|
43 "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Python"+sys.winver
|
|
|
44 rmkey(roothandle, uninstallkey)
|
|
|
45
|
|
|
46 def rmtree(dir, level=0):
|
|
|
47 sep = " "*level
|
|
|
48 print sep+"rmtree", dir
|
|
|
49 for name in os.listdir(dir):
|
|
|
50 if level == 0 and \
|
|
|
51 os.path.normcase(name) == os.path.normcase("uninstall.bat"):
|
|
|
52 continue
|
|
|
53 fn = os.path.join(dir, name)
|
|
|
54 if os.path.isdir(fn):
|
|
|
55 rmtree(fn, level+1)
|
|
|
56 else:
|
|
|
57 try:
|
|
|
58 os.remove(fn)
|
|
|
59 except os.error, msg:
|
|
|
60 print sep+" can't remove", `fn`, msg
|
|
|
61 else:
|
|
|
62 print sep+" removed", `fn`
|
|
|
63 try:
|
|
|
64 os.rmdir(dir)
|
|
|
65 except os.error, msg:
|
|
|
66 print sep+"can't remove directory", `dir`, msg
|
|
|
67 else:
|
|
|
68 print sep+"removed directory", `dir`
|
|
|
69
|
|
|
70 pwd = os.getcwd()
|
|
|
71 scriptdir = os.path.normpath(os.path.join(pwd, os.path.dirname(sys.argv[0])))
|
|
|
72 pathdir = os.path.normpath(os.path.join(pwd, sys.path[0]))
|
|
|
73 if scriptdir == pathdir:
|
|
|
74 rmtree(pathdir)
|
|
|
75 else:
|
|
|
76 print "inconsistend script directory, not removing any files."
|
|
|
77 print "script directory =", `scriptdir`
|
|
|
78 print "path directory =", `pathdir`
|