[templates] Add version and commit to footer
This commit is contained in:
31
vrobbler/context_processors.py
Normal file
31
vrobbler/context_processors.py
Normal file
@ -0,0 +1,31 @@
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def version_info(request):
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||
try:
|
||||
commit = (
|
||||
subprocess.check_output(
|
||||
["git", "rev-parse", "--short", "HEAD"],
|
||||
cwd=PROJECT_ROOT,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
.decode("utf-8")
|
||||
.strip()
|
||||
)
|
||||
except (subprocess.SubprocessError, FileNotFoundError):
|
||||
commit = "unknown"
|
||||
|
||||
try:
|
||||
pyproject = PROJECT_ROOT / "pyproject.toml"
|
||||
version = "unknown"
|
||||
if pyproject.exists():
|
||||
for line in pyproject.read_text().splitlines():
|
||||
if line.startswith("version = "):
|
||||
version = line.split("=")[1].strip().strip('"')
|
||||
break
|
||||
except Exception:
|
||||
version = "unknown"
|
||||
|
||||
return {"app_version": version, "git_commit": commit}
|
||||
@ -183,6 +183,7 @@ TEMPLATES = [
|
||||
"videos.context_processors.video_lists",
|
||||
"music.context_processors.music_lists",
|
||||
"scrobbles.context_processors.now_playing",
|
||||
"vrobbler.context_processors.version_info",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
@ -268,5 +268,9 @@
|
||||
})()
|
||||
</script>
|
||||
|
||||
<footer class="mt-4 py-2 text-center text-muted border-top">
|
||||
<small>v{{ app_version }} ({{ git_commit }})</small>
|
||||
</footer>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user