update_compatibility_version.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. def UpdateCsharp():
  43. RewriteTextFile('csharp/compatibility_tests/v3.0.0/test.sh',
  44. lambda line : re.sub(
  45. r'LAST_RELEASED=.*$',
  46. 'LAST_RELEASED=%s' % NEW_VERSION,
  47. line))
  48. def UpdateTests():
  49. RewriteTextFile('tests.sh',
  50. lambda line : re.sub(
  51. r'LAST_RELEASED=.*$',
  52. 'LAST_RELEASED=%s' % NEW_VERSION,
  53. line))
  54. UpdateCsharp()
  55. UpdateTests()