Utils.py 文件源码

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

项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码
def check_exe(name, env=None):
    """
    Ensure that a program exists

    :type name: string
    :param name: name or path to program
    :return: path of the program or None
    """
    if not name:
        raise ValueError('Cannot execute an empty string!')
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(name)
    if fpath and is_exe(name):
        return os.path.abspath(name)
    else:
        env = env or os.environ
        for path in env["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, name)
            if is_exe(exe_file):
                return os.path.abspath(exe_file)
    return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号