Print version on startup

The version is determined from either the contents of _version.py
(expected to be present in release tarballs) or the output of
`git describe --always`.
This commit is contained in:
flan
2020-01-04 05:36:14 +01:00
parent aaf7e8b5e8
commit c07fe0e65c
3 changed files with 31 additions and 0 deletions

View File

@@ -3,3 +3,31 @@ import sys
sys.path.insert(0, "/usr/share/anki")
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), "anki-bundled"))
_homepage = "https://github.com/tsudoko/anki-sync-server"
_unknown_version = "[unknown version]"
def _get_version():
try:
from ankisyncd._version import version
return version
except ImportError:
pass
import subprocess
try:
return (
subprocess.run(
["git", "describe", "--always"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
.stdout.strip()
.decode()
or _unknown_version
)
except (FileNotFoundError, subprocess.CalledProcessError):
return _unknown_version