Changed setup.py to pull version info from git.

Change-Id: Ifdbdd6b587f5e4d0c255d4ed683bc81aeb8d95e4
This commit is contained in:
Monty Taylor 2011-08-04 08:51:04 -07:00
parent 3aa1701e07
commit 8f5bd2dc1c
2 changed files with 23 additions and 7 deletions

4
README
View File

@ -12,9 +12,9 @@ component.
Quick Start
-----------
If you'd like to run trunk, you can fetch from the bzr repo::
If you'd like to run trunk, you can clone the git repo:
bzr branch lp:glance
git clone git@github.com:openstack/glance.git
Install Glance by running::

View File

@ -23,12 +23,28 @@ from setuptools.command.sdist import sdist
from glance import version
if os.path.isdir('.bzr'):
def run_git_command(cmd):
output = subprocess.Popen(["/bin/sh", "-c", cmd],
stdout=subprocess.PIPE)
return output.communicate()[0].strip()
if os.path.isdir('.git'):
branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "'
branch_nick = run_git_command(branch_nick_cmd)
revid_cmd = "git --no-pager log --max-count=1 | cut -f2 -d' ' | head -1"
revid = run_git_command(revid_cmd)
revno_cmd = "git --no-pager log --oneline | wc -l"
revno = run_git_command(revno_cmd)
with open("glance/vcsversion.py", 'w') as version_file:
vcs_cmd = subprocess.Popen(["bzr", "version-info", "--python"],
stdout=subprocess.PIPE)
vcsversion = vcs_cmd.communicate()[0]
version_file.write(vcsversion)
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))
class local_sdist(sdist):