[alias] Fix argument consumption, allow multiple usage of same var
This commit is contained in:
parent
461c62f596
commit
e1310516fa
1 changed files with 31 additions and 26 deletions
|
|
@ -114,7 +114,7 @@ def set_variable(name, value, creator):
|
||||||
context.save()
|
context.save()
|
||||||
|
|
||||||
|
|
||||||
def replace_variables(cnt, msg=None):
|
def replace_variables(cnts, msg=None):
|
||||||
"""Replace variables contained in the content
|
"""Replace variables contained in the content
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
@ -122,10 +122,12 @@ def replace_variables(cnt, msg=None):
|
||||||
msg -- optional message where pick some variables
|
msg -- optional message where pick some variables
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isinstance(cnt, list):
|
|
||||||
return [replace_variables(c, msg) for c in cnt]
|
|
||||||
|
|
||||||
unsetCnt = list()
|
unsetCnt = list()
|
||||||
|
if not isinstance(cnts, list):
|
||||||
|
cnts = list(cnts)
|
||||||
|
resultCnt = list()
|
||||||
|
|
||||||
|
for cnt in cnts:
|
||||||
for res in re.findall("\\$\{(?P<name>[a-zA-Z0-9:]+)\}", cnt):
|
for res in re.findall("\\$\{(?P<name>[a-zA-Z0-9:]+)\}", cnt):
|
||||||
rv = re.match("([0-9]+)(:([0-9]*))?", res)
|
rv = re.match("([0-9]+)(:([0-9]*))?", res)
|
||||||
if rv is not None:
|
if rv is not None:
|
||||||
|
|
@ -147,9 +149,12 @@ def replace_variables(cnt, msg=None):
|
||||||
unsetCnt.append(varI)
|
unsetCnt.append(varI)
|
||||||
else:
|
else:
|
||||||
cnt = cnt.replace("${%s}" % res, get_variable(res), 1)
|
cnt = cnt.replace("${%s}" % res, get_variable(res), 1)
|
||||||
for u in sorted(unsetCnt, reverse=True):
|
resultCnt.append(cnt)
|
||||||
msg.args.pop(u)
|
|
||||||
return cnt
|
for u in sorted(set(unsetCnt), reverse=True):
|
||||||
|
k = msg.args.pop(u)
|
||||||
|
|
||||||
|
return resultCnt
|
||||||
|
|
||||||
|
|
||||||
# MODULE INTERFACE ####################################################
|
# MODULE INTERFACE ####################################################
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue