diff options
author | Guido van Rossum <guido@python.org> | 1996-09-03 18:19:12 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-09-03 18:19:12 (GMT) |
commit | 03dea6d026d53e920b897037b382c611575e24be (patch) | |
tree | 7c56704f5c1b9eaac9db9062651be5e15df73727 /PC/setup_nt/uninstall.py | |
parent | 604cefa8df16232c064a2b246e392b13a9e473f6 (diff) | |
download | cpython-03dea6d026d53e920b897037b382c611575e24be.zip cpython-03dea6d026d53e920b897037b382c611575e24be.tar.gz cpython-03dea6d026d53e920b897037b382c611575e24be.tar.bz2 |
Added uninstall option
Diffstat (limited to 'PC/setup_nt/uninstall.py')
-rw-r--r-- | PC/setup_nt/uninstall.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/PC/setup_nt/uninstall.py b/PC/setup_nt/uninstall.py new file mode 100644 index 0000000..64f2a02 --- /dev/null +++ b/PC/setup_nt/uninstall.py @@ -0,0 +1,78 @@ +"""Uninstaller for Windows NT 3.5 and Windows 95. + +Actions: + +1. Remove our entries from the Registry: + - Software\Python\PythonCore\<winver> + - Software\Microsoft\Windows\CurrentVersion\Uninstall\Python<winver> + (Should we also remove the entry for .py and Python.Script?) + +2. Remove the installation tree -- this is assumed to be the directory + whose path is both os.path.dirname(sys.argv[0]) and sys.path[0] + +""" + +import sys +import nt +import os +import win32api +import win32con + +def rmkey(parent, key, level=0): + sep = " "*level + try: + handle = win32api.RegOpenKey(parent, key) + except win32api.error, msg: + print sep + "No key", `key` + return + print sep + "Removing key", key + while 1: + try: + subkey = win32api.RegEnumKey(handle, 0) + except win32api.error, msg: + break + rmkey(handle, subkey, level+1) + win32api.RegCloseKey(handle) + win32api.RegDeleteKey(parent, key) + print sep + "Done with", key + +roothandle = win32con.HKEY_LOCAL_MACHINE +pythonkey = "Software\\Python\\PythonCore\\" + sys.winver +rmkey(roothandle, pythonkey) +uninstallkey = \ + "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Python"+sys.winver +rmkey(roothandle, uninstallkey) + +def rmtree(dir, level=0): + sep = " "*level + print sep+"rmtree", dir + for name in os.listdir(dir): + if level == 0 and \ + os.path.normcase(name) == os.path.normcase("uninstall.bat"): + continue + fn = os.path.join(dir, name) + if os.path.isdir(fn): + rmtree(fn, level+1) + else: + try: + os.remove(fn) + except os.error, msg: + print sep+" can't remove", `fn`, msg + else: + print sep+" removed", `fn` + try: + os.rmdir(dir) + except os.error, msg: + print sep+"can't remove directory", `dir`, msg + else: + print sep+"removed directory", `dir` + +pwd = os.getcwd() +scriptdir = os.path.normpath(os.path.join(pwd, os.path.dirname(sys.argv[0]))) +pathdir = os.path.normpath(os.path.join(pwd, sys.path[0])) +if scriptdir == pathdir: + rmtree(pathdir) +else: + print "inconsistend script directory, not removing any files." + print "script directory =", `scriptdir` + print "path directory =", `pathdir` |