mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Added commit time information to the --version output
Now prints date of commit (and timezone offset of commit) Hopefully resolves #783
This commit is contained in:
parent
183fce6d99
commit
208f2b66ed
1 changed files with 8 additions and 4 deletions
|
@ -28,6 +28,7 @@ from ansible import errors
|
|||
from ansible import color
|
||||
from ansible import __version__
|
||||
import ansible.constants as C
|
||||
import time
|
||||
|
||||
try:
|
||||
import json
|
||||
|
@ -288,16 +289,19 @@ def default(value, function):
|
|||
return value
|
||||
|
||||
def _gitinfo():
|
||||
''' returns a string containing git branch and commit id
|
||||
using gitpython if installed and native file operations if not '''
|
||||
''' returns a string containing git branch, commit id and commit date '''
|
||||
result = None
|
||||
repo_path = os.path.join(os.path.dirname(__file__), '..', '..', '.git')
|
||||
if os.path.exists(repo_path):
|
||||
with open(os.path.join(repo_path, "HEAD")) as f:
|
||||
branch = f.readline().split('/')[-1].rstrip("\n")
|
||||
with open(os.path.join(repo_path, "refs", "heads", branch)) as f:
|
||||
branch_path = os.path.join(repo_path, "refs", "heads", branch)
|
||||
with open(branch_path) as f:
|
||||
commit = f.readline()[:10]
|
||||
result = "({0} {1})".format(branch, commit)
|
||||
date = time.localtime(os.stat(branch_path).st_mtime)
|
||||
offset = time.timezone if (time.daylight == 0) else time.altzone
|
||||
result = "({0}) [{1}] {2} ({3:+04d})".format(branch, commit,
|
||||
time.strftime("%Y%m%d-%H%M%S", date), offset / -36)
|
||||
return result
|
||||
|
||||
def version(prog):
|
||||
|
|
Loading…
Reference in a new issue