git.py 683 B

12345678910111213141516171819202122232425262728293031323334
  1. #/usr/bin/python3
  2. import os
  3. def get_date():
  4. CAPTION =""
  5. try:
  6. _gcmd=r'git log -1 --format=%ci'
  7. r = os.popen(_gcmd)
  8. txt=r.read()
  9. print(txt)
  10. CAPTION += " " + txt.strip().split()[0]
  11. except Exception as e:
  12. print(e)
  13. CAPTION += " no-date"
  14. return CAPTION
  15. def get_commit_id():
  16. CAPTION = ""
  17. try:
  18. _gcmd='git rev-parse --short HEAD'
  19. r=os.popen(_gcmd)
  20. txt=r.read()
  21. CAPTION += " v:"+txt.strip()
  22. except Exception as e:
  23. print(e)
  24. CAPTION += " no git"
  25. return CAPTION
  26. def get_all():
  27. out = ""
  28. out += get_commit_id()
  29. out += get_date()
  30. return out