def BuildTypelib(idlfile = "RDKitXL.idl"):
this_dir = os.path.dirname(__file__)
idl = os.path.abspath(os.path.join(this_dir, idlfile))
basename = idlfile.split('.')[0]
tlb=os.path.splitext(idl)[0] + '.tlb'
prev_idl = idl + ".previous"
this_idl_txt = "".join(open(idl, 'r').readlines())
previous_idl_txt = "does not exist"
if os.path.isfile(prev_idl):
previous_idl_txt = "".join(open(prev_idl, 'r').readlines())
if this_idl_txt != previous_idl_txt:
print("Compiling %s." % (idl,))
rc = os.system ('midl "%s"' % (idl,))
if rc:
raise RuntimeError("Compiling MIDL failed!")
# Can't work out how to prevent MIDL from generating the stubs.
# just nuke them
for fname in ("dlldata.c %s_i.c %s_p.c %s.h"%(basename, basename, basename)).split():
os.remove(os.path.join(this_dir, fname))
open(prev_idl, 'w').write("".join(open(idl, 'r').readlines()))
else:
print("No IDL changes.")
print("Registering %s." % (tlb,))
tli=pythoncom.LoadTypeLib(tlb)
pythoncom.RegisterTypeLib(tli,tlb)
评论列表
文章目录