Guido van Rossum | 03dea6d | 1996-09-03 18:19:12 +0000 | [diff] [blame] | 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: |
Guido van Rossum | 71543e1 | 1998-04-06 14:46:29 +0000 | [diff] [blame] | 24 | handle = win32api.RegOpenKey(parent, key) |
Guido van Rossum | 03dea6d | 1996-09-03 18:19:12 +0000 | [diff] [blame] | 25 | except win32api.error, msg: |
Guido van Rossum | 71543e1 | 1998-04-06 14:46:29 +0000 | [diff] [blame] | 26 | print sep + "No key", `key` |
| 27 | return |
Guido van Rossum | 03dea6d | 1996-09-03 18:19:12 +0000 | [diff] [blame] | 28 | print sep + "Removing key", key |
| 29 | while 1: |
Guido van Rossum | 71543e1 | 1998-04-06 14:46:29 +0000 | [diff] [blame] | 30 | try: |
| 31 | subkey = win32api.RegEnumKey(handle, 0) |
| 32 | except win32api.error, msg: |
| 33 | break |
| 34 | rmkey(handle, subkey, level+1) |
Guido van Rossum | 03dea6d | 1996-09-03 18:19:12 +0000 | [diff] [blame] | 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): |
Guido van Rossum | 71543e1 | 1998-04-06 14:46:29 +0000 | [diff] [blame] | 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` |
Guido van Rossum | 03dea6d | 1996-09-03 18:19:12 +0000 | [diff] [blame] | 63 | try: |
Guido van Rossum | 71543e1 | 1998-04-06 14:46:29 +0000 | [diff] [blame] | 64 | os.rmdir(dir) |
Guido van Rossum | 03dea6d | 1996-09-03 18:19:12 +0000 | [diff] [blame] | 65 | except os.error, msg: |
Guido van Rossum | 71543e1 | 1998-04-06 14:46:29 +0000 | [diff] [blame] | 66 | print sep+"can't remove directory", `dir`, msg |
Guido van Rossum | 03dea6d | 1996-09-03 18:19:12 +0000 | [diff] [blame] | 67 | else: |
Guido van Rossum | 71543e1 | 1998-04-06 14:46:29 +0000 | [diff] [blame] | 68 | print sep+"removed directory", `dir` |
Guido van Rossum | 03dea6d | 1996-09-03 18:19:12 +0000 | [diff] [blame] | 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` |