当前位置: 首页>>代码示例>>Python>>正文


Python Path.digest方法代码示例

本文整理汇总了Python中fbuild.path.Path.digest方法的典型用法代码示例。如果您正苦于以下问题:Python Path.digest方法的具体用法?Python Path.digest怎么用?Python Path.digest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fbuild.path.Path的用法示例。


在下文中一共展示了Path.digest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_file

# 需要导入模块: from fbuild.path import Path [as 别名]
# 或者: from fbuild.path.Path import digest [as 别名]
    def add_file(self, file_name):
        """Insert or update the file information. Returns True if the content
        of the file is different from what was in the table."""

        # Make sure we got the right types.
        assert isinstance(file_name, str), file_name

        # Look up the old data.
        file_id, old_mtime, old_digest = self.find_file(file_name)

        # Now, create a path object and find it's mtime.
        file_path = Path(file_name)
        file_mtime = file_path.getmtime()

        if old_mtime is not None:
            # If the file was modified less than 1.0 seconds ago, recompute the
            # hash since it still could have changed even with the same mtime.
            # If True, then assume the file has not been modified.
            if file_mtime == old_mtime and time.time() - file_mtime > 1.0:
                return False, file_id, file_mtime, old_digest

        # The mtime changed, so let's see if the content's changed.
        digest = file_path.digest()

        if digest == old_digest:
            # Save the new mtime.
            self.save_file(file_id, file_name, file_mtime, digest)
            return False, file_id, file_mtime, digest

        if file_id is not None:
            # Since the function changed, all of the calls that used this
            # function are dirty.
            self.delete_file(file_name)

            # The file_id is now invalid.
            file_id = None

        # Now, add the file back to the database.
        file_id = self.save_file(file_id, file_name, file_mtime, digest)

        # Returns True since the file changed.
        return True, file_id, file_mtime, digest
开发者ID:felix-lang,项目名称:fbuild,代码行数:44,代码来源:backend.py


注:本文中的fbuild.path.Path.digest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。