check_files_exist.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2019 The ungoogled-chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """
  6. Checks if files in a list exist.
  7. Used for quick validation of lists in CI checks.
  8. """
  9. import argparse
  10. import sys
  11. from pathlib import Path
  12. def main():
  13. """CLI entrypoint"""
  14. parser = argparse.ArgumentParser(description=__doc__)
  15. parser.add_argument('root_dir', type=Path, help='The directory to check from')
  16. parser.add_argument('input_files', type=Path, nargs='+', help='The files lists to check')
  17. args = parser.parse_args()
  18. for input_name in args.input_files:
  19. file_iter = filter(
  20. len, map(str.strip,
  21. Path(input_name).read_text(encoding='UTF-8').splitlines()))
  22. for file_name in file_iter:
  23. if not Path(args.root_dir, file_name).exists():
  24. print('ERROR: Path "{}" from file "{}" does not exist.'.format(
  25. file_name, input_name),
  26. file=sys.stderr)
  27. sys.exit(1)
  28. if __name__ == "__main__":
  29. main()