printprereleasesuffix.py 963 B

1234567891011121314151617181920212223242526272829303132
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. # Prints the pre-release version suffix based on the version string
  5. #
  6. # Examples:
  7. # 2.1a3 > " 2.1 Alpha 3"
  8. # 2.1a3pre > ""
  9. # 3.2b4 > " 3.2 Beta 4"
  10. # 3.2b4pre > ""
  11. from __future__ import print_function
  12. import sys
  13. import re
  14. def get_prerelease_suffix(version):
  15. """ Returns the prerelease suffix from the version string argument """
  16. def mfunc(m):
  17. return " {0} {1} {2}".format(m.group('prefix'),
  18. {'a': 'Alpha', 'b': 'Beta'}[m.group('c')],
  19. m.group('suffix'))
  20. result, c = re.subn(r'^(?P<prefix>(\d+\.)*\d+)(?P<c>[ab])(?P<suffix>\d+)$',
  21. mfunc, version)
  22. if c != 1:
  23. return ''
  24. return result
  25. if len(sys.argv) == 2:
  26. print(get_prerelease_suffix(sys.argv[1]))