def DatabaseDirectorySize(root_path, extension):
  """Compute size (in bytes) and number of files of a file-based data store."""
  directories = collections.deque([root_path])
  total_size = 0
  total_files = 0
  while directories:
    directory = directories.popleft()
    try:
      items = os.listdir(directory)
    except OSError:
      continue
    for comp in items:
      if comp == constants.REBALANCE_DIRECTORY:
        continue
      path = os.path.join(directory, comp)
      try:
        statinfo = os.lstat(path)
        if stat.S_ISLNK(statinfo.st_mode):
          continue
        if stat.S_ISDIR(statinfo.st_mode):
          directories.append(path)
        elif stat.S_ISREG(statinfo.st_mode):
          if comp.endswith(extension):
            total_size += statinfo.st_size
            total_files += 1
      except __HOLE__:
        continue
  return total_size, total_files
dataset/ETHPy150Open google/grr/grr/lib/data_stores/common.py/DatabaseDirectorySize