checkLicense.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. import sys
  3. import glob
  4. correct_licence = """\
  5. // Copyright Catch2 Authors
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // https://www.boost.org/LICENSE_1_0.txt)
  9. // SPDX-License-Identifier: BSL-1.0
  10. """
  11. def check_licence_in_file(filename: str) -> bool:
  12. with open(filename, 'r') as f:
  13. file_preamble = ''.join(f.readlines()[:7])
  14. if correct_licence != file_preamble:
  15. print('File {} does not have proper licence'.format(filename))
  16. return False
  17. return True
  18. def check_licences_in_path(path: str) -> int:
  19. failed = 0
  20. files_to_check = glob.glob(path + '/**/*.cpp', recursive=True) \
  21. + glob.glob(path + '/**/*.hpp', recursive=True)
  22. for file in files_to_check:
  23. if not check_licence_in_file(file):
  24. failed += 1
  25. return failed
  26. def check_licences():
  27. failed = 0
  28. roots = ['src/catch2', 'tests']
  29. for root in roots:
  30. failed += check_licences_in_path(root)
  31. if failed:
  32. print('{} files are missing licence'.format(failed))
  33. sys.exit(1)
  34. if __name__ == "__main__":
  35. check_licences()