Log a warning if key data files are not found.

master
Pacman Ghost 3 years ago
parent 51b034f260
commit 5f9b4e795c
  1. 17
      asl_rulebook2/webapp/content.py
  2. 3
      asl_rulebook2/webapp/utils.py
  3. 1
      conftest.py

@ -55,11 +55,17 @@ def load_content_sets( startup_msgs, logger ):
def load_content_doc( fname_stem, title, cdoc_id ):
# load the content doc files
content_doc = { "cdoc_id": cdoc_id, "title": title }
if load_file( fname_stem+".targets", content_doc, "targets", startup_msgs.warning ):
fname = fname_stem + ".targets"
if load_file( fname, content_doc, "targets", startup_msgs.warning ):
# update the target index
_target_index[ cdoc_id ] = {}
for ruleid, target in content_doc.get( "targets", {} ).items():
_target_index[ cdoc_id ][ ruleid ] = target
else:
# NOTE: Things will work without this file, but from the user's point of view,
# they've probably set something up incorrectly, so we give them a hint.
if not app.config.get( "IGNORE_MISSING_DATA_FILES" ):
logger.warn( "Didn't find targets file: %s", fname )
load_file( fname_stem+".chapters", content_doc, "chapters", startup_msgs.warning )
if load_file( fname_stem+".footnotes", content_doc, "footnotes", startup_msgs.warning ):
# update the footnote index
@ -75,7 +81,12 @@ def load_content_sets( startup_msgs, logger ):
if ruleid not in _footnote_index[ cdoc_id ]:
_footnote_index[ cdoc_id ][ ruleid ] = []
_footnote_index[ cdoc_id ][ ruleid ].append( footnote )
load_file( fname_stem+".pdf", content_doc, "content", startup_msgs.warning, binary=True )
fname = fname_stem + ".pdf"
if not load_file( fname, content_doc, "content", startup_msgs.warning, binary=True ):
# NOTE: Things will work without this file, but from the user's point of view,
# they've probably set something up incorrectly, so we give them a hint.
if not app.config.get( "IGNORE_MISSING_DATA_FILES" ):
logger.warn( "Didn't find content file: %s", fname )
# locate any chapter backgrounds and icons
resource_dirs = [
data_dir, os.path.join( os.path.dirname(__file__), "data/chapters/" )
@ -120,7 +131,7 @@ def load_content_sets( startup_msgs, logger ):
fspec = os.path.join( data_dir, "*.index" )
for fname in sorted( glob.glob( fspec ) ):
fname2 = os.path.basename( fname )
logger.info( "- %s", fname2 )
logger.info( "- Found index file: %s", fname2 )
# load the index file
title = os.path.splitext( fname2 )[0]
cset_id = slugify( title )

@ -25,14 +25,13 @@ def load_data_file( fname, ftype, binary, logger, on_error ):
"""Load a data file."""
try:
# load the file
logger.debug("- Loading %s: %s", ftype, fname )
if binary:
with open( fname, mode="rb" ) as fp:
data = fp.read()
logger.debug( "- Loaded \"%s\" file: #bytes=%d", ftype, len(data) )
else:
with open( fname, "r", encoding="utf-8" ) as fp:
data = json.load( fp )
logger.debug( "- Loaded \"%s\" file.", ftype )
except Exception as ex: #pylint: disable=broad-except
msg = "Couldn't load \"{}\".".format( os.path.basename(fname) )
on_error( msg, str(ex) )

@ -121,6 +121,7 @@ def _make_webapp():
app.config.pop( "DATA_DIR", None )
app.config.pop( "WEBAPP_INITIAL_QUERY_STRING", None )
app.config.pop( "DISABLE_FIXUP_CONTENT", None )
app.config[ "IGNORE_MISSING_DATA_FILES" ] = True
# NOTE: We run the server thread as a daemon so that it won't prevent the tests from finishing
# when they're done. However, this makes it difficult to know when to shut the server down,
# and, in particular, clean up the gRPC service. We send an EndTests message at the end of each test,

Loading…
Cancel
Save