From e2638fe609cfbe5b1f8923c794218cc5ad766109 Mon Sep 17 00:00:00 2001 From: Taka Date: Wed, 6 May 2020 11:53:06 +0000 Subject: [PATCH] Tightened up how we check the VASSAL version. --- vasl_templates/webapp/main.py | 8 ++++---- vasl_templates/webapp/vassal.py | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/vasl_templates/webapp/main.py b/vasl_templates/webapp/main.py index 0f7fd5b..0756965 100644 --- a/vasl_templates/webapp/main.py +++ b/vasl_templates/webapp/main.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 ) diff --git a/vasl_templates/webapp/vassal.py b/vasl_templates/webapp/vassal.py index 0010f70..f8ef46d 100644 --- a/vasl_templates/webapp/vassal.py +++ b/vasl_templates/webapp/vassal.py @@ -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:

{}", 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 )