1
0
Fork 0
mirror of https://github.com/Findus23/acronomy.git synced 2024-09-19 15:33:45 +02:00
acronomy/acros/templatetags/version.py

19 lines
475 B
Python
Raw Permalink Normal View History

2023-04-12 22:12:27 +02:00
from pathlib import Path
2020-06-15 20:12:30 +02:00
from subprocess import run
from django import template
from django.core.cache import cache
register = template.Library()
@register.simple_tag
def commit_id():
2023-04-12 22:12:27 +02:00
current_dir = Path(__file__).parent
2020-06-15 20:12:30 +02:00
commit = cache.get("commit")
if not commit:
2023-04-12 22:12:27 +02:00
sp = run(["git", "rev-parse", "--verify", "HEAD"], capture_output=True, cwd=current_dir)
2020-06-15 20:12:30 +02:00
commit = sp.stdout.decode().strip()
cache.set("commit", commit)
return commit