summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorAdriana Kobylak <anoo@us.ibm.com>2017-02-19 13:45:42 -0600
committerAdriana Kobylak <anoo@us.ibm.com>2017-02-28 10:47:37 -0600
commit371a38b7b6e8ea8ffce2d4bf245445c6cd0f5c4e (patch)
tree489bde3462ff3cf1ec395ff827c7bb899bec3222 /tools
parent6a9db6e414a7df7b616c33f04d0bbe224689180a (diff)
downloadphosphor-logging-371a38b7b6e8ea8ffce2d4bf245445c6cd0f5c4e.tar.gz
phosphor-logging-371a38b7b6e8ea8ffce2d4bf245445c6cd0f5c4e.zip
elog-gen.py: Dynamically determine the namespaces
Namespaces should be determined by the directory tree where the yaml files are located. Change-Id: I82729728b6aebf4c48a0ec967f2d08c1cbf8b7f3 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/elog-gen.py32
-rw-r--r--tools/phosphor-logging/templates/elog-gen-template.mako.hpp2
2 files changed, 19 insertions, 15 deletions
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
index 3cf396c..6ca8455 100755
--- a/tools/elog-gen.py
+++ b/tools/elog-gen.py
@@ -57,15 +57,17 @@ def check_error_inheritance(i_errors, i_parents):
def get_error_yaml_files(i_yaml_dir, i_test_dir):
- yaml_files = []
+ yaml_files = dict()
if i_yaml_dir != "None":
for root, dirs, files in os.walk(i_yaml_dir):
for files in filter(lambda file:
file.endswith('.errors.yaml'), files):
- yaml_files.append(os.path.join(root, files))
+ splitdir = root.split(i_yaml_dir)[1]
+ yaml_files[(os.path.join(root, files))] = splitdir
for root, dirs, files in os.walk(i_test_dir):
for files in filter(lambda file: file.endswith('.errors.yaml'), files):
- yaml_files.append(os.path.join(root, files))
+ splitdir = root.split(i_test_dir)[1]
+ yaml_files[(os.path.join(root, files))] = splitdir
return yaml_files
@@ -92,7 +94,7 @@ def get_cpp_type(i_type):
def gen_elog_hpp(i_yaml_dir, i_test_dir, i_output_hpp,
- i_template_dir, i_elog_mako, i_error_namespace):
+ i_template_dir, i_elog_mako):
r"""
Read yaml file(s) under input yaml dir, grab the relevant data and call
the mako template to generate the output header file.
@@ -112,6 +114,7 @@ def gen_elog_hpp(i_yaml_dir, i_test_dir, i_output_hpp,
meta = dict() # The meta data names associated (ERRNO, FILE_NAME, ...)
meta_data = dict() # The meta data info (type, format)
parents = dict()
+ namespace = dict()
error_yamls = get_error_yaml_files(i_yaml_dir, i_test_dir)
@@ -135,13 +138,15 @@ def gen_elog_hpp(i_yaml_dir, i_test_dir, i_output_hpp,
get_elog_data(error_yaml,
meta_yaml,
- # 3rd arg is a tuple
+ error_yamls[error_yaml],
+ # Last arg is a tuple
(errors,
error_msg,
error_lvl,
meta,
meta_data,
- parents))
+ parents,
+ namespace))
if(not check_error_inheritance(errors, parents)):
print("Error - failed to validate error inheritance")
@@ -157,13 +162,14 @@ def gen_elog_hpp(i_yaml_dir, i_test_dir, i_output_hpp,
f.write(template.render(
errors=errors, error_msg=error_msg,
error_lvl=error_lvl, meta=meta,
- meta_data=meta_data, error_namespace=i_error_namespace,
+ meta_data=meta_data, error_namespace=namespace,
parents=parents))
f.close()
def get_elog_data(i_elog_yaml,
i_elog_meta_yaml,
+ i_namespace,
o_elog_data):
r"""
Parse the error and metadata yaml files in order to pull out
@@ -172,9 +178,11 @@ def get_elog_data(i_elog_yaml,
Description of arguments:
i_elog_yaml error yaml file
i_elog_meta_yaml metadata yaml file
+ i_namespace namespace data
o_elog_data error metadata
"""
- errors, error_msg, error_lvl, meta, meta_data, parents = o_elog_data
+ errors, error_msg, error_lvl, meta, meta_data, parents, namespace = \
+ o_elog_data
ifile = yaml.safe_load(open(i_elog_yaml))
mfile = yaml.safe_load(open(i_elog_meta_yaml))
for i in mfile:
@@ -207,6 +215,7 @@ def get_elog_data(i_elog_yaml,
meta_data[str_short]['str_short'] = str_short
meta_data[str_short]['type'] = get_cpp_type(j['type'])
meta[i['name']] = tmp_meta
+ namespace[i['name']] = i_namespace
# Debug
# for i in errors:
@@ -240,18 +249,13 @@ def main(i_args):
default="phosphor-logging/templates/",
help="Base directory of files to process")
- parser.add_option("-n", "--namespace", dest="error_namespace",
- default="example/xyz/openbmc_project/Example",
- help="Error d-bus namespace")
-
(options, args) = parser.parse_args(i_args)
gen_elog_hpp(options.yamldir,
options.testdir,
options.output_hpp,
options.templatedir,
- options.elog_mako,
- options.error_namespace)
+ options.elog_mako)
# Only run if it's a script
if __name__ == '__main__':
diff --git a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
index f0b0818..097b865 100644
--- a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
+++ b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
@@ -17,7 +17,7 @@ namespace logging
% for index, name in enumerate(errors):
<%
- namespaces = error_namespace.split('/')
+ namespaces = error_namespace[name].split('/')
## In case someone provided a error_namespace ending with '/', remove the
## last split string, which would be an empty string.
if not namespaces[-1]:
OpenPOWER on IntegriCloud