0

use git to find current hash, should work with overviewer-as-submodule

This commit is contained in:
Aaron Griffith
2013-01-21 16:50:38 -05:00
parent a5ee1b68ba
commit d09b74e6f0

View File

@@ -21,6 +21,7 @@ import imp
import os.path import os.path
import sys import sys
import platform import platform
from string import hexdigits
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from itertools import cycle, islice, product from itertools import cycle, islice, product
@@ -35,21 +36,14 @@ def get_program_path():
except NameError: except NameError:
return os.path.dirname(sys.argv[0]) return os.path.dirname(sys.argv[0])
# does not require git, very likely to work everywhere
def findGitHash(): def findGitHash():
this_dir = get_program_path() try:
if os.path.exists(os.path.join(this_dir,".git")): p = Popen('git rev-parse HEAD', stdout=PIPE, stderr=PIPE, shell=True)
with open(os.path.join(this_dir,".git","HEAD")) as f: p.stderr.close()
data = f.read().strip() line = p.stdout.readlines()[0].strip()
if data.startswith("ref: "): if line and len(line) == 40 and all(c in hexdigits for c in line):
if not os.path.exists(os.path.join(this_dir, ".git", data[5:])): return line
return data except Exception:
with open(os.path.join(this_dir, ".git", data[5:])) as g:
return g.read().strip()
else:
return data
else:
try: try:
import overviewer_version import overviewer_version
return overviewer_version.HASH return overviewer_version.HASH