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,9 +69,9 @@ class Procedure(object):
|
|||
if_count += 1
|
||||
if_name = '{}__if_{}'.format(name, if_count)
|
||||
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],
|
||||
condition=condition,
|
||||
else_branch=else_branch,
|
||||
|
@ -97,7 +97,6 @@ class Procedure(object):
|
|||
Params:
|
||||
n_tries -- Number of tries in case of failure before raising a RuntimeError
|
||||
"""
|
||||
|
||||
if self.args:
|
||||
logger.info('Executing procedure {} with arguments {}'.format(self.name, self.args))
|
||||
for (k,v) in self.args.items():
|
||||
|
@ -205,20 +204,26 @@ class IfProcedure(Procedure):
|
|||
reqs = []
|
||||
|
||||
for req in requests:
|
||||
if isinstance(req, dict):
|
||||
req['origin'] = Config.get('device_id')
|
||||
req['id'] = id
|
||||
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:
|
||||
if isinstance(req, dict):
|
||||
req['origin'] = Config.get('device_id')
|
||||
req['id'] = id
|
||||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue