update_compatibility_version.py 1.2 KB

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