rev_info.py 951 B

1234567891011121314151617181920212223242526272829303132
  1. import datetime
  2. import subprocess
  3. def git_short_rev():
  4. try:
  5. return subprocess.check_output([
  6. 'git',
  7. 'rev-parse',
  8. '--short',
  9. 'HEAD',
  10. ]).decode('utf-8').strip()
  11. except Exception:
  12. raise RuntimeError("Could not read git revision. Make sure you have git installed and you're working with a git clone of the repository.")
  13. def current_date():
  14. return datetime.date.today().strftime('%Y-%m-%d')
  15. def git_date(short=True):
  16. try:
  17. iso = subprocess.check_output([
  18. 'git',
  19. 'log',
  20. '-1',
  21. '--format=%ci',
  22. 'HEAD',
  23. ]).decode('utf-8').strip()
  24. if short:
  25. return iso.split(' ')[0]
  26. else:
  27. return iso
  28. except Exception:
  29. raise RuntimeError("Could not read git commit date. Make sure you have git installed and you're working with a git clone of the repository.")