def _CreateWrapper(tlib, pathname=None): # helper which creates and imports the real typelib wrapper module. fullname = _name_module(tlib) try: return sys.modules[fullname] except KeyError: pass modname = fullname.split(".")[-1] try: return _my_import(fullname) except Exception as details: logger.info("Could not import %s: %s", fullname, details) # generate the module since it doesn't exist or is out of date from comtypes.tools.tlbparser import generate_module if comtypes.client.gen_dir is None: import io ofi = io.StringIO() else: ofi = open(os.path.join(comtypes.client.gen_dir, modname + ".py"), "w") # XXX use logging! logger.info("# Generating comtypes.gen.%s", modname) generate_module(tlib, ofi, pathname) if comtypes.client.gen_dir is None: code = ofi.getvalue() mod = types.ModuleType(fullname) mod.__file__ = os.path.join(os.path.abspath(comtypes.gen.__path__[0]), "<memory>") exec(code, mod.__dict__) sys.modules[fullname] = mod setattr(comtypes.gen, modname, mod) else: ofi.close() # clear the import cache to make sure Python sees newly created modules if hasattr(importlib, "invalidate_caches"): importlib.invalidate_caches() mod = _my_import(fullname) return mod
def _CreateWrapper(tlib, pathname=None): # helper which creates and imports the real typelib wrapper module. fullname = _name_module(tlib) try: return sys.modules[fullname] except KeyError: pass modname = fullname.split(".")[-1] try: return _my_import(fullname) except Exception as details: logger.info("Could not import %s: %s", fullname, details) # generate the module since it doesn't exist or is out of date from comtypes.tools.tlbparser import generate_module if comtypes.client.gen_dir is None: import io ofi = io.StringIO() else: ofi = open(os.path.join(comtypes.client.gen_dir, modname + ".py"), "w") # XXX use logging! if __verbose__: print("# Generating comtypes.gen.%s" % modname) generate_module(tlib, ofi, pathname) if comtypes.client.gen_dir is None: code = ofi.getvalue() mod = types.ModuleType(fullname) mod.__file__ = os.path.join(os.path.abspath(comtypes.gen.__path__[0]), "<memory>") exec(code, mod.__dict__) sys.modules[fullname] = mod setattr(comtypes.gen, modname, mod) else: ofi.close() mod = _my_import(fullname) return mod
try: return _my_import(fullname) except Exception, details: logger.info("Could not import %s: %s", fullname, details) # generate the module since it doesn't exist or is out of date from comtypes.tools.tlbparser import generate_module if comtypes.client.gen_dir is None: import cStringIO ofi = cStringIO.StringIO() else: ofi = open(os.path.join(comtypes.client.gen_dir, modname + ".py"), "w") # XXX use logging! logger.info("# Generating comtypes.gen.%s", modname) generate_module(tlib, ofi, pathname) if comtypes.client.gen_dir is None: code = ofi.getvalue() mod = types.ModuleType(fullname) mod.__file__ = os.path.join(os.path.abspath(list(comtypes.gen.__path__)[0]), "<memory>") exec code in mod.__dict__ sys.modules[fullname] = mod setattr(comtypes.gen, modname, mod) else: ofi.close() mod = _my_import(fullname) return mod ################################################################
try: return _my_import(fullname) except Exception, details: logger.info("Could not import %s: %s", fullname, details) # generate the module since it doesn't exist or is out of date from comtypes.tools.tlbparser import generate_module if comtypes.client.gen_dir is None: import cStringIO ofi = cStringIO.StringIO() else: ofi = open(os.path.join(comtypes.client.gen_dir, modname + ".py"), "w") # XXX use logging! logger.info("# Generating comtypes.gen.%s", modname) generate_module(tlib, ofi, pathname) if comtypes.client.gen_dir is None: code = ofi.getvalue() mod = types.ModuleType(fullname) mod.__file__ = os.path.join(os.path.abspath(comtypes.gen.__path__[0]), "<memory>") exec code in mod.__dict__ sys.modules[fullname] = mod setattr(comtypes.gen, modname, mod) else: ofi.close() mod = _my_import(fullname) return mod