Handle errors in data files.

master
Pacman Ghost 3 years ago
parent b01b302364
commit d6cb63adea
  1. 24
      asl_rulebook2/webapp/rule_info.py

@ -70,13 +70,14 @@ def init_qa( startup_msgs, logger ):
if os.path.isfile( fname ): if os.path.isfile( fname ):
logger.info( "Loading Q+A fixups: %s", fname ) logger.info( "Loading Q+A fixups: %s", fname )
fixups = load_data_file( fname, "fixups", False, logger, startup_msgs.warning ) fixups = load_data_file( fname, "fixups", False, logger, startup_msgs.warning )
for qa_entries in qa.values(): if fixups:
for qa_entry in qa_entries: for qa_entries in qa.values():
for content in qa_entry.get( "content", [] ): for qa_entry in qa_entries:
if "question" in content: for content in qa_entry.get( "content", [] ):
content["question"] = _apply_fixups( content["question"], fixups ) if "question" in content:
for answer in content.get( "answers", [] ): content["question"] = _apply_fixups( content["question"], fixups )
answer[0] = _apply_fixups( answer[0], fixups ) for answer in content.get( "answers", [] ):
answer[0] = _apply_fixups( answer[0], fixups )
# load the Q+A sources # load the Q+A sources
sources = {} sources = {}
@ -162,9 +163,10 @@ def init_errata( startup_msgs, logger ):
if os.path.isfile( fname ): if os.path.isfile( fname ):
logger.info( "Loading errata fixups: %s", fname ) logger.info( "Loading errata fixups: %s", fname )
fixups = load_data_file( fname, "fixups", False, logger, startup_msgs.warning ) fixups = load_data_file( fname, "fixups", False, logger, startup_msgs.warning )
for ruleid in _errata: if fixups:
for anno in _errata[ruleid]: for ruleid in _errata:
anno["content"] = _apply_fixups( anno["content"], fixups ) for anno in _errata[ruleid]:
anno["content"] = _apply_fixups( anno["content"], fixups )
# load the errata sources # load the errata sources
sources = {} sources = {}
@ -189,6 +191,8 @@ def _load_anno( fname, atype, save_loc, logger, startup_msgs ):
"""Load annotations from a data file.""" """Load annotations from a data file."""
logger.info( "Loading %s: %s", atype, fname ) logger.info( "Loading %s: %s", atype, fname )
anno_entries = load_data_file( fname, atype, False, logger, startup_msgs.warning ) anno_entries = load_data_file( fname, atype, False, logger, startup_msgs.warning )
if not anno_entries:
return
for anno in anno_entries: for anno in anno_entries:
if anno["ruleid"] in save_loc: if anno["ruleid"] in save_loc:
save_loc[ anno["ruleid"] ].append( anno ) save_loc[ anno["ruleid"] ].append( anno )

Loading…
Cancel
Save