INNER CODE UNIT · Python

_dirhash

GoogleCloudPlatform/terraform-python-testing-helper · tftest.py:355

  def _dirhash(self, directory, hash, ignore_hidden=False,
               exclude_directories=[], excluded_extensions=[]):
    """Returns hash of directory's file contents"""
    assert Path(directory).is_dir()
    try:
      dir_iter = sorted(Path(directory).iterdir(), key=lambda p: str(p).lower())
    except FileNotFoundError:
      return hash
    for path in dir_iter:
      if path.is_file():
        if ignore_hidden and path.name.startswith("."):
          continue
        if path.suffix in excluded_extensions:
          continue
        with open(path, "rb") as f:
          for chunk in iter(lambda: f.read(4096), b""):
            hash.update(chunk)
      elif path.is_dir() and path.name not in exclude_directories:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…