Use fallback if git is not installed. Closes #44.
This commit is contained in:
parent
75818950f8
commit
e40eec4b85
|
@ -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 = '.'
|
||||||
p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
version = fallback
|
||||||
(stdo, _) = p.communicate()
|
try:
|
||||||
# If we are working off an extracted tarball, git version number is not available.
|
p = subprocess.Popen(['git', 'describe'], cwd=workdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
if p.returncode == 0:
|
(stdo, _) = p.communicate()
|
||||||
version = stdo.decode().strip()
|
if p.returncode == 0:
|
||||||
else:
|
version = stdo.decode().strip()
|
||||||
version = fallback
|
except:
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue