def GenerateChildFromTypeLibSpec(child, typelibInfo, verboseLevel = None, progressInstance = None, bUnicodeToString=None): assert bUnicodeToString is None, "this is deprecated and will go away" if verboseLevel is None: verboseLevel = 0 # By default, we use no gui, and no verbose level for the children. if type(typelibInfo)==type(()): typelibCLSID, lcid, major, minor = typelibInfo tlb = pythoncom.LoadRegTypeLib(typelibCLSID, major, minor, lcid) else: tlb = typelibInfo tla = typelibInfo.GetLibAttr() typelibCLSID = tla[0] lcid = tla[1] major = tla[3] minor = tla[4] spec = selecttlb.TypelibSpec(typelibCLSID, lcid, major, minor) spec.FromTypelib(tlb, str(typelibCLSID)) typelibs = [(tlb, spec)] if progressInstance is None: progressInstance = SimpleProgress(verboseLevel) progress = progressInstance for typelib, info in typelibs: dir_name = gencache.GetGeneratedFileName(info.clsid, info.lcid, info.major, info.minor) dir_path_name = os.path.join(gencache.GetGeneratePath(), dir_name) progress.LogBeginGenerate(dir_path_name) gen = genpy.Generator(typelib, info.dll, progress) gen.generate_child(child, dir_path_name) progress.SetDescription("Importing module") __import__("win32com.gen_py." + dir_name + "." + child) progress.Close()
if os.path.exists("reingart.crt"): data_files.append(("conf", ["reingart.crt", "reingart.key"])) if sys.version_info > (2, 7): # add "Microsoft Visual C++ 2008 Redistributable Package (x86)" if os.path.exists(r"c:\Program Files\Mercurial"): data_files += [( ".", glob.glob(r'c:\Program Files\Mercurial\msvc*.dll') + glob.glob( r'c:\Program Files\Mercurial\Microsoft.VC90.CRT.manifest'), )] # fix permission denied runtime error on win32com.client.gencache.GenGeneratePath # (expects a __init__.py not pyc, also dicts.dat pickled or _LoadDicts/_SaveDicts will fail too) # NOTE: on windows 8.1 64 bits, this is stored in C:\Users\REINGART\AppData\\Local\Temp\gen_py\2.7 from win32com.client import gencache gen_py_path = gencache.GetGeneratePath( ) or "C:\Python27\lib\site-packages\win32com\gen_py" data_files += [( r"win32com\gen_py", [ os.path.join(gen_py_path, "__init__.py"), os.path.join(gen_py_path, "dicts.dat") ], )] sys.path.insert(0, r"C:\Python27\Lib\site-packages\pythonwin") WX_DLL = ( ".", glob.glob(r'C:\Python27\Lib\site-packages\pythonwin\mfc*.*') + glob.glob( r'C:\Python27\Lib\site-packages\pythonwin\Microsoft.VC90.MFC.manifest' ),
def GenerateFromTypeLibSpec(typelibInfo, file = None, verboseLevel = None, progressInstance = None, bUnicodeToString=None, bForDemand = bForDemandDefault, bBuildHidden = 1): assert bUnicodeToString is None, "this is deprecated and will go away" if verboseLevel is None: verboseLevel = 0 # By default, we use no gui and no verbose level! if bForDemand and file is not None: raise RuntimeError("You can only perform a demand-build when the output goes to the gen_py directory") if isinstance(typelibInfo, tuple): # Tuple typelibCLSID, lcid, major, minor = typelibInfo tlb = pythoncom.LoadRegTypeLib(typelibCLSID, major, minor, lcid) spec = selecttlb.TypelibSpec(typelibCLSID, lcid, major, minor) spec.FromTypelib(tlb, str(typelibCLSID)) typelibs = [(tlb, spec)] elif isinstance(typelibInfo, selecttlb.TypelibSpec): if typelibInfo.dll is None: # Version numbers not always reliable if enumerated from registry. tlb = pythoncom.LoadRegTypeLib(typelibInfo.clsid, typelibInfo.major, typelibInfo.minor, typelibInfo.lcid) else: tlb = pythoncom.LoadTypeLib(typelibInfo.dll) typelibs = [(tlb, typelibInfo)] elif hasattr(typelibInfo, "GetLibAttr"): # A real typelib object! # Could also use isinstance(typelibInfo, PyITypeLib) instead, but PyITypeLib is not directly exposed by pythoncom. # pythoncom.TypeIIDs[pythoncom.IID_ITypeLib] seems to work tla = typelibInfo.GetLibAttr() guid = tla[0] lcid = tla[1] major = tla[3] minor = tla[4] spec = selecttlb.TypelibSpec(guid, lcid, major, minor) typelibs = [(typelibInfo, spec)] else: typelibs = GetTypeLibsForSpec(typelibInfo) if progressInstance is None: progressInstance = SimpleProgress(verboseLevel) progress = progressInstance bToGenDir = (file is None) for typelib, info in typelibs: gen = genpy.Generator(typelib, info.dll, progress, bBuildHidden=bBuildHidden) if file is None: this_name = gencache.GetGeneratedFileName(info.clsid, info.lcid, info.major, info.minor) full_name = os.path.join(gencache.GetGeneratePath(), this_name) if bForDemand: try: os.unlink(full_name + ".py") except os.error: pass try: os.unlink(full_name + ".pyc") except os.error: pass try: os.unlink(full_name + ".pyo") except os.error: pass if not os.path.isdir(full_name): os.mkdir(full_name) outputName = os.path.join(full_name, "__init__.py") else: outputName = full_name + ".py" fileUse = gen.open_writer(outputName) progress.LogBeginGenerate(outputName) else: fileUse = file worked = False try: gen.generate(fileUse, bForDemand) worked = True finally: if file is None: gen.finish_writer(outputName, fileUse, worked) if bToGenDir: progress.SetDescription("Importing module") gencache.AddModuleToCache(info.clsid, info.lcid, info.major, info.minor) progress.Close()
def prepare_gencache(): gencache.is_readonly = False gencache.GetGeneratePath()