forked from platypush/platypush
Implemented nested if(s), solves #53
This commit is contained in:
parent
b88f7fcecc
commit
7ec6221a7f
1 changed files with 22 additions and 17 deletions
|
@ -69,13 +69,13 @@ class Procedure(object):
|
||||||
if_count += 1
|
if_count += 1
|
||||||
if_name = '{}__if_{}'.format(name, if_count)
|
if_name = '{}__if_{}'.format(name, if_count)
|
||||||
condition = m.group(2)
|
condition = m.group(2)
|
||||||
else_branch = request_config['else'] if 'else' in request_config else []
|
else_branch = []
|
||||||
|
|
||||||
if_proc = IfProcedure(name=if_name,
|
if_proc = IfProcedure.build(name=if_name, _async=False,
|
||||||
requests=request_config[key],
|
requests=request_config[key],
|
||||||
condition=condition,
|
condition=condition,
|
||||||
else_branch=else_branch,
|
else_branch=else_branch,
|
||||||
backend=backend, id=id)
|
backend=backend, id=id)
|
||||||
|
|
||||||
reqs.append(if_proc)
|
reqs.append(if_proc)
|
||||||
continue
|
continue
|
||||||
|
@ -97,7 +97,6 @@ class Procedure(object):
|
||||||
Params:
|
Params:
|
||||||
n_tries -- Number of tries in case of failure before raising a RuntimeError
|
n_tries -- Number of tries in case of failure before raising a RuntimeError
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.args:
|
if self.args:
|
||||||
logger.info('Executing procedure {} with arguments {}'.format(self.name, self.args))
|
logger.info('Executing procedure {} with arguments {}'.format(self.name, self.args))
|
||||||
for (k,v) in self.args.items():
|
for (k,v) in self.args.items():
|
||||||
|
@ -205,20 +204,26 @@ class IfProcedure(Procedure):
|
||||||
reqs = []
|
reqs = []
|
||||||
|
|
||||||
for req in requests:
|
for req in requests:
|
||||||
req['origin'] = Config.get('device_id')
|
if isinstance(req, dict):
|
||||||
req['id'] = id
|
req['origin'] = Config.get('device_id')
|
||||||
if 'target' not in req:
|
req['id'] = id
|
||||||
req['target'] = req['origin']
|
if 'target' not in req:
|
||||||
|
req['target'] = req['origin']
|
||||||
|
|
||||||
reqs.append(Request.build(req))
|
req = Request.build(req)
|
||||||
|
|
||||||
|
reqs.append(req)
|
||||||
|
|
||||||
for req in else_branch:
|
for req in else_branch:
|
||||||
req['origin'] = Config.get('device_id')
|
if isinstance(req, dict):
|
||||||
req['id'] = id
|
req['origin'] = Config.get('device_id')
|
||||||
if 'target' not in req:
|
req['id'] = id
|
||||||
req['target'] = req['origin']
|
if 'target' not in req:
|
||||||
|
req['target'] = req['origin']
|
||||||
|
|
||||||
self.else_branch.append(Request.build(req))
|
req = Request.build(req)
|
||||||
|
|
||||||
|
self.else_branch.append(req)
|
||||||
|
|
||||||
super(). __init__(name=name, requests=reqs, args=args, backend=backend, **kwargs)
|
super(). __init__(name=name, requests=reqs, args=args, backend=backend, **kwargs)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue