Show git timestamp in version

This commit is contained in:
Florian Bruhin 2014-06-23 16:19:43 +02:00
parent af8b2284ea
commit b6ddda8f17
3 changed files with 13 additions and 6 deletions

View File

@ -45,7 +45,6 @@ Improvements / minor features
- Color statusbar in insert mode
- set_toggle to toggle setting between two states
- Customizable statusbar
- Timestamp of git commit in version
- Show size of widgets in __repr__
- Ask whether to close when downloads are running or maybe if form fields are
unsubmitted (book page 187)

View File

@ -97,20 +97,24 @@ def _git_str():
def _git_str_subprocess(gitpath):
"""Try to get the git commit ID by calling git.
"""Try to get the git commit ID and timestamp by calling git.
Args:
gitpath: The path where the .git folder is.
Return:
The path on success, None on failure.
The ID/timestamp on success, None on failure.
"""
if not os.path.isdir(os.path.join(gitpath, ".git")):
return None
try:
return subprocess.check_output(
cid = subprocess.check_output(
['git', 'describe', '--tags', '--dirty', '--always'],
cwd=gitpath).decode('UTF-8').strip()
date = subprocess.check_output(
['git', 'show', '-s', '--format=%ci', 'HEAD'],
cwd=gitpath).decode('UTF-8').strip()
return '{} ({})'.format(cid, date)
except (subprocess.CalledProcessError, FileNotFoundError):
return None

View File

@ -61,7 +61,7 @@ def _git_str():
"""Try to find out git version.
Return:
string containing the git commit ID.
string containing the git commit ID and timestamp.
None if there was an error or we're not in a git repo.
"""
if BASEDIR is None:
@ -69,9 +69,13 @@ def _git_str():
if not os.path.isdir(os.path.join(BASEDIR, ".git")):
return None
try:
return subprocess.check_output(
cid = subprocess.check_output(
['git', 'describe', '--tags', '--dirty', '--always'],
cwd=BASEDIR).decode('UTF-8').strip()
date = subprocess.check_output(
['git', 'show', '-s', '--format=%ci', 'HEAD'],
cwd=BASEDIR).decode('UTF-8').strip()
return '{} ({})'.format(cid, date)
except (subprocess.CalledProcessError, FileNotFoundError):
return None