forked from sidoh/esp8266_milight_hub
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.get_version.py
31 lines (26 loc) · 828 Bytes
/
.get_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from subprocess import check_output
import sys
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, name])
return True
except:
return False
version = "UNKNOWN".encode()
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
sys.stdout.write("-DMILIGHT_HUB_VERSION=%s %s" % (version.decode('utf-8'), ' '.join(sys.argv[1:])))