update_compatibility_version.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. """Compatibility tests between last released and the current version.
  3. Usage: ./update_compatibility_version.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
  4. Example: ./update_compatibility_version.py 3.7.1
  5. """
  6. from __future__ import print_function
  7. import re
  8. import sys
  9. if len(sys.argv) < 2 or len(sys.argv) > 3:
  10. print("""
  11. [ERROR] Please specify a version.
  12. ./update_compatibility_version.py.py <MAJOR>.<MINOR>.<MICRO> [<RC version>]
  13. Example:
  14. ./update_compatibility_version.py.py 3.7.1 2
  15. """)
  16. exit(1)
  17. NEW_VERSION = sys.argv[1]
  18. NEW_VERSION_INFO = NEW_VERSION.split('.')
  19. if len(NEW_VERSION_INFO) != 3:
  20. print("""
  21. [ERROR] Version must be in the format <MAJOR>.<MINOR>.<MICRO>
  22. Example:
  23. ./update_compatibility_version.py.py 3.7.3
  24. """)
  25. exit(1)
  26. if len(sys.argv) > 2:
  27. RC_VERSION = int(sys.argv[2])
  28. # Do not update compatibility versions for rc release
  29. if RC_VERSION != 0:
  30. exit(0)
  31. def RewriteTextFile(filename, line_rewriter):
  32. lines = open(filename, 'r').readlines()
  33. updated_lines = []
  34. for line in lines:
  35. updated_lines.append(line_rewriter(line))
  36. if lines == updated_lines:
  37. print('%s was not updated. Please double check.' % filename)
  38. f = open(filename, 'w')
  39. f.write(''.join(updated_lines))
  40. f.close()
  41. def ReplaceVersion(line):
  42. return re.sub(r'LAST_RELEASED=.*$', 'LAST_RELEASED=%s' % NEW_VERSION, line)
  43. RewriteTextFile('tests.sh', ReplaceVersion)