jenkins.check_copyright.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #-------------------------------------------------------------------------------------------------------
  2. # Copyright (C) Microsoft. All rights reserved.
  3. # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. #-------------------------------------------------------------------------------------------------------
  5. # Python 2.7
  6. import sys
  7. import os.path
  8. import re
  9. copyright_lines = [
  10. r'-------------------------------------------------------------------------------------------------------',
  11. r' Copyright \(C\) Microsoft\. All rights reserved\.',
  12. r' Licensed under the MIT license\. See LICENSE\.txt file in the project root for full license information\.'
  13. ]
  14. regexes = []
  15. for line in copyright_lines:
  16. pattern = '^.{1,5}%s$' % line
  17. regexes.append(re.compile(pattern))
  18. if len(sys.argv) < 2:
  19. print "Requires passing a filename as an argument."
  20. exit(1)
  21. file_name = sys.argv[1]
  22. if not os.path.isfile(file_name):
  23. print "File does not exist:", file_name, "(not necessarily an error)"
  24. exit(0)
  25. with open(file_name, 'r') as sourcefile:
  26. for x in range(0,len(copyright_lines)):
  27. # TODO add a check for empty files (dummy.js etc), as they cause the script to crash here
  28. line = next(sourcefile)
  29. line = line.rstrip()
  30. matches = regexes[x].match(line)
  31. if not matches:
  32. print file_name, "... does not contain a correct Microsoft copyright notice."
  33. # found a problem so exit and report the problem to the caller
  34. exit(1)