mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
Printing git branch when printing version.
This commit is contained in:
parent
4dc3ebf2b8
commit
4a7f33b625
2 changed files with 23 additions and 7 deletions
6
main.py
6
main.py
|
|
@ -13,7 +13,7 @@ from wrolpi.common import logger, get_config, wrol_mode_enabled, import_modules,
|
|||
from wrolpi.dates import set_timezone
|
||||
from wrolpi.downloader import download_manager
|
||||
from wrolpi.vars import PROJECT_DIR, DOCKERIZED
|
||||
from wrolpi.version import __version__, git_commit
|
||||
from wrolpi.version import get_version_string
|
||||
|
||||
logger = logger.getChild('wrolpi-main')
|
||||
|
||||
|
|
@ -62,12 +62,12 @@ async def main(loop):
|
|||
|
||||
if args.version:
|
||||
# Print out the relevant version information, then exit.
|
||||
print(f'{__version__} (git revision: {git_commit()})')
|
||||
print(get_version_string())
|
||||
return 0
|
||||
|
||||
logger.warning(f'Starting with: {sys.argv}')
|
||||
await set_log_level(args)
|
||||
logger.debug(f'git revision: {git_commit()}')
|
||||
logger.debug(get_version_string())
|
||||
|
||||
if DOCKERIZED:
|
||||
logger.info('Running in Docker')
|
||||
|
|
|
|||
|
|
@ -3,13 +3,29 @@ __version__ = '0.1.2-beta'
|
|||
import subprocess
|
||||
|
||||
|
||||
def git_commit():
|
||||
def git_revision():
|
||||
try:
|
||||
cmd = ('git', 'log', '-1', '--format="%H"')
|
||||
git_version = subprocess.check_output(cmd, stderr=subprocess.PIPE)
|
||||
git_version = git_version.decode().strip().strip('"')
|
||||
revision = subprocess.check_output(cmd, stderr=subprocess.PIPE)
|
||||
revision = revision.decode().strip().strip('"')
|
||||
return revision
|
||||
except Exception:
|
||||
# Could not find git version...
|
||||
return 'unknown'
|
||||
|
||||
return git_version
|
||||
|
||||
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()})'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue