Show a warning if an unsupported version of VASSAL or VASL is being used.

master
Pacman Ghost 5 years ago
parent 103423f193
commit eadb681d84
  1. 8
      vasl_templates/webapp/file_server/vasl_mod.py
  2. 15
      vasl_templates/webapp/static/main.js
  3. 2
      vasl_templates/webapp/templates/index.html
  4. 37
      vasl_templates/webapp/vassal.py
  5. BIN
      vassal-shim/release/vassal-shim.jar
  6. 14
      vassal-shim/src/vassal_shim/Main.java

@ -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."""

@ -268,6 +268,21 @@ $(document).ready( function () {
showErrorMsg( "Can't get the template pack:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
} ) ;
// 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:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
} ) ;
$.get( gCheckVaslVersionUrl, function( resp ) {
if ( resp )
showWarningMsg( resp ) ;
} ).fail( function( xhr, status, errorMsg ) {
showErrorMsg( "Can't check the VASL version:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
} ) ;
// fixup the layout
var prevHeight = [] ;
$(window).resize( function() {
// FUDGE! CSS grids don't seem to update their layout vertically when

@ -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)}}" ;

@ -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.<p>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.<p>Things might work, but they might not...".format( vasl_mod.vasl_version )
return ""

@ -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 ) ;

Loading…
Cancel
Save