summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2012-02-06 07:14:02 -0800
committerMonty Taylor <mordred@inaugust.com>2012-02-09 10:11:12 -0800
commit225107526bf157d5034bfe72e4c2b76ee20b6212 (patch)
tree4ce85d8eaeca8cd219696782d93c2094d0b88eca /setup.py
parentfbaefc8bcb27feea1fc3d43c1a3fe7dea4c9d946 (diff)
downloadpbr-225107526bf157d5034bfe72e4c2b76ee20b6212.tar.gz
Add git vcsversion method.
Leaving in the branch_nick for now - I think we need to go through the projects using this code and ensure that they aren't going to get screwed before we remove it. Change-Id: Ib91b5af050244f44cd811ca47cb6e2c53ef74ddb
Diffstat (limited to 'setup.py')
-rw-r--r--setup.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/setup.py b/setup.py
index 28f5e6f..34c88e5 100644
--- a/setup.py
+++ b/setup.py
@@ -85,3 +85,30 @@ def write_requirements():
stdout=subprocess.PIPE)
requirements = output.communicate()[0].strip()
req_file.write(requirements)
+
+
+def _run_shell_command(cmd):
+ output = subprocess.Popen(["/bin/sh", "-c", cmd],
+ stdout=subprocess.PIPE)
+ return output.communicate()[0].strip()
+
+
+def write_vcsversion(location):
+ """ Produce a vcsversion dict that mimics the old one produced by bzr
+ """
+ if os.path.isdir('.git'):
+ branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "'
+ branch_nick = _run_shell_command(branch_nick_cmd)
+ revid_cmd = "git rev-parse HEAD"
+ revid = _run_shell_command(revid_cmd).split()[0]
+ revno_cmd = "git log --oneline | wc -l"
+ revno = _run_shell_command(revno_cmd)
+ with open(location, 'w') as version_file:
+ version_file.write("""
+# This file is automatically generated by setup.py, So don't edit it. :)
+version_info = {
+ 'branch_nick': '%s',
+ 'revision_id': '%s',
+ 'revno': %s
+}
+""" % (branch_nick, revid, revno))