discover.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright 2023 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import os
  5. from typing import List
  6. # The base names that are known to be Chromium metadata files.
  7. _METADATA_FILES = {
  8. "README.chromium",
  9. }
  10. def is_metadata_file(path: str) -> bool:
  11. """Filter for metadata files."""
  12. return os.path.basename(path) in _METADATA_FILES
  13. def find_metadata_files(root: str) -> List[str]:
  14. """Finds all metadata files within the given root directory,
  15. including subdirectories.
  16. Args:
  17. root: the absolute path to the root directory within which to
  18. search.
  19. Returns: the absolute full paths for all the metadata files within
  20. the root directory, sorted in ascending order.
  21. """
  22. metadata_files = []
  23. for (dirpath, _, filenames) in os.walk(root, followlinks=True):
  24. for filename in filenames:
  25. if is_metadata_file(filename):
  26. full_path = os.path.join(root, dirpath, filename)
  27. metadata_files.append(full_path)
  28. return sorted(metadata_files)