utils.py 文件源码

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

项目:PyPPL 作者: pwwang 项目源码 文件源码
def chmodX (thefile):
    """
    Convert script file to executable or add extract shebang to cmd line
    @params:
        `thefile`: the script file
    @returns:
        A list with or without the path of the interpreter as the first element and the script file as the last element
    """
    thefile = path.realpath(thefile)
    ret = [thefile]
    try:
        st = stat (thefile)
        chmod (thefile, st.st_mode | S_IEXEC)
    except Exception as e1:
        try:
            shebang = open (thefile).read().strip().splitlines()[0]
            if not shebang.startswith("#!"): # pragma: no cover
                raise
            ret = shebang[2:].strip().split() + [thefile] # pragma: no cover
        except Exception as e2:
            raise Exception("Cannot change %s as executable or read the shebang from it:\n%s\n%s" % (thefile, e1, e2))
    return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号