summaryrefslogtreecommitdiffstats
path: root/openstack/common/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
commita9e10729737c33a4c29c409ec966ce64301383c7 (patch)
treeeb10fc594d257f4505cbcf2ee4570dd67ecd4bbc /openstack/common/setup.py
parent6f08fb4edabd0be6a61fca91b3cee15433bc110f (diff)
downloadoslo-a9e10729737c33a4c29c409ec966ce64301383c7.tar.gz
oslo-a9e10729737c33a4c29c409ec966ce64301383c7.tar.xz
oslo-a9e10729737c33a4c29c409ec966ce64301383c7.zip
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 'openstack/common/setup.py')
-rw-r--r--openstack/common/setup.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/openstack/common/setup.py b/openstack/common/setup.py
index 28f5e6f..34c88e5 100644
--- a/openstack/common/setup.py
+++ b/openstack/common/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))