2014-10-27 16:29:04 -06:00
|
|
|
from pywintypes import com_error
|
2015-10-18 12:19:43 +02:00
|
|
|
import win32com
|
|
|
|
import paths
|
|
|
|
win32com.__gen_path__=paths.data_path("com_cache")
|
2015-10-18 22:18:43 +02:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
sys.path.append(os.path.join(win32com.__gen_path__, "."))
|
2014-10-27 16:29:04 -06:00
|
|
|
from win32com.client import gencache
|
2015-10-18 22:18:43 +02:00
|
|
|
fixed=False
|
2014-10-27 16:29:04 -06:00
|
|
|
|
|
|
|
def prepare_gencache():
|
|
|
|
gencache.is_readonly = False
|
|
|
|
gencache.GetGeneratePath()
|
|
|
|
|
2015-10-18 22:18:43 +02:00
|
|
|
def patched_getmodule(modname):
|
|
|
|
mod=__import__(modname)
|
|
|
|
return sys.modules[modname]
|
2014-10-27 16:29:04 -06:00
|
|
|
|
|
|
|
def load_com(*names):
|
2015-10-18 22:18:43 +02:00
|
|
|
global fixed
|
|
|
|
if fixed==False:
|
|
|
|
gencache._GetModule=patched_getmodule
|
|
|
|
fixed=True
|
2014-10-27 16:29:04 -06:00
|
|
|
result = None
|
|
|
|
for name in names:
|
|
|
|
try:
|
|
|
|
result = gencache.EnsureDispatch(name)
|
|
|
|
break
|
|
|
|
except com_error:
|
|
|
|
continue
|
|
|
|
if result is None:
|
|
|
|
raise com_error("Unable to load any of the provided com objects.")
|
|
|
|
return result
|
|
|
|
|