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.

setup_d.py 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Install and register pythonxx_d.dll, pywintypesxx_d.dll and pythoncomxx_d.dll
  2. #
  3. # Assumes the _d files can be found in the same directory as this script
  4. # or in the cwd.
  5. import os
  6. import shutil
  7. import sys
  8. import winreg
  9. import win32api
  10. def usage_and_die(rc):
  11. print()
  12. print("This script is designed to copy and register the Python debug")
  13. print("binaries. It looks for pythonxx_d.dll, pythoncomxx_d.dll etc,")
  14. print("and installs them to work correctly with Python debug builds.")
  15. print()
  16. print("You will generally find this script in the. zip file that")
  17. print("included these _d files. Please run this script from")
  18. print("that directory")
  19. sys.exit(rc)
  20. if win32api.__file__.find("_d") > 0:
  21. print("This scripts appears to be running a DEBUG version of Python.")
  22. print("Please run it using a normal release build (python.exe)")
  23. usage_and_die(1)
  24. try:
  25. import pythoncom
  26. except ImportError as details:
  27. print("Could not import the release version of pythoncom")
  28. print("The error details are: %s" % (details,))
  29. print("Please correct this error and rerun the script")
  30. usage_and_die(2)
  31. try:
  32. import pywintypes
  33. except ImportError as details:
  34. print("Could not import the release version of pywintypes")
  35. print("The error details are: %s" % (details,))
  36. print("Please correct this error and rerun the script")
  37. usage_and_die(2)
  38. def _docopy(src, dest):
  39. orig_src = src
  40. if not os.path.isfile(src):
  41. src = os.path.join(os.path.split(sys.argv[0])[0], src)
  42. print(
  43. "Can not find %s or %s to copy"
  44. % (os.path.abspath(orig_src), os.path.abspath(src))
  45. )
  46. return 0
  47. try:
  48. shutil.copy(src, dest)
  49. print("Copied %s -> %s" % (src, dest))
  50. return 1
  51. except:
  52. print("Error copying '%s' -> '%s'" % (src, dest))
  53. print(str(sys.exc_info[1]))
  54. usage_and_die(3)
  55. def _doregister(mod_name, dll_name):
  56. assert os.path.isfile(dll_name), "Shouldn't get here if the file doesn't exist!"
  57. try:
  58. key = winreg.OpenKey(
  59. winreg.HKEY_LOCAL_MACHINE,
  60. "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, mod_name),
  61. )
  62. except winreg.error:
  63. try:
  64. key = winreg.OpenKey(
  65. winreg.HKEY_LOCAL_MACHINE,
  66. "Software\\Python\\PythonCore\\%s\\Modules\\%s"
  67. % (sys.winver, mod_name),
  68. )
  69. except winreg.error:
  70. print(
  71. "Could not find the existing '%s' module registered in the registry"
  72. % (mod_name,)
  73. )
  74. usage_and_die(4)
  75. # Create the debug key.
  76. sub_key = winreg.CreateKey(key, "Debug")
  77. winreg.SetValue(sub_key, None, winreg.REG_SZ, dll_name)
  78. print("Registered '%s' in the registry" % (dll_name,))
  79. def _domodule(mod_name, release_mod_filename):
  80. path, fname = os.path.split(release_mod_filename)
  81. base, ext = os.path.splitext(fname)
  82. new_fname = base + "_d" + ext
  83. if _docopy(new_fname, path):
  84. _doregister(mod_name, os.path.abspath(os.path.join(path, new_fname)))
  85. # First the main Python DLL.
  86. path, fname = path, fname = os.path.split(win32api.GetModuleFileName(sys.dllhandle))
  87. base, ext = os.path.splitext(fname)
  88. _docopy(base + "_d" + ext, path)
  89. # Then pythoncom and pywintypes.
  90. _domodule("pythoncom", pythoncom.__file__)
  91. _domodule("pywintypes", pywintypes.__file__)
  92. print("System _d files were setup.")