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