From eadb681d84c5740e12e536ce23c2ab4d79f9d88c Mon Sep 17 00:00:00 2001 From: Taka Date: Wed, 28 Nov 2018 05:41:43 +0000 Subject: [PATCH] Show a warning if an unsupported version of VASSAL or VASL is being used. --- vasl_templates/webapp/file_server/vasl_mod.py | 8 ++-- vasl_templates/webapp/static/main.js | 15 +++++++ vasl_templates/webapp/templates/index.html | 2 + vasl_templates/webapp/vassal.py | 37 +++++++++++++++++- vassal-shim/release/vassal-shim.jar | Bin 26840 -> 27037 bytes vassal-shim/src/vassal_shim/Main.java | 14 +++++++ 6 files changed, 72 insertions(+), 4 deletions(-) diff --git a/vasl_templates/webapp/file_server/vasl_mod.py b/vasl_templates/webapp/file_server/vasl_mod.py index f91936d..a878f98 100644 --- a/vasl_templates/webapp/file_server/vasl_mod.py +++ b/vasl_templates/webapp/file_server/vasl_mod.py @@ -25,7 +25,9 @@ class VaslMod: # parse the VASL module file _logger.info( "Loading VASL module: %s", fname ) self.zip_file = zipfile.ZipFile( fname, "r" ) - self._parse_vmod( data_dir ) + self.vasl_version = self._parse_vmod( data_dir ) + if self.vasl_version not in SUPPORTED_VASL_MOD_VERSIONS: + _logger.warning( "Unsupported VASL version: %s", self.vasl_version ) def get_piece_image( self, gpid, side, index ): """Get the image for the specified piece.""" @@ -92,8 +94,6 @@ class VaslMod: # parse the VASL build info build_info = self.zip_file.read( "buildFile" ) doc = xml.etree.ElementTree.fromstring( build_info ) - if doc.attrib.get( "version" ) not in SUPPORTED_VASL_MOD_VERSIONS: - _logger.warning( "Unsupported VASL version: %s", doc.attrib.get("version") ) for node in doc.iter( "VASSAL.build.widget.PieceSlot" ): # load the next entry @@ -149,6 +149,8 @@ class VaslMod: gpids = ", ".join( expected_multiple_images.keys() ) _logger.warning( "Expected multiple images but didn't find them: %s", gpids ) + return doc.attrib.get( "version" ) + @staticmethod def _get_image_paths( gpid, val ): #pylint: disable=too-many-branches """Get the image path(s) for a piece.""" diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index 6899c61..e65e793 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -268,6 +268,21 @@ $(document).ready( function () { showErrorMsg( "Can't get the template pack:
" + escapeHTML(errorMsg) + "
" ) ; } ) ; + // check the VASSAL/VASL versions + $.get( gCheckVassalVersionUrl, function( resp ) { + if ( resp ) + showWarningMsg( resp ) ; + } ).fail( function( xhr, status, errorMsg ) { + showErrorMsg( "Can't check the VASSAL version:
" + escapeHTML(errorMsg) + "
" ) ; + } ) ; + $.get( gCheckVaslVersionUrl, function( resp ) { + if ( resp ) + showWarningMsg( resp ) ; + } ).fail( function( xhr, status, errorMsg ) { + showErrorMsg( "Can't check the VASL version:
" + escapeHTML(errorMsg) + "
" ) ; + } ) ; + + // fixup the layout var prevHeight = [] ; $(window).resize( function() { // FUDGE! CSS grids don't seem to update their layout vertically when diff --git a/vasl_templates/webapp/templates/index.html b/vasl_templates/webapp/templates/index.html index 2acc181..092290e 100644 --- a/vasl_templates/webapp/templates/index.html +++ b/vasl_templates/webapp/templates/index.html @@ -88,6 +88,8 @@ gAppName = "{{APP_NAME}}" ; gAppVersion = "{{APP_VERSION}}" ; gImagesBaseUrl = "{{url_for('static',filename='images')}}" ; +gCheckVassalVersionUrl = "{{url_for('check_vassal_version')}}" ; +gCheckVaslVersionUrl = "{{url_for('check_vasl_version')}}" ; gGetTemplatePackUrl = "{{url_for('get_template_pack')}}" ; gGetDefaultScenarioUrl = "{{url_for('get_default_scenario')}}" ; gVehicleListingsUrl = "{{url_for('get_vehicle_listings',merge_common=1)}}" ; diff --git a/vasl_templates/webapp/vassal.py b/vasl_templates/webapp/vassal.py index 6cd2dc8..818c666 100644 --- a/vasl_templates/webapp/vassal.py +++ b/vasl_templates/webapp/vassal.py @@ -16,6 +16,8 @@ from flask import request from vasl_templates.webapp import app from vasl_templates.webapp.config.constants import BASE_DIR, IS_FROZEN +from vasl_templates.webapp.files import vasl_mod +from vasl_templates.webapp.file_server.vasl_mod import SUPPORTED_VASL_MOD_VERSIONS from vasl_templates.webapp.utils import TempFile, HtmlScreenshots, SimpleError _logger = logging.getLogger( "update_vsav" ) @@ -252,6 +254,15 @@ class VassalShim: if not os.path.isfile( self.shim_jar ): raise SimpleError( "Can't find the VASSAL shim JAR." ) + def get_version( self ): + """Get the VASSAL version.""" + # 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 ) + with open( temp_file.name, "r" ) as fp: + return fp.read() + def dump_scenario( self, fname ): """Dump a scenario file.""" return self._run_vassal_shim( "dump", fname ) @@ -279,8 +290,10 @@ class VassalShim: class_path = sep.join( class_path ) args2 = [ java_path, "-classpath", class_path, "vassal_shim.Main", - args[0], self.vasl_mod + args[0] ] + if args[0] in ("dump","update"): + args2.append( self.vasl_mod ) args2.extend( args[1:] ) # figure out how long to the let the VASSAL shim run @@ -347,3 +360,25 @@ class VassalShimError( Exception ): self.retcode = retcode self.stdout = stdout self.stderr = stderr + +# --------------------------------------------------------------------- + +@app.route( "/check-vassal-version" ) +def check_vassal_version(): + """Check if we're running a supported version of VASSAL.""" + vassal_dir = app.config.get( "VASSAL_DIR" ) + if vassal_dir: + vassal_shim = VassalShim() + version = vassal_shim.get_version() + if version not in SUPPORTED_VASSAL_VERSIONS: + return "VASSAL {} is unsupported.

Things might work, but they might not...".format( version ) + return "" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +@app.route( "/check-vasl-version" ) +def check_vasl_version(): + """Check if we're running a supported version of VASL.""" + if vasl_mod and vasl_mod.vasl_version not in SUPPORTED_VASL_MOD_VERSIONS: + return "VASL {} is unsupported.

Things might work, but they might not...".format( vasl_mod.vasl_version ) + return "" diff --git a/vassal-shim/release/vassal-shim.jar b/vassal-shim/release/vassal-shim.jar index e1d4324f18f26fa8f7a03155be7a62d6151fb793..9c45bc3859ba1a299b59327a97e92bf00ce7c374 100644 GIT binary patch delta 1912 zcmZ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X`HM9xc2^P`MGh8RaBRn*u&-%AkSAB`GRl zY;qZ)I>h|dB6{hZc7F09y6}k2pRlL<>dvWjF6}}6YL%sM+ElSwFNn6>bc{Dcjdd#; zjG723yQ6kVu*lyvtbNe@vB8}2e26hstl2l3`c`^qsp#I{oWCYVmqZnZO(t-kW@Bp^ zGC^l{ZIxMhZ3Wnz8JT7W)=l?HQ@(jRc8yyv#XoDvE=W(~QteC1?wX;`d9brQ9jj9< z4r5;8U58}TOk9eSt~qS8v)T5p=))K{pf|xkaqiOO_4wn@E8=WPRgHr|B%aLInb)EJ zAeZGmpi-tK>Q?OI6wY=L&t_>0O_Q4FrwBf=TfMKo(<6H#l$%it(=7@B5TXnKKSW-O zp{9+ZJnh2QY9i!m*Aw^?6hu~Ssnq>qDrZW(`W55_eQzvWUX1une=m9hx5$TDUWX2X z^67RuL5?5kTsg*u*J!L{sMmiEAOnV#oC;=OLCP8^k+J3H)ef7V9Lam&0MMWW065_P zCm#cKGxmbk+7OAn0osK?LlX?Ne5S>on=@((0Bv*t(Ea}ia2~tTtPNG_DnYps>TgFV!^opNEEmcN{qyVu0irG4#5cM&dOCnh2BMaS$y6H0O4WrVJ2ix j7>EJ>{dc?))u^~E5CA$90Ra7j!Ul*Fg;RR9fA#SnkzMed diff --git a/vassal-shim/src/vassal_shim/Main.java b/vassal-shim/src/vassal_shim/Main.java index f8ba7e6..299a215 100644 --- a/vassal-shim/src/vassal_shim/Main.java +++ b/vassal-shim/src/vassal_shim/Main.java @@ -1,5 +1,10 @@ package vassal_shim ; +import java.io.BufferedWriter ; +import java.io.FileWriter ; + +import VASSAL.Info ; + import vassal_shim.VassalShim ; // -------------------------------------------------------------------- @@ -29,6 +34,15 @@ public class Main shim.updateScenario( args[3], args[4], args[5], args[6] ) ; System.exit( 0 ) ; } + else if ( cmd.equals( "version" ) ) { + checkArgs( args, 2, "the output file" ) ; + System.out.println( Info.getVersion() ) ; + // FUDGE! The Python web server can't capture output on Windows - save the result to a file as well :-/ + BufferedWriter writer = new BufferedWriter( new FileWriter( args[1] ) ) ; + writer.write( Info.getVersion() ) ; + writer.close() ; + System.exit( 0 ) ; + } else { System.out.println( "Unknown command: " + cmd ) ; System.exit( 1 ) ;