rossum.py 文件源码

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

项目:rossum 作者: gavanderhoorn 项目源码 文件源码
def find_fr_install_dir(search_locs):
    try:
        import _winreg as wreg

        # find roboguide install dir
        fr_key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, r'Software\FANUC', 0,
            # always use 32-bit registry view, even if this is a 64-bit
            # Python, as Roboguide is a 32-bit application, so its keys
            # are stored in the 32-bit view
            wreg.KEY_READ | wreg.KEY_WOW64_32KEY)
        fr_install_dir = wreg.QueryValueEx(fr_key, "InstallDir")[0]

        # get roboguide version
        # TODO: this will fail if roboguide isn't installed
        rg_key = wreg.OpenKey(wreg.HKEY_LOCAL_MACHINE, r'Software\FANUC\ROBOGUIDE',
            # always use 32-bit registry view, even if this is a 64-bit
            # Python, as Roboguide is a 32-bit application, so its keys
            # are stored in the 32-bit view
            0, wreg.KEY_READ | wreg.KEY_WOW64_32KEY)
        rg_ver = wreg.QueryValueEx(rg_key, "Version")[0]

        logger.debug("Found Roboguide version: {0}".format(rg_ver))
        if os.path.exists(os.path.join(fr_install_dir, 'Shared')):
            logger.debug("Most likely FANUC base-dir: {}".format(fr_install_dir))
            return fr_install_dir

    except WindowsError as we:
        logger.debug("Couldn't find FANUC registry key(s), trying other methods")
    except ImportError as ime:
        logger.debug("Couldn't access Windows registry, trying other methods")

    # no windows registry, try looking in the file system
    logger.warn("Can't find FANUC base-dir using registry, switching to file-system search")

    for search_loc in search_locs:
        logger.debug("Looking in '{0}'".format(search_loc))
        candidate_path = os.path.join(search_loc, 'Shared')
        if os.path.exists(candidate_path):
            logger.debug("Found FANUC base-dir: {}".format(search_loc))
            return search_loc

    logger.warn("Exhausted all methods to find FANUC base-dir")
    raise Exception("Can't find FANUC base-dir anywhere")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号