mirror of https://gerrit.osmocom.org/osmo-dev
fill_config: fix multiple command expansions
If there are multiple ${foo()} commands expanded in one iteration, there would be offset mismatches because the changed string was used with regex offsets from before the match. Re-run the regex after each change. Change-Id: I69de60d840ff3ba115c37d1ede7ccbc8879c82eb
This commit is contained in:
parent
3c093457d2
commit
e7cb4a591c
|
@ -189,9 +189,12 @@ def insert_foreach(tmpl, tmpl_dir, tmpl_src, match, local_config, arg):
|
||||||
return ''.join(expanded)
|
return ''.join(expanded)
|
||||||
|
|
||||||
def handle_commands(tmpl, tmpl_dir, tmpl_src, local_config):
|
def handle_commands(tmpl, tmpl_dir, tmpl_src, local_config):
|
||||||
handled = 0
|
while True:
|
||||||
for m in command_re.finditer(tmpl):
|
# make sure to re-run the regex after each expansion to get proper string
|
||||||
handled += 1
|
# offsets each time
|
||||||
|
m = command_re.search(tmpl)
|
||||||
|
if not m:
|
||||||
|
break;
|
||||||
cmd = m.group(1)
|
cmd = m.group(1)
|
||||||
arg = m.group(2)
|
arg = m.group(2)
|
||||||
if cmd == 'include':
|
if cmd == 'include':
|
||||||
|
@ -202,6 +205,9 @@ def handle_commands(tmpl, tmpl_dir, tmpl_src, local_config):
|
||||||
print('Error: unknown command: %r in %r' % (cmd, tmpl_src))
|
print('Error: unknown command: %r in %r' % (cmd, tmpl_src))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
# There was some command expansion. Go again.
|
||||||
|
continue
|
||||||
|
|
||||||
return tmpl
|
return tmpl
|
||||||
|
|
||||||
for tmpl_name in sorted(os.listdir(tmpl_dir)):
|
for tmpl_name in sorted(os.listdir(tmpl_dir)):
|
||||||
|
|
Loading…
Reference in New Issue