blob: f14772961fedeebef68608a78fee3d2f96556c85 [file] [log] [blame]
Guido van Rossum03dea6d1996-09-03 18:19:12 +00001"""Uninstaller for Windows NT 3.5 and Windows 95.
2
3Actions:
4
51. 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
102. 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
15import sys
16import nt
17import os
18import win32api
19import win32con
20
21def rmkey(parent, key, level=0):
22 sep = " "*level
23 try:
Guido van Rossum71543e11998-04-06 14:46:29 +000024 handle = win32api.RegOpenKey(parent, key)
Guido van Rossum03dea6d1996-09-03 18:19:12 +000025 except win32api.error, msg:
Guido van Rossum71543e11998-04-06 14:46:29 +000026 print sep + "No key", `key`
27 return
Guido van Rossum03dea6d1996-09-03 18:19:12 +000028 print sep + "Removing key", key
29 while 1:
Guido van Rossum71543e11998-04-06 14:46:29 +000030 try:
31 subkey = win32api.RegEnumKey(handle, 0)
32 except win32api.error, msg:
33 break
34 rmkey(handle, subkey, level+1)
Guido van Rossum03dea6d1996-09-03 18:19:12 +000035 win32api.RegCloseKey(handle)
36 win32api.RegDeleteKey(parent, key)
37 print sep + "Done with", key
38
39roothandle = win32con.HKEY_LOCAL_MACHINE
40pythonkey = "Software\\Python\\PythonCore\\" + sys.winver
41rmkey(roothandle, pythonkey)
42uninstallkey = \
43 "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Python"+sys.winver
44rmkey(roothandle, uninstallkey)
45
46def rmtree(dir, level=0):
47 sep = " "*level
48 print sep+"rmtree", dir
49 for name in os.listdir(dir):
Guido van Rossum71543e11998-04-06 14:46:29 +000050 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`
Guido van Rossum03dea6d1996-09-03 18:19:12 +000063 try:
Guido van Rossum71543e11998-04-06 14:46:29 +000064 os.rmdir(dir)
Guido van Rossum03dea6d1996-09-03 18:19:12 +000065 except os.error, msg:
Guido van Rossum71543e11998-04-06 14:46:29 +000066 print sep+"can't remove directory", `dir`, msg
Guido van Rossum03dea6d1996-09-03 18:19:12 +000067 else:
Guido van Rossum71543e11998-04-06 14:46:29 +000068 print sep+"removed directory", `dir`
Guido van Rossum03dea6d1996-09-03 18:19:12 +000069
70pwd = os.getcwd()
71scriptdir = os.path.normpath(os.path.join(pwd, os.path.dirname(sys.argv[0])))
72pathdir = os.path.normpath(os.path.join(pwd, sys.path[0]))
73if scriptdir == pathdir:
74 rmtree(pathdir)
75else:
76 print "inconsistend script directory, not removing any files."
77 print "script directory =", `scriptdir`
78 print "path directory =", `pathdir`