PyXR

c:\python24\lib\site-packages\win32\lib \ regcheck.py



0001 import win32con
0002 import regutil
0003 import win32api
0004 import os
0005 import sys
0006 
0007 def CheckRegisteredExe(exename):
0008         try:
0009                 os.stat(win32api.RegQueryValue(regutil.GetRootKey()  , regutil.GetAppPathsKey() + "\\" + exename))
0010 # except SystemError:
0011         except (os.error,win32api.error):
0012                 print "Registration of %s - Not registered correctly" % exename
0013 
0014 def CheckPathString(pathString):
0015         import string
0016         for path in string.split(pathString, ";"):
0017                 if not os.path.isdir(path):
0018                         return "'%s' is not a valid directory!" % path
0019         return None
0020 
0021 def CheckPythonPaths(verbose):
0022         if verbose: print "Python Paths:"
0023         # Check the core path
0024         if verbose: print "\tCore Path:",
0025         try:
0026                 appPath = win32api.RegQueryValue(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath")
0027         except win32api.error, (code, fn, desc):
0028                 print "** does not exist - ", desc
0029         problem = CheckPathString(appPath)
0030         if problem:
0031                 print problem
0032         else:
0033                 if verbose: print appPath
0034         
0035         key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath", 0, win32con.KEY_READ)
0036         try:
0037                 keyNo = 0
0038                 while 1:
0039                         try:
0040                                 appName = win32api.RegEnumKey(key, keyNo)
0041                                 appPath = win32api.RegQueryValue(key, appName)
0042                                 if verbose: print "\t"+appName+":",
0043                                 if appPath:
0044                                         problem = CheckPathString(appPath)
0045                                         if problem:
0046                                                 print problem
0047                                         else:
0048                                                 if verbose: print appPath
0049                                 else:
0050                                         if verbose: print "(empty)"
0051                                 keyNo = keyNo + 1
0052                         except win32api.error:
0053                                 break
0054         finally:
0055                 win32api.RegCloseKey(key)
0056 
0057 def CheckHelpFiles(verbose):
0058         if verbose: print "Help Files:"
0059         try:
0060                 key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
0061         except win32api.error, (code, fn, details):
0062                 import winerror
0063                 if code!=winerror.ERROR_FILE_NOT_FOUND:
0064                         raise win32api.error, (code, fn, details)
0065                 return
0066                 
0067         try:
0068                 keyNo = 0
0069                 while 1:
0070                         try:
0071                                 helpDesc = win32api.RegEnumKey(key, keyNo)
0072                                 helpFile = win32api.RegQueryValue(key, helpDesc)
0073                                 if verbose: print "\t"+helpDesc+":",
0074                                 # query the os section.
0075                                 try:
0076                                         os.stat(helpFile )
0077                                         if verbose: print helpFile
0078                                 except os.error:
0079                                         print "** Help file %s does not exist" % helpFile
0080                                 keyNo = keyNo + 1
0081                         except win32api.error, (code, fn, desc):
0082                                 import winerror
0083                                 if code!=winerror.ERROR_NO_MORE_ITEMS:
0084                                         raise win32api.error, (code, fn, desc)
0085                                 break
0086         finally:
0087                 win32api.RegCloseKey(key)
0088 
0089 def ChcekRegisteredModules(verbose):
0090         # Check out all registered modules.
0091         k=regutil.BuildDefaultPythonKey() + "\\Modules"
0092         try:
0093                 keyhandle = win32api.RegOpenKey(regutil.GetRootKey(), k)
0094         except win32api.error, (code, fn, details):
0095                 import winerror
0096                 if code!=winerror.ERROR_FILE_NOT_FOUND:
0097                         raise win32api.error, (code, fn, details)
0098                 return
0099         try:
0100                 if verbose: print "Registered Modules:"
0101                 num = 0
0102                 while 1:
0103                         try:
0104                                 key = win32api.RegEnumKey(keyhandle, num)
0105                         except win32api.error:
0106                                 break;
0107                         num = num+1
0108                         value = win32api.RegQueryValue(keyhandle, key)
0109                         if verbose: print "\t%s:" % key,
0110                         try:
0111                                 os.stat(value)
0112                                 if verbose: print value
0113                         except os.error:
0114                                 if not verbose:
0115                                         print "Error is registered module %s" % value, 
0116                                 print "** Not found at %s" % value
0117         finally:
0118                 win32api.RegCloseKey(keyhandle)
0119 
0120 
0121 def CheckRegistry(verbose=0):
0122         # check the registered modules
0123         if os.environ.has_key('pythonpath'):
0124                 print "Warning - PythonPath in environment - registry PythonPath will be ignored"
0125         # Check out all paths on sys.path
0126         
0127         CheckPythonPaths(verbose)
0128         CheckHelpFiles(verbose)
0129         ChcekRegisteredModules(verbose)
0130         CheckRegisteredExe("Python.exe")
0131         CheckRegisteredExe("Pythonwin.exe")
0132 
0133 if __name__=='__main__':
0134         if len(sys.argv)>1 and sys.argv[1]=='-q':
0135                 verbose = 0
0136         else:
0137                 verbose = 1
0138         CheckRegistry(verbose)
0139 

Generated by PyXR 0.9.4
SourceForge.net Logo