From d24c8543879d3ac8709c8f8663fe2f6ff1bf41ab Mon Sep 17 00:00:00 2001 From: Taka Date: Fri, 24 Apr 2020 03:42:26 +0000 Subject: [PATCH] Updated for VASL 6.5.0. --- vasl_templates/webapp/config/site.cfg.example | 2 +- vasl_templates/webapp/static/help/index.html | 4 +- .../reverse-remapped-gpids-650.vsav | Bin 0 -> 4431 bytes .../webapp/tests/fixtures/gpid-remapping.json | 8 +- .../tests/fixtures/vasl-pieces-6.5.0.txt | 1219 +++++++++++++++++ .../tests/fixtures/vasl-pieces-legacy.txt | 1219 +++++++++++++++++ .../webapp/tests/fixtures/vasl-pieces.txt | 1219 ----------------- vasl_templates/webapp/tests/remote.py | 5 +- vasl_templates/webapp/tests/test_counters.py | 72 +- vasl_templates/webapp/tests/test_files.py | 4 +- vasl_templates/webapp/tests/test_vassal.py | 44 +- vasl_templates/webapp/vasl_mod.py | 90 +- vasl_templates/webapp/vassal.py | 19 +- 13 files changed, 2638 insertions(+), 1267 deletions(-) create mode 100644 vasl_templates/webapp/tests/fixtures/analyze-vsav/reverse-remapped-gpids-650.vsav create mode 100644 vasl_templates/webapp/tests/fixtures/vasl-pieces-6.5.0.txt create mode 100644 vasl_templates/webapp/tests/fixtures/vasl-pieces-legacy.txt delete mode 100644 vasl_templates/webapp/tests/fixtures/vasl-pieces.txt diff --git a/vasl_templates/webapp/config/site.cfg.example b/vasl_templates/webapp/config/site.cfg.example index adc1667..244aabe 100644 --- a/vasl_templates/webapp/config/site.cfg.example +++ b/vasl_templates/webapp/config/site.cfg.example @@ -2,7 +2,7 @@ ; configure VASSAL and VASL VASSAL_DIR = ...configure the VASSAL installation directory... -VASL_MOD = ...configure the VASL module (e.g. vasl-6.4.4.vmod)... +VASL_MOD = ...configure the VASL module (e.g. vasl-6.5.0.vmod)... VASL_EXTNS_DIR = ...configured the VASL extensions directory... BOARDS_DIR = ...configure the VASL boards directory... diff --git a/vasl_templates/webapp/static/help/index.html b/vasl_templates/webapp/static/help/index.html index 65d21f2..7e57ff5 100644 --- a/vasl_templates/webapp/static/help/index.html +++ b/vasl_templates/webapp/static/help/index.html @@ -79,7 +79,7 @@ and then connect to it in a browser at http://localhost:5010.

If you have Docker installed, the webapp can be run in a container e.g.

./run-container.sh --port 5010 \ - --vasl-vmod ~/vasl/vasl-6.4.4.vmod \ + --vasl-vmod ~/vasl/vasl-6.5.0.vmod \ --vasl-extensions ~/vasl/extensions/ \ --chapter-h ~/vasl/chapter-h/
@@ -132,7 +132,7 @@ The first thing we want to do is configure the program.

Choose Settings from the File menu and configure the highlighted settings. As a guide, here are some example settings:
VASSAL installation: C:/bin/vassal-3.2.17/ -
VASL module: C:/bin/vasl/vasl-6.4.4.vmod +
VASL module: C:/bin/vasl/vasl-6.5.0.vmod
VASL extensions: C:/bin/vasl/extensions/
VASL boards: C:/bin/vasl/boards/
Java: C:/bin/jPortable-8u201-x64/bin/java.exe diff --git a/vasl_templates/webapp/tests/fixtures/analyze-vsav/reverse-remapped-gpids-650.vsav b/vasl_templates/webapp/tests/fixtures/analyze-vsav/reverse-remapped-gpids-650.vsav new file mode 100644 index 0000000000000000000000000000000000000000..d0fccb22c8c39d8bed4f4429939c1f4392c8948b GIT binary patch literal 4431 zcmbVQXHXMdvqq3EAVL7?7?c|6ywpe$LJ_Ibi%1I~E!0qzB1*u}Q96X)t5Hf2q_>3L zMVj;=y~C$7_ulut-^_P^+~>?WXV2N$nP+!@?W3bfbd#QdjEs!H2pz9O@DGsxwmq$V z>}(;{E_T}%>hYy=cffriM7X!(&0BVmivSXjYoM1sMRfRmvE*%kAyjVftB5y=iAzSs zAy=2!>nk%FpSl>A@)|wzB^NiD8G{1Rl8R_?y|t0?<@6`X+hw;^ z4|_{h$4j1t;p#~!`Se@AY%qrHY7!! z;?$Y-xkiV380NNP7%n5f#(?F0wEuIqS!Jsg&W!T%s?1D*&+&IK2|liTGs%b<3J{aq zEL*v508!#bj)9E;ue50bi!PJ5_|K=nf!C%D$;0mpUNbmB&6GfGGM_7R9Q3TM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-}oPm;@`vmS+qZ0{2Qb+|0QkwF4Mn9{gcR_ dg8q$~-%)>;S4WeW 0: + assert compare_vasl_versions( SUPPORTED_VASL_MOD_VERSIONS[i-1], vasl_version ) < 0 + assert compare_vasl_versions( vasl_version, vasl_version ) == 0 + if i < len(SUPPORTED_VASL_MOD_VERSIONS)-1: + assert compare_vasl_versions( vasl_version, SUPPORTED_VASL_MOD_VERSIONS[i+1] ) < 0 diff --git a/vasl_templates/webapp/tests/test_files.py b/vasl_templates/webapp/tests/test_files.py index e8b0942..77f4961 100644 --- a/vasl_templates/webapp/tests/test_files.py +++ b/vasl_templates/webapp/tests/test_files.py @@ -117,10 +117,10 @@ def test_local_user_files( webapp, webdriver ): assert ex.code == 404 # try getting a file outside the configured directory (nb: should always fail) - fname = os.path.join( os.path.split(__file__)[0], "fixtures/vasl-pieces.txt" ) + fname = os.path.join( os.path.split(__file__)[0], "fixtures/vasl-pieces-legacy.txt" ) assert os.path.isfile( fname ) with pytest.raises( urllib.error.HTTPError ) as exc_info: - url = webapp.url_for( "get_user_file", path="../vasl-pieces.txt" ) + url = webapp.url_for( "get_user_file", path="../vasl-pieces-legacy.txt" ) resp = urllib.request.urlopen( url ) assert exc_info.value.code == 404 diff --git a/vasl_templates/webapp/tests/test_vassal.py b/vasl_templates/webapp/tests/test_vassal.py index ea81f13..402fb16 100644 --- a/vasl_templates/webapp/tests/test_vassal.py +++ b/vasl_templates/webapp/tests/test_vassal.py @@ -10,6 +10,7 @@ import typing.re #pylint: disable=import-error import pytest from vasl_templates.webapp.vassal import VassalShim +from vasl_templates.webapp.vasl_mod import compare_vasl_versions from vasl_templates.webapp.utils import TempFile, change_extn from vasl_templates.webapp import globvars from vasl_templates.webapp.tests.utils import \ @@ -604,9 +605,38 @@ def test_analyze_vsav_hip_concealed( webapp, webdriver ): # run the test against all versions of VASSAL+VASL _run_tests( control_tests, do_test, not pytest.config.option.short_tests ) #pylint: disable=no-member +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +@pytest.mark.skipif( not pytest.config.option.vasl_mods, reason="--vasl-mods not specified" ) #pylint: disable=no-member +@pytest.mark.skipif( not pytest.config.option.vassal, reason="--vassal not specified" ) #pylint: disable=no-member +def test_reverse_remapped_gpids( webapp, webdriver ): + """Test reverse mapping of GPID's.""" + + # initialize + control_tests = init_webapp( webapp, webdriver, vsav_persistence=1, scenario_persistence=1, + reset = lambda ct: ct.set_data_dir( dtype="real" ) + ) + + def do_test(): #pylint: disable=missing-docstring + + new_scenario() + set_player( 1, "american" ) + set_player( 2, "croatian" ) + _analyze_vsav( "reverse-remapped-gpids-650.vsav", + [ ["am/v:044"], ["am/o:002","am/o:021"] ], + [ ["cr/v:002","cr/v:003"], ["cr/o:000"] ], + [ "Imported 1 American vehicle and 2 ordnance.", "Imported 2 Croatian vehicles and 1 ordnance." ] + ) + + # run the test against all versions of VASSAL+VASL + _run_tests( control_tests, do_test, + not pytest.config.option.short_tests, #pylint: disable=no-member + min_vasl_version="6.5.0" + ) + # --------------------------------------------------------------------- -def _run_tests( control_tests, func, test_all ): +def _run_tests( control_tests, func, test_all, min_vasl_version=None ): """Run the test function for each combination of VASSAL + VASL. This is, of course, going to be insanely slow, since we need to spin up a JVM @@ -634,6 +664,12 @@ def _run_tests( control_tests, func, test_all ): for vassal_engine in vassal_engines: control_tests.set_vassal_engine( vengine=vassal_engine ) for vasl_mod in vasl_mods: + # FUDGE! We assume the version number is part of the filename. Otherwise, we have to load + # the vmod, extract the buildFile, parse the XML, etc. :-/ + mo = re.search( r"\d+\.\d+\.\d+", vasl_mod ) + vasl_version = mo.group() + if min_vasl_version and compare_vasl_versions( vasl_version, min_vasl_version ) < 0: + continue control_tests.set_vasl_mod( vmod=vasl_mod ) func() @@ -730,7 +766,11 @@ def _check_vsav_dump( vsav_dump, expected, ignore=None ): def _get_vsav_labels( vsav_dump ): """Extract the labels from a VSAV dump.""" - matches = re.finditer( r"AddPiece: DynamicProperty/User-Labeled.*?- Map", vsav_dump, re.DOTALL ) + # NOTE: We used to see things like: + # Map0;119;44;6295 + # but from 6.5.0, we're getting: + # Main Map;119;44;6295 + matches = re.finditer( r"AddPiece: DynamicProperty/User-Labeled.*?- (Main )?Map", vsav_dump, re.DOTALL ) labels = [ mo.group() for mo in matches ] regex = re.compile( r".*?" ) matches = [ regex.search(label) for label in labels ] diff --git a/vasl_templates/webapp/vasl_mod.py b/vasl_templates/webapp/vasl_mod.py index f1b9cdd..540c1fd 100644 --- a/vasl_templates/webapp/vasl_mod.py +++ b/vasl_templates/webapp/vasl_mod.py @@ -13,8 +13,8 @@ _logger = logging.getLogger( "vasl_mod" ) from vasl_templates.webapp import app, globvars from vasl_templates.webapp.config.constants import DATA_DIR -SUPPORTED_VASL_MOD_VERSIONS = [ "6.4.0", "6.4.1", "6.4.2", "6.4.3", "6.4.4" ] -SUPPORTED_VASL_MOD_VERSIONS_DISPLAY = "6.4.0-6.4.4" +SUPPORTED_VASL_MOD_VERSIONS = [ "6.4.0", "6.4.1", "6.4.2", "6.4.3", "6.4.4", "6.5.0" ] +SUPPORTED_VASL_MOD_VERSIONS_DISPLAY = "6.4.0-6.5.0" warnings = [] # nb: for the test suite @@ -167,10 +167,10 @@ class VaslMod: """Get the image for the specified piece.""" # get the image path - gpid = get_effective_gpid( gpid ) + gpid = get_remapped_gpid( self.vasl_version, gpid ) if gpid not in self._pieces: return None, None - piece = self._pieces[ get_effective_gpid( gpid ) ] + piece = self._pieces[ gpid ] assert side in ("front","back") image_paths = piece[ side + "_images" ] if not image_paths: @@ -198,7 +198,7 @@ class VaslMod: paths = piece[ "front_images" ] return paths if isinstance(paths,list) else [paths] return { - p["gpid"]: { + get_reverse_remapped_gpid( self.vasl_version, p["gpid"] ): { "name": p["name"], "front_images": image_count( p, "front_images" ), "back_images": image_count( p, "back_images" ), @@ -225,8 +225,13 @@ class VaslMod: fname = os.path.join( data_dir, "expected-multiple-images.json" ) expected_multiple_images = json.load( open( fname, "r" ) ) + # get the VASL version + build_info = self._files[0][0].read( "buildFile" ) + doc = xml.etree.ElementTree.fromstring( build_info ) + vasl_version = doc.attrib.get( "version" ) + # figure out which pieces we're interested in - target_gpids = get_vo_gpids( data_dir, self.get_extns() ) + target_gpids = get_vo_gpids( vasl_version, data_dir, self.get_extns() ) # parse the VASL module and any extensions for i,files in enumerate( self._files ): @@ -330,6 +335,8 @@ class VaslMod: return False if val.endswith( (".gif",".png") ): return True + if val.startswith( "," ): + val = val[1:] if val.startswith( ("ru/","ge/","am/","br/","it/","ja/","ch/","sh/","fr/","al/","ax/","hu/","fi/") ): return True return False @@ -406,7 +413,7 @@ class VaslMod: # --------------------------------------------------------------------- -def get_vo_gpids( data_dir, extns ): #pylint: disable=too-many-locals,too-many-branches +def get_vo_gpids( vasl_version, data_dir, extns ): #pylint: disable=too-many-locals,too-many-branches """Get the GPID's for the vehicles/ordnance.""" gpids = set() @@ -434,7 +441,7 @@ def get_vo_gpids( data_dir, extns ): #pylint: disable=too-many-locals,too-many-b entry_gpids = [ entry_gpids ] for gpid in entry_gpids: if gpid: - gpids.add( get_effective_gpid( str(gpid) ) ) + gpids.add( get_remapped_gpid( vasl_version, str(gpid) ) ) # process any extensions if extns: #pylint: disable=too-many-nested-blocks @@ -452,6 +459,16 @@ def get_vo_gpids( data_dir, extns ): #pylint: disable=too-many-locals,too-many-b return gpids +def compare_vasl_versions( lhs, rhs ): + """Compare two VASL version strings.""" + # NOTE: We can do this with a simple string comparison, but see test_compare_vasl_versions(). + if lhs < rhs: + return -1 + elif lhs > rhs: + return +1 + else: + return 0 + # --------------------------------------------------------------------- # VASL 6.4.3 removed several PieceSlot's. There's no comment for the commmit (0a27c24) @@ -461,11 +478,52 @@ def get_vo_gpids( data_dir, extns ): #pylint: disable=too-many-locals,too-many-b # but we can't just remove the now-missing GPID's, since any scenarios that use them # will break. This kind of thing is going to happen again, so we provide a generic mechanism # for dealing with this kind of thing... -GPID_REMAPPINGS = { - "7140": "2775", # SdKfz 10/5 - "7146": "2772", # SdKfz 10/4 -} - -def get_effective_gpid( gpid ): - """Return the effective GPID.""" - return GPID_REMAPPINGS.get( gpid, gpid ) +# VASL 6.5.0 introduced a bunch of changes, where pieces were mysteriously assigned a new GPID :-/ +GPID_REMAPPINGS = [ + [ "6.4.3", { + "7140": "2775", # SdKfz 10/5 + "7146": "2772", # SdKfz 10/4 + } ], + [ "6.5.0", { + "879": "12483", # 81* MTR M1 (American) + "900": "3b5:3741", # 12.7 AA M51 (American) + "1002": "11340", # M8 AC (American) + "1380": "3b5:7681", # Churchill Bridgelayer (British) + "3741": "11500", # 45L AT PTP obr. 32 (Axis Minor) + "3756": "11501", # 150L ART Skoda M28(NOa) (Axis Minor) + "3766": "11502", # 47L AA Skoda 47L40(t) (Axis Minor) + "3772": "11503", # 65* INF Cannone da 65/17 (Axis Minor) + "3896": "11504", # L6/40(i) (Axis Minor) + "3898": "11506", # wz. 34-I (Axis Minor) + "4059": "11524", # 40M Nimrod (Hungarian) + "4065": "11532", # 39M Csaba (Hungarian) + "6873": "7461", # T-26C (r) nb: also 7463 (Finnish) + # NOTE: Doug Rimmer confirms that the "FT-17 730m(f)" and "FT-17 730(f)" were probably incorrectly renamed + # to "FT-17 730(f)" and "FT-17 730(m)". However, the 7124 -> 11479 GPID change is still probably correct. + # He also suggests that 7124 and 7128 are incorrectly-added duplicates, and the correct ones + # are 2542 and 2544. + "7124": "11479", # FT-17 730m(f) (German) + } ] +] + +REVERSE_GPID_REMAPPINGS = [ + [ row[0], { v: k for k,v in row[1].items() } ] + for row in GPID_REMAPPINGS +] + +def get_remapped_gpid( vasl_version, gpid ): + """Check if a GPID has been remapped.""" + for remappings in GPID_REMAPPINGS: + # FUDGE! Early versions of this code (pre-6.5.0) always applied the remappings for 6.4.3, + # even for versions of VASL earlier than that. For simplicity, we preserve that behavior. + if compare_vasl_versions( remappings[0], "6.5.0" ) < 0 \ + or compare_vasl_versions( vasl_version, remappings[0] ) >= 0: + gpid = remappings[1].get( gpid, gpid ) + return gpid + +def get_reverse_remapped_gpid( vasl_version, gpid ): + """Check if a GPID has been remapped.""" + for remappings in REVERSE_GPID_REMAPPINGS: + if compare_vasl_versions( vasl_version, remappings[0] ) >= 0: + gpid = remappings[1].get( gpid, gpid ) + return gpid diff --git a/vasl_templates/webapp/vassal.py b/vasl_templates/webapp/vassal.py index a2a199d..0010f70 100644 --- a/vasl_templates/webapp/vassal.py +++ b/vasl_templates/webapp/vassal.py @@ -18,6 +18,7 @@ from vasl_templates.webapp import app, globvars from vasl_templates.webapp.config.constants import BASE_DIR, IS_FROZEN from vasl_templates.webapp.utils import TempFile, SimpleError from vasl_templates.webapp.webdriver import WebDriver +from vasl_templates.webapp.vasl_mod import get_reverse_remapped_gpid SUPPORTED_VASSAL_VERSIONS = [ "3.2.15" ,"3.2.16", "3.2.17" ] SUPPORTED_VASSAL_VERSIONS_DISPLAY = "3.2.15-.17" @@ -221,12 +222,26 @@ def analyze_vsav(): return VassalShim.translate_vassal_shim_exception( ex, logger ) + # translate any remapped GPID's back into their original values + # NOTE: We need to do this e.g. if we're analyzing a scenario that was created using VASL 6.5.0 + # and it contains pieces that had their GPID's changed from 6.4.4. This kind of nonsense + # is probably unsustainable over the long-term, but we try to maintain some semblance of + # back-compatibility for as long as we can :-/ + report2 = {} + for gpid,vals in report.items(): + orig_gpid = get_reverse_remapped_gpid( globvars.vasl_mod.vasl_version, gpid ) + if orig_gpid == gpid: + report2[ gpid ] = vals + else: + report2[ orig_gpid ] = vals + # return the results logger.info( "Analyzed the VSAV file OK: elapsed=%.3fs\n%s", time.time() - start_time, - pprint.pformat( report, indent=2, width=120 ) + pprint.pformat( report2, indent=2, width=120 ) ) - return jsonify( report ) + + return jsonify( report2 ) def _parse_analyze_report( fname ): """Read the analysis report generated by the VASSAL shim."""