Show the desktop build info in the Program Info dialog.

master
Pacman Ghost 3 years ago
parent 2a8f5f97aa
commit b23199228e
  1. 2
      Dockerfile
  2. 23
      vasl_templates/about.py
  3. 27
      vasl_templates/utils.py
  4. 14
      vasl_templates/webapp/main.py
  5. 8
      vasl_templates/webapp/templates/program-info-content.html

@ -61,7 +61,7 @@ ENV PATH="/opt/venv/bin:$PATH"
# install the application
WORKDIR /app
COPY vasl_templates/webapp/ ./vasl_templates/webapp/
COPY vasl_templates/ ./vasl_templates/
COPY vassal-shim/release/vassal-shim.jar ./vassal-shim/release/
COPY setup.py requirements.txt requirements-dev.txt LICENSE.txt ./
RUN pip3 install --editable .

@ -2,7 +2,6 @@
import sys
import os
import json
import time
import io
import re
@ -12,7 +11,8 @@ from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QDesktopServices, QIcon, QCursor
from PyQt5.QtWidgets import QDialog
from vasl_templates.webapp.config.constants import APP_NAME, APP_VERSION, APP_HOME_URL, BASE_DIR, IS_FROZEN
from vasl_templates.webapp.config.constants import APP_NAME, APP_VERSION, APP_HOME_URL, IS_FROZEN
from vasl_templates.utils import get_build_info
# ---------------------------------------------------------------------
@ -41,28 +41,17 @@ class AboutDialog( QDialog ):
self.app_icon.mouseReleaseEvent = self.on_app_icon_clicked
self.app_icon.setCursor( QCursor( QtCore.Qt.PointingHandCursor ) )
# get the build info
dname = os.path.join( BASE_DIR, "config" )
fname = os.path.join( dname, "build-info.json" )
if os.path.isfile( fname ):
build_info = json.load( open( fname, "r" ) )
else:
build_info = None
# load the dialog
self.app_name.setText( "{} ({})".format( APP_NAME, APP_VERSION ) )
self.license.setText( "Licensed under the GNU Affero General Public License (v3)." )
build_info = get_build_info()
if build_info:
buf = io.StringIO()
timestamp = build_info[ "timestamp" ]
buf.write( "Built {}".format(
time.strftime( "%d %B %Y %H:%S", time.localtime( timestamp ) ) # nb: "-d" doesn't work on Windows :-/
time.strftime( "%d %B %Y %H:%M", time.localtime( build_info["timestamp"] ) )
) )
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>" )
if "git_info" in build_info:
buf.write( " <small><em>({})</em></small>".format( build_info["git_info"] ) )
buf.write( "." )
self.build_info.setText( buf.getvalue() )
else:

@ -1,8 +1,35 @@
""" Miscellaneous utilities. """
import os
import functools
import logging
import traceback
import json
from vasl_templates.webapp.config.constants import BASE_DIR
# ---------------------------------------------------------------------
def get_build_info():
"""Get the program build info."""
# locate and load the build info file
fname = os.path.join( BASE_DIR, "config", "build-info.json" )
if not os.path.isfile( fname ):
return None
build_info = json.load( open( fname, "r" ) )
# get the build timestamp
result = { "timestamp": build_info["timestamp"] }
# get the git info
if "branch_name" in build_info:
git_info = build_info[ "branch_name" ]
if "last_commit_id" in build_info:
git_info += ":{}".format( build_info["last_commit_id"][:8] )
result["git_info"] = git_info
return result
# ---------------------------------------------------------------------

@ -15,9 +15,10 @@ from vasl_templates.webapp import app, shutdown_event
from vasl_templates.webapp.vassal import VassalShim
from vasl_templates.webapp.utils import MsgStore, parse_int
import vasl_templates.webapp.config.constants
from vasl_templates.webapp.config.constants import BASE_DIR, DATA_DIR
from vasl_templates.webapp.config.constants import BASE_DIR, DATA_DIR, IS_FROZEN
from vasl_templates.webapp import globvars
from vasl_templates.webapp.lfa import DEFAULT_LFA_DICE_HOTNESS_WEIGHTS, DEFAULT_LFA_DICE_HOTNESS_THRESHOLDS
from vasl_templates.utils import get_build_info
# NOTE: This is used to stop multiple instances of the program from running (see main.py in the desktop app).
INSTANCE_ID = uuid.uuid4().hex
@ -197,6 +198,17 @@ def get_program_info():
"""Replace a mount point with its corresponding target (on the host)."""
params[ key ] = os.environ.get( "{}_TARGET".format( key ) )
# check if we are running the desktop application
if IS_FROZEN:
# yup - return information about the build
build_info = get_build_info()
if build_info:
params[ "BUILD_TIMESTAMP" ] = datetime.strftime(
to_localtime( datetime.utcfromtimestamp( build_info["timestamp"] ) ),
"%H:%M (%d %b %Y)"
)
params[ "BUILD_GIT_INFO" ] = build_info[ "git_info" ]
# check if we are running inside a Docker container
if app.config.get( "IS_CONTAINER" ):
# yup - return related information

@ -1,3 +1,11 @@
{%if BUILD_TIMESTAMP%}
<table>
<tr> <td class="key"> Build date:
<td class="val"> {{BUILD_TIMESTAMP}}
{%if BUILD_GIT_INFO%} <span class="info"> ({{BUILD_GIT_INFO}}) </span> {%endif%}
</table>
{%endif%}
{%if DOCKER_CONTAINER_ID%}
<table>
<tr> <td class="key"> Docker container:

Loading…
Cancel
Save