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]
if workdir == '':
workdir = '.'
p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdo, _) = p.communicate()
# If we are working off an extracted tarball, git version number is not available.
if p.returncode == 0:
version = stdo.decode().strip()
else:
version = fallback
version = fallback
try:
p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdo, _) = p.communicate()
if p.returncode == 0:
version = stdo.decode().strip()
except:
pass
newdata = open(infile).read().replace('@VERSION@', version)
try:
olddata = open(outfile).read()
if olddata == newdata:
return
except Exception:
except:
pass
open(outfile, 'w').write(newdata)