From 434509e22a2ce3578e226bcaa68d4d2b4ceece2b Mon Sep 17 00:00:00 2001 From: Trevor Bramwell Date: Fri, 16 Mar 2018 14:14:12 -0700 Subject: Make Apex JJB Renderer Importable Wrapping the script into a function will make it importable from other python code. Calling the file directly will still work as it did before. Change-Id: I8336d34b05687fa650ce1c123bb37fa311ce2978 Signed-off-by: Trevor Bramwell --- jjb/apex/apex-jjb-renderer.py | 50 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 21 deletions(-) (limited to 'jjb/apex') diff --git a/jjb/apex/apex-jjb-renderer.py b/jjb/apex/apex-jjb-renderer.py index 6fd83afe9..b67784376 100644 --- a/jjb/apex/apex-jjb-renderer.py +++ b/jjb/apex/apex-jjb-renderer.py @@ -12,30 +12,38 @@ import yaml from jinja2 import Environment from jinja2 import FileSystemLoader -gspathname = dict() -branch = dict() -build_slave = dict() -env = Environment(loader=FileSystemLoader('./'), autoescape=True) -with open('scenarios.yaml.hidden') as _: - scenarios = yaml.safe_load(_) +def render_jjb(): + """Render JJB output from scenarios.yaml.hidden file and jinja + template""" -template = env.get_template('apex.yml.j2') + gspathname = dict() + branch = dict() + build_slave = dict() + env = Environment(loader=FileSystemLoader('./'), autoescape=True) -print("Scenarios are: ") -pprint.pprint(scenarios) + with open('scenarios.yaml.hidden') as _: + scenarios = yaml.safe_load(_) -for stream in scenarios: - if stream == 'master': - gspathname['master'] = '' - branch[stream] = stream - else: - gspathname[stream] = '/' + stream - branch[stream] = 'stable/' + stream - build_slave[stream] = 'apex-baremetal-{}'.format(stream) + template = env.get_template('apex.yml.j2') -output = template.render(scenarios=scenarios, gspathname=gspathname, - branch=branch, build_slave=build_slave) + print("Scenarios are: ") + pprint.pprint(scenarios) -with open('./apex.yml', 'w') as fh: - fh.write(output) + for stream in scenarios: + if stream == 'master': + gspathname['master'] = '' + branch[stream] = stream + else: + gspathname[stream] = '/' + stream + branch[stream] = 'stable/' + stream + build_slave[stream] = 'apex-baremetal-{}'.format(stream) + + output = template.render(scenarios=scenarios, gspathname=gspathname, + branch=branch, build_slave=build_slave) + + with open('./apex.yml', 'w') as fh: + fh.write(output) + +if __name__ == "__main__": + render_jjb() -- cgit 1.2.3-korg