cleanup_ignore_lists.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. # SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
  3. # SPDX-License-Identifier: Apache-2.0
  4. import glob
  5. import os
  6. import typing as t
  7. from pathlib import Path
  8. from idf_ci_utils import IDF_PATH
  9. def print_list(_list: t.Iterable[t.Any], title: t.Optional[str] = None) -> None:
  10. if not _list:
  11. return
  12. if title:
  13. print(title)
  14. for i in _list:
  15. print('- ', str(i))
  16. if __name__ == '__main__':
  17. os.chdir(IDF_PATH)
  18. ignore_lists: t.Set[Path] = set()
  19. ignore_lists.update(Path('tools', 'ci').glob('**/*.txt'))
  20. ignore_lists.remove(Path('tools', 'ci', 'ignore_build_warnings.txt'))
  21. ignore_lists.remove(Path('tools', 'ci', 'check_ldgen_mapping_exceptions.txt'))
  22. print_list(ignore_lists, 'Ignore lists:')
  23. updated_files = []
  24. for f in ignore_lists:
  25. print('Checking file:', f)
  26. updated = False
  27. lines = []
  28. with open(f) as fr:
  29. for line in map(str.strip, fr.readlines()):
  30. if line.startswith('#'):
  31. lines.append(line)
  32. continue
  33. if not line:
  34. lines.append(line)
  35. continue
  36. glob_pattern = line
  37. if not list(glob.glob(glob_pattern, recursive=True)):
  38. print(' - No match:', glob_pattern)
  39. updated = True
  40. else:
  41. lines.append(glob_pattern)
  42. lines.append('')
  43. if updated:
  44. updated_files.append(f)
  45. with open(f, 'w') as fw:
  46. fw.write('\n'.join(lines))
  47. if updated_files:
  48. print_list(updated_files, 'Updated files:')
  49. exit(1)