diff --git a/.vscode/launch.json b/.vscode/launch.json index 5d5c8e985..f68486265 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "type": "python", "python": "/dls_sw/prod/tools/RHEL7-x86_64/defaults/bin/dls-python", "request": "launch", - "program": "builder2ibek.support.py", + "program": "dls_builder_conversion/builder2ibek.support.py", "console": "integratedTerminal", "args": [ "/dls_sw/prod/R3.14.12.7/support/ADCore/3-9dls2", diff --git a/dls_builder_conversion/builder2ibek.support.py b/dls_builder_conversion/builder2ibek.support.py index 004fa60a5..34c69e370 100755 --- a/dls_builder_conversion/builder2ibek.support.py +++ b/dls_builder_conversion/builder2ibek.support.py @@ -42,6 +42,8 @@ is_float_re = re.compile(r"[-+]?\d*\.\d+([eE][-+]?\d+)?$") # this monster regex finds strings between '' or "" (just wow!) extract_printed_strings_re = re.compile(r"([\"'])((?:\\\1|(?:(?!\1))[\S\s])*)(?:\1)") +macros_re = re.compile(r"%\((.*?)\).|\n") +macro_to_jinja_re = r"{{\1}}" class Builder2Support: @@ -262,7 +264,8 @@ def _make_init_script(self, builder_object, func_name, typ, script): for print_string in print_strings: matches = extract_printed_strings_re.findall(print_string) if matches: - script_item["value"].append(matches[0][1]) + line = macros_re.sub(macro_to_jinja_re, matches[0][1]) + script_item["value"].append(line) if len(script_item["value"]) > 0: script.append(script_item) @@ -322,14 +325,14 @@ def write_yaml_tree(self, filename): def tidy_up(yaml): # add blank lines between major fields for field in [ - "- type:", - "- file:", "- name:", - "databases:", - "pre_init:", + " databases:", + " pre_init:", "module", + "defs", + " args", ]: - yaml = re.sub(r"(\s*%s)" % field, "\n\\g<1>", yaml) + yaml = re.sub(r"(\n%s)" % field, "\n\\g<1>", yaml) return yaml