Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

regcheck.py 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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(
  5. "The regcheck module has been pending deprecation since build 210",
  6. category=PendingDeprecationWarning,
  7. )
  8. import os
  9. import sys
  10. import regutil
  11. import win32api
  12. import win32con
  13. def CheckRegisteredExe(exename):
  14. try:
  15. os.stat(
  16. win32api.RegQueryValue(
  17. regutil.GetRootKey(), regutil.GetAppPathsKey() + "\\" + exename
  18. )
  19. )
  20. # except SystemError:
  21. except (os.error, win32api.error):
  22. print("Registration of %s - Not registered correctly" % exename)
  23. def CheckPathString(pathString):
  24. for path in pathString.split(";"):
  25. if not os.path.isdir(path):
  26. return "'%s' is not a valid directory!" % path
  27. return None
  28. def CheckPythonPaths(verbose):
  29. if verbose:
  30. print("Python Paths:")
  31. # Check the core path
  32. if verbose:
  33. print("\tCore Path:", end=" ")
  34. try:
  35. appPath = win32api.RegQueryValue(
  36. regutil.GetRootKey(), regutil.BuildDefaultPythonKey() + "\\PythonPath"
  37. )
  38. except win32api.error as exc:
  39. print("** does not exist - ", exc.strerror)
  40. problem = CheckPathString(appPath)
  41. if problem:
  42. print(problem)
  43. else:
  44. if verbose:
  45. print(appPath)
  46. key = win32api.RegOpenKey(
  47. regutil.GetRootKey(),
  48. regutil.BuildDefaultPythonKey() + "\\PythonPath",
  49. 0,
  50. win32con.KEY_READ,
  51. )
  52. try:
  53. keyNo = 0
  54. while 1:
  55. try:
  56. appName = win32api.RegEnumKey(key, keyNo)
  57. appPath = win32api.RegQueryValue(key, appName)
  58. if verbose:
  59. print("\t" + appName + ":", end=" ")
  60. if appPath:
  61. problem = CheckPathString(appPath)
  62. if problem:
  63. print(problem)
  64. else:
  65. if verbose:
  66. print(appPath)
  67. else:
  68. if verbose:
  69. print("(empty)")
  70. keyNo = keyNo + 1
  71. except win32api.error:
  72. break
  73. finally:
  74. win32api.RegCloseKey(key)
  75. def CheckHelpFiles(verbose):
  76. if verbose:
  77. print("Help Files:")
  78. try:
  79. key = win32api.RegOpenKey(
  80. regutil.GetRootKey(),
  81. regutil.BuildDefaultPythonKey() + "\\Help",
  82. 0,
  83. win32con.KEY_READ,
  84. )
  85. except win32api.error as exc:
  86. import winerror
  87. if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  88. raise
  89. return
  90. try:
  91. keyNo = 0
  92. while 1:
  93. try:
  94. helpDesc = win32api.RegEnumKey(key, keyNo)
  95. helpFile = win32api.RegQueryValue(key, helpDesc)
  96. if verbose:
  97. print("\t" + helpDesc + ":", end=" ")
  98. # query the os section.
  99. try:
  100. os.stat(helpFile)
  101. if verbose:
  102. print(helpFile)
  103. except os.error:
  104. print("** Help file %s does not exist" % helpFile)
  105. keyNo = keyNo + 1
  106. except win32api.error as exc:
  107. import winerror
  108. if exc.winerror != winerror.ERROR_NO_MORE_ITEMS:
  109. raise
  110. break
  111. finally:
  112. win32api.RegCloseKey(key)
  113. def CheckRegisteredModules(verbose):
  114. # Check out all registered modules.
  115. k = regutil.BuildDefaultPythonKey() + "\\Modules"
  116. try:
  117. keyhandle = win32api.RegOpenKey(regutil.GetRootKey(), k)
  118. print("WARNING: 'Modules' registry entry is deprectated and evil!")
  119. except win32api.error as exc:
  120. import winerror
  121. if exc.winerror != winerror.ERROR_FILE_NOT_FOUND:
  122. raise
  123. return
  124. def CheckRegistry(verbose=0):
  125. # check the registered modules
  126. if verbose and "pythonpath" in os.environ:
  127. print("Warning - PythonPath in environment - please check it!")
  128. # Check out all paths on sys.path
  129. CheckPythonPaths(verbose)
  130. CheckHelpFiles(verbose)
  131. CheckRegisteredModules(verbose)
  132. CheckRegisteredExe("Python.exe")
  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)