소스 검색

try to make version script more windows friendly and fault tolerant

Chris Mullins 8 년 전
부모
커밋
f2238ce3cc
1개의 변경된 파일28개의 추가작업 그리고 1개의 파일을 삭제
  1. 28 1
      .get_version.py

+ 28 - 1
.get_version.py

@@ -1,5 +1,32 @@
 from subprocess import check_output
+import os
+import os
+import platform
+import subprocess
+
+dir_path = os.path.dirname(os.path.realpath(__file__))
+os.chdir(dir_path)
+
+# http://stackoverflow.com/questions/11210104/check-if-a-program-exists-from-a-python-script
+def is_tool(name):
+    cmd = "where" if platform.system() == "Windows" else "which"
+    try:
+        check_output([cmd, "git"])
+        return True
+    except:
+        return False;
+
+version = "UNKNOWN"
+
+if is_tool("git"):
+    try:
+        version = check_output(["git", "describe", "--always"]).rstrip()
+    except:
+        try:
+            version = check_output(["git", "rev-parse", "--short", "HEAD"]).rstrip()
+        except:
+            pass
+        pass
 
-version = check_output(["git", "describe", "--always"]).rstrip()
 
 print("-DMILIGHT_HUB_VERSION=%s" % version)