Show the git branch and last commit ID in the desktop app About box.

master
Pacman Ghost 5 years ago
parent 15f693fc05
commit 36b6ea2da5
  1. 29
      _freeze.py
  2. 11
      vasl_templates/about.py

@ -4,10 +4,12 @@
import sys
import os
import shutil
import subprocess
import tempfile
import time
import datetime
import json
import re
import getopt
from PyInstaller.__main__ import run as run_pyinstaller
@ -24,6 +26,32 @@ DEFAULT_TARGET_NAME = "vasl-templates"
# ---------------------------------------------------------------------
def get_git_info():
"""Get the git branch/commit we're building from."""
# get the latest commit ID
proc = subprocess.run(
[ "git", "log" ],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8"
)
buf = proc.stdout.split( "\n" )[0]
mo = re.search( r"^commit ([a-z0-9]+)$", buf )
last_commit_id = mo.group(1)
# get the current git branch
proc = subprocess.run(
[ "git", "branch" ],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8"
)
lines = [ s for s in proc.stdout.split("\n") if s.startswith("* ") ]
if len(lines) != 1:
raise RuntimeError( "Can't parse git branch status." )
branch_name = lines[0][2:]
return { "last_commit_id": last_commit_id, "branch_name": branch_name }
# ---------------------------------------------------------------------
# parse the command-line options
output_fname = None
work_dir = None
@ -131,6 +159,7 @@ for f in fnames:
build_info = {
"timestamp": int( time.time() ),
}
build_info.update( get_git_info() )
dname = os.path.join( dist_dir, "config" )
with open( os.path.join(dname,"build-info.json"), "w" ) as fp:
json.dump( build_info, fp )

@ -3,6 +3,7 @@
import os
import json
import time
import io
from PyQt5 import uic
from PyQt5.QtWidgets import QDialog
@ -38,10 +39,18 @@ class AboutDialog( QDialog ):
self.app_name.setText( "{} ({})".format( APP_NAME, APP_VERSION ) )
self.license.setText( "Licensed under the GNU Affero General Public License (v3)." )
if build_info:
buf = io.StringIO()
timestamp = build_info[ "timestamp" ]
self.build_info.setText( "Built {}.".format(
buf.write( "Built {}".format(
time.strftime( "%d %B %Y %H:%S", time.localtime( timestamp ) ) # nb: "-d" doesn't work on Windows :-/
) )
if "branch_name" in build_info or "last_commit_id" in build_info:
buf.write( " <small><em>({}".format( build_info["branch_name"] ) )
if "last_commit_id" in build_info:
buf.write( ":{}".format( build_info["last_commit_id"][:8] ) )
buf.write( ")</em></small>" )
buf.write( "." )
self.build_info.setText( buf.getvalue() )
else:
self.build_info.setText( "" )
self.home_url.setText(

Loading…
Cancel
Save