Python 2 support for scripts/git_revision.py on error /o\

This commit is contained in:
heinrich5991 2018-03-02 03:22:44 +01:00
parent fca81553ba
commit b285d777f3

View file

@ -1,7 +1,16 @@
import errno
import subprocess
try:
FileNotFoundError
except NameError:
FileNotFoundError = OSError
try:
git_hash = subprocess.check_output(["git", "rev-parse", "--short=16", "HEAD"], stderr=None).decode().strip()
definition = '"{}"'.format(git_hash)
except (FileNotFoundError, subprocess.CalledProcessError):
except FileNotFoundError as e:
if e.errno != errno.ENOENT:
raise
definition = "0"
except subprocess.CalledProcessError:
definition = "0";
print("const char *GIT_SHORTREV_HASH = {};".format(definition))