home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Shareware / Comunicatii / jyte / jyte.exe / regcheck.py < prev    next >
Text File  |  2002-01-08  |  4KB  |  139 lines

  1. import win32con
  2. import regutil
  3. import win32api
  4. import os
  5. import sys
  6.  
  7. def CheckRegisteredExe(exename):
  8.     try:
  9.         os.stat(win32api.RegQueryValue(regutil.GetRootKey()  , regutil.GetAppPathsKey() + "\\" + exename))
  10. #    except SystemError:
  11.     except (os.error,win32api.error):
  12.         print "Registration of %s - Not registered correctly" % exename
  13.  
  14. def CheckPathString(pathString):
  15.     import string
  16.     for path in string.split(pathString, ";"):
  17.         if not os.path.isdir(path):
  18.             return "'%s' is not a valid directory!" % path
  19.     return None
  20.  
  21. def CheckPythonPaths(verbose):
  22.     if verbose: print "Python Paths:"
  23.     # Check the core path
  24.     if verbose: print "\tCore Path:",
  25.     try:
  26.         appPath = win32api.RegQueryValue(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath")
  27.     except win32api.error, (code, fn, desc):
  28.         print "** does not exist - ", desc
  29.     problem = CheckPathString(appPath)
  30.     if problem:
  31.         print problem
  32.     else:
  33.         if verbose: print appPath
  34.     
  35.     key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath", 0, win32con.KEY_READ)
  36.     try:
  37.         keyNo = 0
  38.         while 1:
  39.             try:
  40.                 appName = win32api.RegEnumKey(key, keyNo)
  41.                 appPath = win32api.RegQueryValue(key, appName)
  42.                 if verbose: print "\t"+appName+":",
  43.                 if appPath:
  44.                     problem = CheckPathString(appPath)
  45.                     if problem:
  46.                         print problem
  47.                     else:
  48.                         if verbose: print appPath
  49.                 else:
  50.                     if verbose: print "(empty)"
  51.                 keyNo = keyNo + 1
  52.             except win32api.error:
  53.                 break
  54.     finally:
  55.         win32api.RegCloseKey(key)
  56.  
  57. def CheckHelpFiles(verbose):
  58.     if verbose: print "Help Files:"
  59.     try:
  60.         key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
  61.     except win32api.error, (code, fn, details):
  62.         import winerror
  63.         if code!=winerror.ERROR_FILE_NOT_FOUND:
  64.             raise win32api.error, (code, fn, details)
  65.         return
  66.         
  67.     try:
  68.         keyNo = 0
  69.         while 1:
  70.             try:
  71.                 helpDesc = win32api.RegEnumKey(key, keyNo)
  72.                 helpFile = win32api.RegQueryValue(key, helpDesc)
  73.                 if verbose: print "\t"+helpDesc+":",
  74.                 # query the os section.
  75.                 try:
  76.                     os.stat(helpFile )
  77.                     if verbose: print helpFile
  78.                 except os.error:
  79.                     print "** Help file %s does not exist" % helpFile
  80.                 keyNo = keyNo + 1
  81.             except win32api.error, (code, fn, desc):
  82.                 import winerror
  83.                 if code!=winerror.ERROR_NO_MORE_ITEMS:
  84.                     raise win32api.error, (code, fn, desc)
  85.                 break
  86.     finally:
  87.         win32api.RegCloseKey(key)
  88.  
  89. def ChcekRegisteredModules(verbose):
  90.     # Check out all registered modules.
  91.     k=regutil.BuildDefaultPythonKey() + "\\Modules"
  92.     try:
  93.         keyhandle = win32api.RegOpenKey(regutil.GetRootKey(), k)
  94.     except win32api.error, (code, fn, details):
  95.         import winerror
  96.         if code!=winerror.ERROR_FILE_NOT_FOUND:
  97.             raise win32api.error, (code, fn, details)
  98.         return
  99.     try:
  100.         if verbose: print "Registered Modules:"
  101.         num = 0
  102.         while 1:
  103.             try:
  104.                 key = win32api.RegEnumKey(keyhandle, num)
  105.             except win32api.error:
  106.                 break;
  107.             num = num+1
  108.             value = win32api.RegQueryValue(keyhandle, key)
  109.             if verbose: print "\t%s:" % key,
  110.             try:
  111.                 os.stat(value)
  112.                 if verbose: print value
  113.             except os.error:
  114.                 if not verbose:
  115.                     print "Error is registered module %s" % value, 
  116.                 print "** Not found at %s" % value
  117.     finally:
  118.         win32api.RegCloseKey(keyhandle)
  119.  
  120.  
  121. def CheckRegistry(verbose=0):
  122.     # check the registered modules
  123.     if os.environ.has_key('pythonpath'):
  124.         print "Warning - PythonPath in environment - registry PythonPath will be ignored"
  125.     # Check out all paths on sys.path
  126.     
  127.     CheckPythonPaths(verbose)
  128.     CheckHelpFiles(verbose)
  129.     ChcekRegisteredModules(verbose)
  130.     CheckRegisteredExe("Python.exe")
  131.     CheckRegisteredExe("Pythonwin.exe")
  132.  
  133. if __name__=='__main__':
  134.     if len(sys.argv)>1 and sys.argv[1]=='-q':
  135.         verbose = 0
  136.     else:
  137.         verbose = 1
  138.     CheckRegistry(verbose)
  139.