Show a better error message if the VASL data directory is not there.

master
Pacman Ghost 1 year ago
parent bc87c398bb
commit 1c28ba4373
  1. 28
      vasl_templates/webapp/vasl_mod.py

@ -25,6 +25,12 @@ _warnings = [] # nb: for the test suite
# ---------------------------------------------------------------------
class CantFindDataDirException( Exception ):
"""Raised if the VASL data directory is missing."""
def __init__( self, vasl_version ):
super().__init__()
self.vasl_version = vasl_version
def set_vasl_mod( vmod_fname, msg_store ):
"""Install a new global VaslMod object."""
globvars.vasl_mod = None
@ -36,6 +42,13 @@ def set_vasl_mod( vmod_fname, msg_store ):
extns = _load_vasl_extns( extns_dir, msg_store )
try:
vasl_mod = VaslMod( vmod_fname, DATA_DIR, extns )
except CantFindDataDirException as ex:
msg = "Can't find the data directory for VASL {}." \
" Are you running an older version of this program?".format( ex.vasl_version )
_logger.error( "%s", msg )
if msg_store:
msg_store.error( msg )
return
except Exception as ex: #pylint: disable=broad-except
msg = "Can't load the VASL module: {}".format( ex )
_logger.error( "%s", msg )
@ -265,11 +278,20 @@ class VaslMod:
aliases = json.load( fp )
self.vasl_version = aliases.get( self.vasl_real_version, self.vasl_real_version )
# locate the VASL data files
# NOTE: We do this explicitly because people were running older versions of vasl-templates, configured
# with a version of VASL that it didn't know about. An exception was thrown when we tried to open
# the data files below, which was caught and reported correctly, but the error message was a little opaque,
# so we check for this case explicitly, and try to show something a little more comprehensible :-/
dname = os.path.join( data_dir, "vasl-"+self.vasl_version )
if not os.path.isdir( dname ):
raise CantFindDataDirException( self.vasl_version )
# load our overrides
fname = os.path.join( data_dir, "vasl-"+self.vasl_version, "vasl-overrides.json" )
fname = os.path.join( data_dir, dname, "vasl-overrides.json" )
with open( fname, "r", encoding="utf-8" ) as fp:
vasl_overrides = json.load( fp )
fname = os.path.join( data_dir, "vasl-"+self.vasl_version, "expected-multiple-images.json" )
fname = os.path.join( data_dir, dname, "expected-multiple-images.json" )
with open( fname, "r", encoding="utf-8" ) as fp:
expected_multiple_images = json.load( fp )
@ -277,7 +299,7 @@ class VaslMod:
target_gpids = get_vo_gpids( self )
# parse the VASL module and any extensions
fname = os.path.join( data_dir, "vasl-"+self.vasl_version, "piece-info.json" )
fname = os.path.join( data_dir, dname, "piece-info.json" )
with open( fname, "r", encoding="utf-8" ) as fp:
piece_info = json.load( fp )
for i,files in enumerate( self._files ):

Loading…
Cancel
Save