Created
February 21, 2012 18:51
-
-
Save turtlebender/1878110 to your computer and use it in GitHub Desktop.
get version number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| from subprocess import Popen, PIPE | |
| import re | |
| import string | |
| import datetime | |
| import time | |
| def get_version(): | |
| p1 = Popen('git branch', stdout=PIPE, shell=True) | |
| p2 = Popen('grep -e ^*', stdin=p1.stdout, stdout=PIPE, shell=True) | |
| p1.stdout.close() | |
| branch_name = p2.communicate()[0] | |
| if string.lower(branch_name).strip() == '* integration': | |
| return "snapshot-{0}".format(int(time.mktime(datetime.datetime.now().timetuple()))) | |
| m = re.match('^.*(RELEASE-)(.*)', branch_name) | |
| if m is not None: | |
| p1 = Popen('git log {0}{1} --not integration --oneline'.format(m.group(1), m.group(2)), stdout=PIPE, shell=True) | |
| p2 = Popen('wc -l', stdin=p1.stdout, stdout=PIPE, shell=True) | |
| p1.stdout.close() | |
| beta_version = "-{0}".format(p2.communicate()[0].strip()) | |
| if beta_version == '-0': | |
| beta_version = '' | |
| return "{0}-beta{1}".format(string.replace(m.group(2), '-', '.'), beta_version) | |
| p = Popen('git log --oneline -n 5', stdout=PIPE, shell=True) | |
| output = p.communicate()[0] | |
| for i in output.split('\n'): | |
| m = re.match("^.*RELEASE-(.*)-SIGNOFF-.*$", i) | |
| if m is None: | |
| continue | |
| return string.replace(m.group(1), "-", ".") | |
| print get_version() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment