From ec3a9c3f1f30fd8d75ca171d1f17deae6e0b8063 Mon Sep 17 00:00:00 2001 From: Nick Bolton Date: Mon, 20 Oct 2014 17:46:11 +0100 Subject: [PATCH] added getGitRevision function to get current git revision. --- ext/toolchain/commands1.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ext/toolchain/commands1.py b/ext/toolchain/commands1.py index ef492f2b..d245c55b 100644 --- a/ext/toolchain/commands1.py +++ b/ext/toolchain/commands1.py @@ -941,6 +941,24 @@ class InternalCommands: print self.find_revision() def find_revision(self): + return self.getGitRevision() + + def getGitRevision(self): + if sys.version_info < (2, 4): + raise Exception("Python 2.4 or greater required.") + else: + p = subprocess.Popen( + ["git", "log", "--pretty=format:%h", "-n", "1"], + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + stdout, stderr = p.communicate() + + if p.returncode != 0: + raise Exception('Could not get revision - git info failed with code: ' + str(p.returncode)) + + return stdout + + def find_revision_svn(self): if sys.version_info < (2, 4): stdout = commands.getoutput('svn info') else: @@ -1403,7 +1421,7 @@ class InternalCommands: def dist_name_rev(self, type): # find the version number (we're puting the rev in after this) pattern = '(.*\d+\.\d+\.\d+)(.*)' - replace = '\g<1>-r' + self.find_revision() + '\g<2>' + replace = '\g<1>-' + self.find_revision() + '\g<2>' return re.sub(pattern, replace, self.dist_name(type)) def dist_usage(self):