Utils.py 文件源码

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

项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码
def h_file(fname):
    """
    Compute a hash value for a file by using md5. This method may be replaced by
    a faster version if necessary. The following uses the file size and the timestamp value::

        import stat
        from waflib import Utils
        def h_file(fname):
            st = os.stat(fname)
            if stat.S_ISDIR(st[stat.ST_MODE]): raise IOError('not a file')
            m = Utils.md5()
            m.update(str(st.st_mtime))
            m.update(str(st.st_size))
            m.update(fname)
            return m.digest()
        Utils.h_file = h_file

    :type fname: string
    :param fname: path to the file to hash
    :return: hash of the file contents
    """
    f = open(fname, 'rb')
    m = md5()
    try:
        while fname:
            fname = f.read(200000)
            m.update(fname)
    finally:
        f.close()
    return m.digest()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号