mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
30 lines
884 B
Python
30 lines
884 B
Python
import pathlib
|
|
import subprocess
|
|
|
|
__version__ = (pathlib.Path(__file__).parent / 'version.txt').read_text()
|
|
|
|
|
|
def git_revision():
|
|
try:
|
|
cmd = ('git', 'log', '-1', '--format="%H"')
|
|
revision = subprocess.check_output(cmd, stderr=subprocess.PIPE)
|
|
revision = revision.decode().strip().strip('"')
|
|
return revision
|
|
except Exception:
|
|
# Could not find git version...
|
|
return 'unknown'
|
|
|
|
|
|
def git_branch():
|
|
try:
|
|
cmd = ('git', 'rev-parse', '--abbrev-ref', 'HEAD')
|
|
branch = subprocess.check_output(cmd, stderr=subprocess.PIPE)
|
|
branch = branch.decode().strip()
|
|
return branch
|
|
except Exception:
|
|
return 'unknown'
|
|
|
|
|
|
def get_version_string():
|
|
"""Return a string containing the WROLPi version, git branch and git revision hash."""
|
|
return f'{__version__} (git: {git_branch()} {git_revision()})'
|