Use fallback if git is not installed. Closes #44.

This commit is contained in:
Jussi Pakkanen 2015-02-27 20:24:06 +02:00
parent 75818950f8
commit e40eec4b85
1 changed files with 9 additions and 8 deletions

View File

@ -6,19 +6,20 @@ def generate(infile, outfile, fallback):
workdir = os.path.split(infile)[0] workdir = os.path.split(infile)[0]
if workdir == '': if workdir == '':
workdir = '.' workdir = '.'
version = fallback
try:
p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdo, _) = p.communicate() (stdo, _) = p.communicate()
# If we are working off an extracted tarball, git version number is not available.
if p.returncode == 0: if p.returncode == 0:
version = stdo.decode().strip() version = stdo.decode().strip()
else: except:
version = fallback pass
newdata = open(infile).read().replace('@VERSION@', version) newdata = open(infile).read().replace('@VERSION@', version)
try: try:
olddata = open(outfile).read() olddata = open(outfile).read()
if olddata == newdata: if olddata == newdata:
return return
except Exception: except:
pass pass
open(outfile, 'w').write(newdata) open(outfile, 'w').write(newdata)