elog-gen: handle missing YAML without crashing
The code to build the mako template path was buried inside a
for-loop, which ran against every found YAML file (redundantly).
If, for some reason, the script is configured where the error
YAML is missing, the for-loop never runs and we end up with a
Python crash:
File "../tools/elog-gen.py", line 167, in gen_elog_hpp
template = Template(filename=template_path)
UnboundLocalError: local variable 'template_path' referenced
before assignment
Pull the template path code out of the for loop to better handle
this case.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ic3dd4e8d9c7a9a9ed4fa382b879ecdc4b1b04838
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
index 9b9edac..ede916a 100755
--- a/tools/elog-gen.py
+++ b/tools/elog-gen.py
@@ -125,6 +125,13 @@
parents = dict()
metadata_process = dict() # metadata that have the 'process' keyword set
+ # Verify the input mako file
+ template_path = os.path.join(i_template_dir, i_elog_mako)
+ if (not (os.path.isfile(template_path))):
+ print("Cannot find input template file " + template_path)
+ exit(1)
+ template_path = os.path.abspath(template_path)
+
error_yamls = get_error_yaml_files(i_yaml_dir, i_test_dir)
for error_yaml in error_yamls:
@@ -136,13 +143,6 @@
# Verify the metadata yaml file
meta_yaml = get_meta_yaml_file(error_yaml)
- # Verify the input mako file
- template_path = os.path.join(i_template_dir, i_elog_mako)
- if (not (os.path.isfile(template_path))):
- print("Cannot find input template file " + template_path)
- exit(1)
- template_path = os.path.abspath(template_path)
-
get_elog_data(error_yaml,
meta_yaml,
error_yamls[error_yaml],