From: Kienan Stewart Date: Fri, 11 Oct 2024 12:57:06 +0000 (-0400) Subject: jjb: Add `to_groovy` filter to convert variables to groovy syntax X-Git-Url: http://git.lttng.org./?a=commitdiff_plain;h=7e91f7a75401b3f5f6caa50406e5d54a781cf29c;p=lttng-ci.git jjb: Add `to_groovy` filter to convert variables to groovy syntax To update jobs that use this filter, use recent jjb versions and execute it as follows: ``` PYTHONPATH=. jenkins-job update ./jobs/linux.yml ``` Change-Id: I09b4b5e3e57f4bfeb76eac00399f3bb885bb1b2b Signed-off-by: Kienan Stewart --- diff --git a/jjb_filters/__init__.py b/jjb_filters/__init__.py new file mode 100644 index 0000000..93e9f19 --- /dev/null +++ b/jjb_filters/__init__.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +""" +""" +import jinja2 +@jinja2.pass_environment +def do_groovy(env, data, skip_list_wrap=False): + list_format="[{}]" + if skip_list_wrap: + list_format="{}" + if isinstance(data, str): + return '"{}"'.format(data.replace('"', '\"')) + elif isinstance(data, list) or isinstance(data, tuple): + _data = [do_groovy(env, d) for d in data] + return list_format.format(", ".join(_data)) + elif isinstance(data, dict): + _data = ["{}: {}".format(key, do_groovy(env, value)) for key, value in data.items()] + return "[{}]".format(", ".join(_data)) + elif isinstance(data, bool): + return 'true' if data else 'false' + else: + raise Exception("Unknown data type: '{}'".format(type(data))) +FILTERS = { + "to_groovy": do_groovy, +}