.get_version.py 820 B

12345678910111213141516171819202122232425262728293031
  1. from subprocess import check_output
  2. import sys
  3. import os
  4. import platform
  5. import subprocess
  6. dir_path = os.path.dirname(os.path.realpath(__file__))
  7. os.chdir(dir_path)
  8. # http://stackoverflow.com/questions/11210104/check-if-a-program-exists-from-a-python-script
  9. def is_tool(name):
  10. cmd = "where" if platform.system() == "Windows" else "which"
  11. try:
  12. check_output([cmd, "git"])
  13. return True
  14. except:
  15. return False
  16. version = "UNKNOWN"
  17. if is_tool("git"):
  18. try:
  19. version = check_output(["git", "describe", "--always"]).rstrip()
  20. except:
  21. try:
  22. version = check_output(["git", "rev-parse", "--short", "HEAD"]).rstrip()
  23. except:
  24. pass
  25. pass
  26. sys.stdout.write("-DMILIGHT_HUB_VERSION=%s %s" % (version.decode('utf-8'), ' '.join(sys.argv[1:])))