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.

__init__.py 4.8KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #
  2. # Initialization for the win32com package
  3. #
  4. import os
  5. import sys
  6. import pythoncom
  7. import win32api
  8. # flag if we are in a "frozen" build.
  9. _frozen = getattr(sys, "frozen", 1 == 0)
  10. # pythoncom dumbly defaults this to zero - we believe sys.frozen over it.
  11. if _frozen and not getattr(pythoncom, "frozen", 0):
  12. pythoncom.frozen = sys.frozen
  13. # Add support for an external "COM Extensions" path.
  14. # Concept is that you can register a seperate path to be used for
  15. # COM extensions, outside of the win32com directory. These modules, however,
  16. # look identical to win32com built-in modules.
  17. # This is the technique that we use for the "standard" COM extensions.
  18. # eg "win32com.mapi" or "win32com.axscript" both work, even though they do not
  19. # live under the main win32com directory.
  20. __gen_path__ = ""
  21. __build_path__ = None
  22. ### TODO - Load _all_ \\Extensions subkeys - for now, we only read the default
  23. ### Modules will work if loaded into "win32comext" path.
  24. def SetupEnvironment():
  25. HKEY_LOCAL_MACHINE = -2147483646 # Avoid pulling in win32con for just these...
  26. KEY_QUERY_VALUE = 0x1
  27. # Open the root key once, as this is quite slow on NT.
  28. try:
  29. keyName = "SOFTWARE\\Python\\PythonCore\\%s\\PythonPath\\win32com" % sys.winver
  30. key = win32api.RegOpenKey(HKEY_LOCAL_MACHINE, keyName, 0, KEY_QUERY_VALUE)
  31. except (win32api.error, AttributeError):
  32. key = None
  33. try:
  34. found = 0
  35. if key is not None:
  36. try:
  37. __path__.append(win32api.RegQueryValue(key, "Extensions"))
  38. found = 1
  39. except win32api.error:
  40. # Nothing registered
  41. pass
  42. if not found:
  43. try:
  44. __path__.append(
  45. win32api.GetFullPathName(__path__[0] + "\\..\\win32comext")
  46. )
  47. except win32api.error:
  48. # Give up in disgust!
  49. pass
  50. # For the sake of developers, we also look up a "BuildPath" key
  51. # If extension modules add support, we can load their .pyd's from a completely
  52. # different directory (see the comments below)
  53. try:
  54. if key is not None:
  55. global __build_path__
  56. __build_path__ = win32api.RegQueryValue(key, "BuildPath")
  57. __path__.append(__build_path__)
  58. except win32api.error:
  59. # __build_path__ neednt be defined.
  60. pass
  61. global __gen_path__
  62. if key is not None:
  63. try:
  64. __gen_path__ = win32api.RegQueryValue(key, "GenPath")
  65. except win32api.error:
  66. pass
  67. finally:
  68. if key is not None:
  69. key.Close()
  70. # A Helper for developers. A sub-package's __init__ can call this help function,
  71. # which allows the .pyd files for the extension to live in a special "Build" directory
  72. # (which the win32com developers do!)
  73. def __PackageSupportBuildPath__(package_path):
  74. # See if we have a special directory for the binaries (for developers)
  75. if not _frozen and __build_path__:
  76. package_path.append(__build_path__)
  77. if not _frozen:
  78. SetupEnvironment()
  79. # If we don't have a special __gen_path__, see if we have a gen_py as a
  80. # normal module and use that (ie, "win32com.gen_py" may already exist as
  81. # a package.
  82. if not __gen_path__:
  83. try:
  84. import win32com.gen_py
  85. # hrmph - 3.3 throws: TypeError: '_NamespacePath' object does not support indexing
  86. # attempting to get __path__[0] - but I can't quickly repro this stand-alone.
  87. # Work around it by using an iterator.
  88. __gen_path__ = next(iter(sys.modules["win32com.gen_py"].__path__))
  89. except ImportError:
  90. # If a win32com\gen_py directory already exists, then we use it
  91. # (gencache doesn't insist it have an __init__, but our __import__
  92. # above does!
  93. __gen_path__ = os.path.abspath(os.path.join(__path__[0], "gen_py"))
  94. if not os.path.isdir(__gen_path__):
  95. # We used to dynamically create a directory under win32com -
  96. # but this sucks. If the dir doesn't already exist, we we
  97. # create a version specific directory under the user temp
  98. # directory.
  99. __gen_path__ = os.path.join(
  100. win32api.GetTempPath(),
  101. "gen_py",
  102. "%d.%d" % (sys.version_info[0], sys.version_info[1]),
  103. )
  104. # we must have a __gen_path__, but may not have a gen_py module -
  105. # set that up.
  106. if "win32com.gen_py" not in sys.modules:
  107. # Create a "win32com.gen_py", but with a custom __path__
  108. import types
  109. gen_py = types.ModuleType("win32com.gen_py")
  110. gen_py.__path__ = [__gen_path__]
  111. sys.modules[gen_py.__name__] = gen_py
  112. del types
  113. gen_py = sys.modules["win32com.gen_py"]
  114. # get rid of these for module users
  115. del os, sys, win32api, pythoncom