本文整理汇总了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