Skip to content

Commit

Permalink
added support for eval statements in launch files
Browse files Browse the repository at this point in the history
  • Loading branch information
atiderko committed Jul 7, 2023
1 parent cef20cb commit 8451e7c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fkie_node_manager_daemon/src/fkie_node_manager_daemon/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<name>.*?)\'\)")
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


Expand Down

0 comments on commit 8451e7c

Please sign in to comment.