From 8451e7c01919f5caee2c3c47cfa9c2853e9981f3 Mon Sep 17 00:00:00 2001 From: Alexander Tiderko Date: Fri, 7 Jul 2023 13:24:15 +0200 Subject: [PATCH] added support for eval statements in launch files --- .../src/fkie_node_manager_daemon/common.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fkie_node_manager_daemon/src/fkie_node_manager_daemon/common.py b/fkie_node_manager_daemon/src/fkie_node_manager_daemon/common.py index 560d10f6..27fdf9c1 100644 --- a/fkie_node_manager_daemon/src/fkie_node_manager_daemon/common.py +++ b/fkie_node_manager_daemon/src/fkie_node_manager_daemon/common.py @@ -390,6 +390,21 @@ def replace_arg(value, resolve_args): for arg in re_if.findall(value): if arg in resolve_args: result = result.replace('$(arg %s)' % arg, resolve_args[arg]) + if value.startswith('$(eval'): + # resolve args in eval statement + re_if = re.compile(r"arg\(\'(?P.*?)\'\)") + for arg in re_if.findall(value): + if arg in resolve_args: + result = result.replace("arg('%s')" % arg, f"'{resolve_args[arg]}'") + re_items = '|'.join([f"({item})" for item in list(resolve_args.keys())]) + re_if = re.compile(re_items) + for matches in re_if.findall(value): + for arg in matches: + if arg: + if arg in resolve_args: + result = result.replace("%s" % arg, f"\'{resolve_args[arg]}\'") + result = result.replace('$(eval', '').rstrip(')') + result = 'true' if eval(result) else 'false' return result