Give in to tabnanny
This commit is contained in:
parent
8053d89f7b
commit
71543e13db
|
@ -27,41 +27,41 @@ while 1:
|
||||||
pwd = nt.getcwd()
|
pwd = nt.getcwd()
|
||||||
##print "Could it be", `pwd`, "?"
|
##print "Could it be", `pwd`, "?"
|
||||||
try:
|
try:
|
||||||
open("Lib\\os.py").close()
|
open("Lib\\os.py").close()
|
||||||
##print "It appears so."
|
##print "It appears so."
|
||||||
break
|
break
|
||||||
except IOError:
|
except IOError:
|
||||||
##print "Hm, it doesn't appear to be. Try the parent directory."
|
##print "Hm, it doesn't appear to be. Try the parent directory."
|
||||||
try:
|
try:
|
||||||
opwd = pwd
|
opwd = pwd
|
||||||
nt.chdir("..")
|
nt.chdir("..")
|
||||||
pwd = nt.getcwd()
|
pwd = nt.getcwd()
|
||||||
if opwd == pwd:
|
if opwd == pwd:
|
||||||
##print "Seems like we're in the root already."
|
##print "Seems like we're in the root already."
|
||||||
raise nt.error
|
raise nt.error
|
||||||
except nt.error:
|
except nt.error:
|
||||||
##print "Can't chdir to the parent -- we're stuck."
|
##print "Can't chdir to the parent -- we're stuck."
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
##print "Try again one level higher."
|
##print "Try again one level higher."
|
||||||
continue
|
continue
|
||||||
print "Hey, would you like to help?"
|
print "Hey, would you like to help?"
|
||||||
print "Please enter the pathname of the Python root."
|
print "Please enter the pathname of the Python root."
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
dirname = raw_input("Python root: ")
|
dirname = raw_input("Python root: ")
|
||||||
except EOFError:
|
except EOFError:
|
||||||
print "OK, I give up."
|
print "OK, I give up."
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not dirname:
|
if not dirname:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
nt.chdir(dirname)
|
nt.chdir(dirname)
|
||||||
except nt.error:
|
except nt.error:
|
||||||
print "That directory doesn't seem to exist."
|
print "That directory doesn't seem to exist."
|
||||||
print "Please try again."
|
print "Please try again."
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
pwd = nt.getcwd()
|
pwd = nt.getcwd()
|
||||||
print "Python root directory is", pwd
|
print "Python root directory is", pwd
|
||||||
sys.path[1:] = [".\\Lib", ".\\Lib\win", ".\\Bin", ".\\vc40"]
|
sys.path[1:] = [".\\Lib", ".\\Lib\win", ".\\Bin", ".\\vc40"]
|
||||||
|
@ -80,49 +80,49 @@ except ImportError:
|
||||||
print "Beh. We have win32api but not win32con."
|
print "Beh. We have win32api but not win32con."
|
||||||
print "Making do with a dummy."
|
print "Making do with a dummy."
|
||||||
class win32con:
|
class win32con:
|
||||||
REG_NOTIFY_CHANGE_ATTRIBUTES = 0x00000002L
|
REG_NOTIFY_CHANGE_ATTRIBUTES = 0x00000002L
|
||||||
REG_NOTIFY_CHANGE_SECURITY = 0x00000008L
|
REG_NOTIFY_CHANGE_SECURITY = 0x00000008L
|
||||||
REG_RESOURCE_REQUIREMENTS_LIST = 10
|
REG_RESOURCE_REQUIREMENTS_LIST = 10
|
||||||
REG_NONE = 0
|
REG_NONE = 0
|
||||||
REG_SZ = 1
|
REG_SZ = 1
|
||||||
REG_EXPAND_SZ = 2
|
REG_EXPAND_SZ = 2
|
||||||
REG_BINARY = 3
|
REG_BINARY = 3
|
||||||
REG_DWORD = 4
|
REG_DWORD = 4
|
||||||
REG_DWORD_LITTLE_ENDIAN = 4
|
REG_DWORD_LITTLE_ENDIAN = 4
|
||||||
REG_DWORD_BIG_ENDIAN = 5
|
REG_DWORD_BIG_ENDIAN = 5
|
||||||
REG_LINK = 6
|
REG_LINK = 6
|
||||||
REG_MULTI_SZ = 7
|
REG_MULTI_SZ = 7
|
||||||
REG_RESOURCE_LIST = 8
|
REG_RESOURCE_LIST = 8
|
||||||
REG_FULL_RESOURCE_DESCRIPTOR = 9
|
REG_FULL_RESOURCE_DESCRIPTOR = 9
|
||||||
HKEY_CLASSES_ROOT = 0x80000000
|
HKEY_CLASSES_ROOT = 0x80000000
|
||||||
HKEY_CURRENT_USER = 0x80000001
|
HKEY_CURRENT_USER = 0x80000001
|
||||||
HKEY_LOCAL_MACHINE = 0x80000002
|
HKEY_LOCAL_MACHINE = 0x80000002
|
||||||
HKEY_USERS = 0x80000003
|
HKEY_USERS = 0x80000003
|
||||||
HKEY_PERFORMANCE_DATA = 0x80000004
|
HKEY_PERFORMANCE_DATA = 0x80000004
|
||||||
HKEY_PERFORMANCE_TEXT = 0x80000050
|
HKEY_PERFORMANCE_TEXT = 0x80000050
|
||||||
HKEY_PERFORMANCE_NLSTEXT = 0x80000060
|
HKEY_PERFORMANCE_NLSTEXT = 0x80000060
|
||||||
|
|
||||||
|
|
||||||
def listtree(handle, level=0):
|
def listtree(handle, level=0):
|
||||||
i = 0
|
i = 0
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
key = win32api.RegEnumKey(handle, i)
|
key = win32api.RegEnumKey(handle, i)
|
||||||
except win32api.error:
|
except win32api.error:
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
value = win32api.RegQueryValue(handle, key)
|
value = win32api.RegQueryValue(handle, key)
|
||||||
except win32api.error, msg:
|
except win32api.error, msg:
|
||||||
try:
|
try:
|
||||||
msg = msg[2]
|
msg = msg[2]
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
value = "*** Error: %s" % str(msg)
|
value = "*** Error: %s" % str(msg)
|
||||||
print " "*level + "%s: %s" % (key, value)
|
print " "*level + "%s: %s" % (key, value)
|
||||||
subhandle = win32api.RegOpenKey(handle, key)
|
subhandle = win32api.RegOpenKey(handle, key)
|
||||||
listtree(subhandle, level+1)
|
listtree(subhandle, level+1)
|
||||||
win32api.RegCloseKey(subhandle)
|
win32api.RegCloseKey(subhandle)
|
||||||
i = i+1
|
i = i+1
|
||||||
|
|
||||||
roothandle = win32con.HKEY_LOCAL_MACHINE
|
roothandle = win32con.HKEY_LOCAL_MACHINE
|
||||||
pythonkey = "Software\\Python"
|
pythonkey = "Software\\Python"
|
||||||
|
@ -156,11 +156,11 @@ except win32api.error, msg:
|
||||||
path = []
|
path = []
|
||||||
pwd = nt.getcwd()
|
pwd = nt.getcwd()
|
||||||
for i in ["Bin",
|
for i in ["Bin",
|
||||||
"Lib",
|
"Lib",
|
||||||
"Lib\\win",
|
"Lib\\win",
|
||||||
"Lib\\tkinter",
|
"Lib\\tkinter",
|
||||||
"Lib\\test",
|
"Lib\\test",
|
||||||
"Lib\\dos_8x3"]:
|
"Lib\\dos_8x3"]:
|
||||||
i = pwd + "\\" + i
|
i = pwd + "\\" + i
|
||||||
path.append(i)
|
path.append(i)
|
||||||
sys.path[1:] = path
|
sys.path[1:] = path
|
||||||
|
@ -181,9 +181,9 @@ try:
|
||||||
except win32api.error, msg:
|
except win32api.error, msg:
|
||||||
uihandle = win32api.RegCreateKey(roothandle, uninstallkey)
|
uihandle = win32api.RegCreateKey(roothandle, uninstallkey)
|
||||||
win32api.RegSetValueEx(uihandle, "DisplayName", None, win32con.REG_SZ,
|
win32api.RegSetValueEx(uihandle, "DisplayName", None, win32con.REG_SZ,
|
||||||
"Python "+sys.winver)
|
"Python "+sys.winver)
|
||||||
win32api.RegSetValueEx(uihandle, "UninstallString", None, win32con.REG_SZ,
|
win32api.RegSetValueEx(uihandle, "UninstallString", None, win32con.REG_SZ,
|
||||||
uninstaller)
|
uninstaller)
|
||||||
win32api.RegCloseKey(uihandle)
|
win32api.RegCloseKey(uihandle)
|
||||||
|
|
||||||
print "Registering Python Interpreter as shell for *.py files..."
|
print "Registering Python Interpreter as shell for *.py files..."
|
||||||
|
@ -195,7 +195,7 @@ sz = win32con.REG_SZ
|
||||||
win32api.RegSetValue(root, ".py", sz, "Python.Script")
|
win32api.RegSetValue(root, ".py", sz, "Python.Script")
|
||||||
win32api.RegSetValue(root , "Python.Script", sz, "Python Script")
|
win32api.RegSetValue(root , "Python.Script", sz, "Python Script")
|
||||||
win32api.RegSetValue(root , "Python.Script\\Shell\\Open\\Command", sz,
|
win32api.RegSetValue(root , "Python.Script\\Shell\\Open\\Command", sz,
|
||||||
interpreter)
|
interpreter)
|
||||||
|
|
||||||
import compileall
|
import compileall
|
||||||
print "Compiling all library modules..."
|
print "Compiling all library modules..."
|
||||||
|
@ -250,10 +250,10 @@ Most common functions:
|
||||||
Get the (unnamed) value stored as key in handle
|
Get the (unnamed) value stored as key in handle
|
||||||
RegSetValue(handle, subkey, type, value)
|
RegSetValue(handle, subkey, type, value)
|
||||||
Set the (unnamed) value stored as key in handle, with given
|
Set the (unnamed) value stored as key in handle, with given
|
||||||
type; type should be REG_SZ
|
type; type should be REG_SZ
|
||||||
RegSetValueEx(handle, name, reserved, type, value)
|
RegSetValueEx(handle, name, reserved, type, value)
|
||||||
Set the value with given name to the given type and value;
|
Set the value with given name to the given type and value;
|
||||||
currently reserved is ignored and type should be REG_SZ
|
currently reserved is ignored and type should be REG_SZ
|
||||||
|
|
||||||
Functions to list directory contents (start counting at 0, fail if done):
|
Functions to list directory contents (start counting at 0, fail if done):
|
||||||
RegEnumKey(handle, i)
|
RegEnumKey(handle, i)
|
||||||
|
|
|
@ -21,17 +21,17 @@ import win32con
|
||||||
def rmkey(parent, key, level=0):
|
def rmkey(parent, key, level=0):
|
||||||
sep = " "*level
|
sep = " "*level
|
||||||
try:
|
try:
|
||||||
handle = win32api.RegOpenKey(parent, key)
|
handle = win32api.RegOpenKey(parent, key)
|
||||||
except win32api.error, msg:
|
except win32api.error, msg:
|
||||||
print sep + "No key", `key`
|
print sep + "No key", `key`
|
||||||
return
|
return
|
||||||
print sep + "Removing key", key
|
print sep + "Removing key", key
|
||||||
while 1:
|
while 1:
|
||||||
try:
|
try:
|
||||||
subkey = win32api.RegEnumKey(handle, 0)
|
subkey = win32api.RegEnumKey(handle, 0)
|
||||||
except win32api.error, msg:
|
except win32api.error, msg:
|
||||||
break
|
break
|
||||||
rmkey(handle, subkey, level+1)
|
rmkey(handle, subkey, level+1)
|
||||||
win32api.RegCloseKey(handle)
|
win32api.RegCloseKey(handle)
|
||||||
win32api.RegDeleteKey(parent, key)
|
win32api.RegDeleteKey(parent, key)
|
||||||
print sep + "Done with", key
|
print sep + "Done with", key
|
||||||
|
@ -47,25 +47,25 @@ def rmtree(dir, level=0):
|
||||||
sep = " "*level
|
sep = " "*level
|
||||||
print sep+"rmtree", dir
|
print sep+"rmtree", dir
|
||||||
for name in os.listdir(dir):
|
for name in os.listdir(dir):
|
||||||
if level == 0 and \
|
if level == 0 and \
|
||||||
os.path.normcase(name) == os.path.normcase("uninstall.bat"):
|
os.path.normcase(name) == os.path.normcase("uninstall.bat"):
|
||||||
continue
|
continue
|
||||||
fn = os.path.join(dir, name)
|
fn = os.path.join(dir, name)
|
||||||
if os.path.isdir(fn):
|
if os.path.isdir(fn):
|
||||||
rmtree(fn, level+1)
|
rmtree(fn, level+1)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
os.remove(fn)
|
os.remove(fn)
|
||||||
except os.error, msg:
|
except os.error, msg:
|
||||||
print sep+" can't remove", `fn`, msg
|
print sep+" can't remove", `fn`, msg
|
||||||
else:
|
else:
|
||||||
print sep+" removed", `fn`
|
print sep+" removed", `fn`
|
||||||
try:
|
try:
|
||||||
os.rmdir(dir)
|
os.rmdir(dir)
|
||||||
except os.error, msg:
|
except os.error, msg:
|
||||||
print sep+"can't remove directory", `dir`, msg
|
print sep+"can't remove directory", `dir`, msg
|
||||||
else:
|
else:
|
||||||
print sep+"removed directory", `dir`
|
print sep+"removed directory", `dir`
|
||||||
|
|
||||||
pwd = os.getcwd()
|
pwd = os.getcwd()
|
||||||
scriptdir = os.path.normpath(os.path.join(pwd, os.path.dirname(sys.argv[0])))
|
scriptdir = os.path.normpath(os.path.join(pwd, os.path.dirname(sys.argv[0])))
|
||||||
|
|
Loading…
Reference in New Issue