2016-02-13 17:06:36 -06:00
|
|
|
from pywintypes import com_error
|
2016-04-05 12:44:35 -05:00
|
|
|
import win32com
|
|
|
|
import paths
|
2016-06-02 17:42:44 -05:00
|
|
|
win32com.__gen_path__=paths.com_path()
|
2016-04-05 12:44:35 -05:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
sys.path.append(os.path.join(win32com.__gen_path__, "."))
|
2016-02-13 17:06:36 -06:00
|
|
|
from win32com.client import gencache
|
2016-04-05 12:44:35 -05:00
|
|
|
fixed=False
|
2016-02-13 17:06:36 -06:00
|
|
|
|
|
|
|
def prepare_gencache():
|
|
|
|
gencache.is_readonly = False
|
|
|
|
gencache.GetGeneratePath()
|
|
|
|
|
2016-04-05 12:44:35 -05:00
|
|
|
def patched_getmodule(modname):
|
|
|
|
mod=__import__(modname)
|
|
|
|
return sys.modules[modname]
|
2016-02-13 17:06:36 -06:00
|
|
|
|
|
|
|
def load_com(*names):
|
2016-04-05 12:44:35 -05:00
|
|
|
global fixed
|
|
|
|
if fixed==False:
|
|
|
|
gencache._GetModule=patched_getmodule
|
|
|
|
fixed=True
|
2016-02-13 17:06:36 -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
|
|
|
|
|
2016-06-02 17:42:44 -05:00
|
|
|
|
|
|
|
def preexec():
|
|
|
|
global fixed
|
|
|
|
if fixed==False:
|
|
|
|
gencache._GetModule=patched_getmodule
|
|
|
|
fixed=True
|