def collect_win32com_genpy(path, typelibs, verbose=0, dry_run=0):
    import win32com
    from win32com.client import gencache, makepy
    from distutils.file_util import copy_file
    
    old_gen_path = win32com.__gen_path__
    num = 0
    try:
        win32com.__gen_path__ = path
        win32com.gen_py.__path__ = [path]
        gencache.__init__()
        for info in typelibs:
            guid, lcid, major, minor = info[:4]
            # They may provide an input filename in the tuple - in which case
            # they will have pre-generated it on a machine with the typelibs
            # installed, and just want us to include it.
            fname_in = None
            if len(info) > 4:
                fname_in = info[4]
            if fname_in is not None:
                base = gencache.GetGeneratedFileName(guid, lcid, major, minor)
                fname_out = os.path.join(path, base) + ".py"
                copy_file(fname_in, fname_out, verbose=verbose, dry_run=dry_run)
                num += 1
                # That's all we gotta do!
                continue

            # It seems bForDemand=True generates code which is missing
            # at least sometimes an import of DispatchBaseClass.
            # Until this is resolved, set it to false.
            # What's the purpose of bForDemand=True? Thomas
            # bForDemand is supposed to only generate stubs when each
            # individual object is referenced.  A side-effect of that is
            # that each object gets its own source file.  The intent of
            # this code was to set bForDemand=True, meaning we get the
            # 'file per object' behaviour, but then explicitly walk all
            # children forcing them to be built - so the entire object model
            # is included, but not in a huge .pyc.
            # I'm not sure why its not working :) I'll debug later.
            # bForDemand=False isn't really important here - the overhead for
            # monolithic typelib stubs is in the compilation, not the loading
            # of an existing .pyc. Mark.
##            makepy.GenerateFromTypeLibSpec(info, bForDemand = True)
            tlb_info = (guid, lcid, major, minor)
            makepy.GenerateFromTypeLibSpec(tlb_info, bForDemand = False)
            # Now get the module, and build all sub-modules.
            mod = gencache.GetModuleForTypelib(*tlb_info)
            for clsid, name in mod.CLSIDToPackageMap.items():
                try:
                    gencache.GetModuleForCLSID(clsid)
                    num += 1
                    #print "", name
                except ImportError:
                    pass
        return num
    finally:
        # restore win32com, just in case.
        win32com.__gen_path__ = old_gen_path
        win32com.gen_py.__path__ = [old_gen_path]
        gencache.__init__()

# utilities hacked from distutils.dir_util
dataset/ETHPy150Open fogleman/FeedNotifier/patch/build_exe.py/collect_win32com_genpy/original