setuptestframework.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:remoteControlPPT 作者: htwenning 项目源码 文件源码
def makemdb(testfolder, mdb_name):
    # following setup code borrowed from pywin32 odbc test suite
    # kindly contributed by Frank Millman.
    import os

    _accessdatasource = os.path.join(testfolder, mdb_name)
    if not os.path.isfile(_accessdatasource):
        try:
            from win32com.client.gencache import EnsureDispatch
            from win32com.client import constants
            win32 = True
        except ImportError: #perhaps we are running IronPython
            win32 = False #iron Python
            try:
                from System import Activator, Type
            except:
                pass

        # Create a brand-new database - what is the story with these?
        dbe = None
        for suffix in (".36", ".35", ".30"):
            try:
                if win32:
                    dbe = EnsureDispatch("DAO.DBEngine" + suffix)
                else:
                    type= Type.GetTypeFromProgID("DAO.DBEngine" + suffix)
                    dbe =  Activator.CreateInstance(type)
                break
            except:
                pass
        if dbe:
            print('    ...Creating ACCESS db at '+_accessdatasource)
            if win32:
                workspace = dbe.Workspaces(0)
                newdb = workspace.CreateDatabase(_accessdatasource,
                                                constants.dbLangGeneral,
                                                constants.dbEncrypt)
            else:
                newdb = dbe.CreateDatabase(_accessdatasource,';LANGID=0x0409;CP=1252;COUNTRY=0')
            newdb.Close()
        else:
            print('    ...copying test ACCESS db to '+_accessdatasource)
            mdbName = os.path.normpath(os.getcwd() + '/../examples/test.mdb')
            import shutil
            shutil.copy(mdbName, _accessdatasource)

    return  _accessdatasource
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号