regcheck.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # This module is very old and useless in this day and age! It will be
  2. # removed in a few years (ie, 2009 or so...)
  3. import warnings
  4. warnings.warn("The regcheck module has been pending deprecation since build 210",
  5. category=PendingDeprecationWarning)
  6. import win32con
  7. import regutil
  8. import win32api
  9. import os
  10. import sys
  11. def CheckRegisteredExe(exename):
  12. try:
  13. os.stat(win32api.RegQueryValue(regutil.GetRootKey() , regutil.GetAppPathsKey() + "\\" + exename))
  14. # except SystemError:
  15. except (os.error,win32api.error):
  16. print("Registration of %s - Not registered correctly" % exename)
  17. def CheckPathString(pathString):
  18. for path in pathString.split(";"):
  19. if not os.path.isdir(path):
  20. return "'%s' is not a valid directory!" % path
  21. return None
  22. def CheckPythonPaths(verbose):
  23. if verbose: print("Python Paths:")
  24. # Check the core path
  25. if verbose: print("\tCore Path:", end=' ')
  26. try:
  27. appPath = win32api.RegQueryValue(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath")
  28. except win32api.error as exc:
  29. print("** does not exist - ", exc.strerror)
  30. problem = CheckPathString(appPath)
  31. if problem:
  32. print(problem)
  33. else:
  34. if verbose: print(appPath)
  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+":", end=' ')
  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. def CheckHelpFiles(verbose):
  57. if verbose: print("Help Files:")
  58. try:
  59. key = win32api.RegOpenKey(regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\Help", 0, win32con.KEY_READ)
  60. except win32api.error as exc:
  61. import winerror
  62. if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
  63. raise
  64. return
  65. try:
  66. keyNo = 0
  67. while 1:
  68. try:
  69. helpDesc = win32api.RegEnumKey(key, keyNo)
  70. helpFile = win32api.RegQueryValue(key, helpDesc)
  71. if verbose: print("\t"+helpDesc+":", end=' ')
  72. # query the os section.
  73. try:
  74. os.stat(helpFile )
  75. if verbose: print(helpFile)
  76. except os.error:
  77. print("** Help file %s does not exist" % helpFile)
  78. keyNo = keyNo + 1
  79. except win32api.error as exc:
  80. import winerror
  81. if exc.winerror!=winerror.ERROR_NO_MORE_ITEMS:
  82. raise
  83. break
  84. finally:
  85. win32api.RegCloseKey(key)
  86. def CheckRegisteredModules(verbose):
  87. # Check out all registered modules.
  88. k=regutil.BuildDefaultPythonKey() + "\\Modules"
  89. try:
  90. keyhandle = win32api.RegOpenKey(regutil.GetRootKey(), k)
  91. print("WARNING: 'Modules' registry entry is deprectated and evil!")
  92. except win32api.error as exc:
  93. import winerror
  94. if exc.winerror!=winerror.ERROR_FILE_NOT_FOUND:
  95. raise
  96. return
  97. def CheckRegistry(verbose=0):
  98. # check the registered modules
  99. if verbose and 'pythonpath' in os.environ:
  100. print("Warning - PythonPath in environment - please check it!")
  101. # Check out all paths on sys.path
  102. CheckPythonPaths(verbose)
  103. CheckHelpFiles(verbose)
  104. CheckRegisteredModules(verbose)
  105. CheckRegisteredExe("Python.exe")
  106. if __name__=='__main__':
  107. if len(sys.argv)>1 and sys.argv[1]=='-q':
  108. verbose = 0
  109. else:
  110. verbose = 1
  111. CheckRegistry(verbose)