Tightened up how we check the VASSAL version.

master
Pacman Ghost 4 years ago
parent 59a05e7a22
commit e2638fe609
  1. 8
      vasl_templates/webapp/main.py
  2. 18
      vasl_templates/webapp/vassal.py

@ -73,11 +73,11 @@ def get_app_config():
}
for key in ["APP_NAME","APP_VERSION","APP_DESCRIPTION","APP_HOME_URL"]:
vals[ key ] = getattr( vasl_templates.webapp.config.constants, key )
from vasl_templates.webapp.vassal import VassalShim
try:
from vasl_templates.webapp.vassal import VassalShim
vals[ "VASSAL_VERSION" ] = VassalShim().get_version()
except: #pylint: disable=bare-except
pass
vals[ "VASSAL_VERSION" ] = VassalShim.get_version()
except Exception as ex: #pylint: disable=broad-except
logging.error( "Can't check the VASSAL version: %s", str(ex) )
if globvars.vasl_mod:
vals["VASL_VERSION"] = globvars.vasl_mod.vasl_version
return jsonify( vals )

@ -282,12 +282,16 @@ class VassalShim:
if not os.path.isfile( self.shim_jar ):
raise SimpleError( "Can't find the VASSAL shim JAR." )
def get_version( self ):
@staticmethod
def get_version():
"""Get the VASSAL version."""
vassal_dir = app.config.get( "VASSAL_DIR" )
if not vassal_dir:
return None
# FUDGE! We can't capture the output on Windows, get the result in a temp file instead :-/
with TempFile() as temp_file:
temp_file.close()
self._run_vassal_shim( "version", temp_file.name )
VassalShim()._run_vassal_shim( "version", temp_file.name ) #pylint: disable=protected-access
with open( temp_file.name, "r" ) as fp:
return fp.read()
@ -443,7 +447,12 @@ class VassalShim:
"""Check the version of VASSAL."""
if not app.config.get( "VASSAL_DIR" ) or not msg_store:
return
version = VassalShim().get_version()
try:
version = VassalShim.get_version()
except Exception as ex: #pylint: disable=broad-except
if msg_store:
msg_store.error( "Can't get the VASSAL version: <p> {}", ex )
return
if version not in SUPPORTED_VASSAL_VERSIONS:
if msg_store:
msg_store.warning(
@ -461,3 +470,6 @@ class VassalShimError( Exception ):
self.retcode = retcode
self.stdout = stdout
self.stderr = stderr
def __str__( self ):
return "VassalShim error: rc={}".format( self.retcode )

Loading…
Cancel
Save