Merge "Allow to modify computable inputs in Composer files"
This commit is contained in:
commit
37e2f39388
@ -236,7 +236,7 @@ def update_resources(template_resources):
|
|||||||
|
|
||||||
def update_inputs(child, inputs):
|
def update_inputs(child, inputs):
|
||||||
child = load_resource(child)
|
child = load_resource(child)
|
||||||
connections, assignments = parse_inputs(inputs)
|
connections, assignments, computable = parse_inputs(inputs)
|
||||||
parents = defaultdict(lambda: defaultdict(dict))
|
parents = defaultdict(lambda: defaultdict(dict))
|
||||||
for c in connections:
|
for c in connections:
|
||||||
mapping = {c['parent_input']: c['child_input']}
|
mapping = {c['parent_input']: c['child_input']}
|
||||||
@ -253,6 +253,9 @@ def update_inputs(child, inputs):
|
|||||||
|
|
||||||
child.update(assignments)
|
child.update(assignments)
|
||||||
|
|
||||||
|
for comp in computable:
|
||||||
|
child.input_computable_change(**comp)
|
||||||
|
|
||||||
|
|
||||||
def extend_events(template_events):
|
def extend_events(template_events):
|
||||||
events = []
|
events = []
|
||||||
@ -295,22 +298,28 @@ def parse_events(template_events):
|
|||||||
def parse_inputs(inputs):
|
def parse_inputs(inputs):
|
||||||
connections = []
|
connections = []
|
||||||
assignments = {}
|
assignments = {}
|
||||||
|
computable = []
|
||||||
for r_input, arg in inputs.items():
|
for r_input, arg in inputs.items():
|
||||||
if isinstance(arg, list):
|
if isinstance(arg, list):
|
||||||
c, a = parse_list_input(r_input, arg)
|
c, a = parse_list_input(r_input, arg)
|
||||||
connections.extend(c)
|
connections.extend(c)
|
||||||
assignments.update(a)
|
assignments.update(a)
|
||||||
elif isinstance(arg, dict):
|
elif isinstance(arg, dict):
|
||||||
c, a = parse_dict_input(r_input, arg)
|
if 'computable' in arg:
|
||||||
connections.extend(c)
|
comp, conn = parse_computable_input(r_input, arg)
|
||||||
assignments.update(a)
|
computable.append(comp)
|
||||||
|
connections.extend(conn)
|
||||||
|
else:
|
||||||
|
c, a = parse_dict_input(r_input, arg)
|
||||||
|
connections.extend(c)
|
||||||
|
assignments.update(a)
|
||||||
else:
|
else:
|
||||||
if is_connection(arg):
|
if is_connection(arg):
|
||||||
c = parse_connection(r_input, arg)
|
c = parse_connection(r_input, arg)
|
||||||
connections.append(c)
|
connections.append(c)
|
||||||
else:
|
else:
|
||||||
assignments[r_input] = arg
|
assignments[r_input] = arg
|
||||||
return connections, assignments
|
return connections, assignments, computable
|
||||||
|
|
||||||
|
|
||||||
def parse_list_input(r_input, args):
|
def parse_list_input(r_input, args):
|
||||||
@ -347,6 +356,25 @@ def parse_dict_input(r_input, args):
|
|||||||
return connections, assignments
|
return connections, assignments
|
||||||
|
|
||||||
|
|
||||||
|
def parse_computable_input(r_input, arg):
|
||||||
|
computable = {'name': r_input}
|
||||||
|
connections = []
|
||||||
|
data = arg['computable']
|
||||||
|
func = data.get('func', None)
|
||||||
|
d_type = data.get('type', None)
|
||||||
|
lang = data.get('lang', None)
|
||||||
|
if func:
|
||||||
|
computable['func'] = func
|
||||||
|
if d_type:
|
||||||
|
computable['type'] = d_type
|
||||||
|
if lang:
|
||||||
|
computable['lang'] = lang
|
||||||
|
for c in data.get('connections', []):
|
||||||
|
c = parse_connection(r_input, c)
|
||||||
|
connections.append(c)
|
||||||
|
return computable, connections
|
||||||
|
|
||||||
|
|
||||||
def add_assignment(assignments, r_input, arg):
|
def add_assignment(assignments, r_input, arg):
|
||||||
try:
|
try:
|
||||||
assignments[r_input].append(arg)
|
assignments[r_input].append(arg)
|
||||||
|
@ -191,6 +191,22 @@ def test_parse_dict_input():
|
|||||||
assert correct_connections == connections
|
assert correct_connections == connections
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_computable_input():
|
||||||
|
comp, conn = cr.parse_computable_input('cmd', {'computable': {
|
||||||
|
'func': 'echo 1',
|
||||||
|
'type': 'full',
|
||||||
|
'lang': 'jinja',
|
||||||
|
'connections': ['N::ip']}})
|
||||||
|
assert comp == {'lang': 'jinja',
|
||||||
|
'type': 'full',
|
||||||
|
'name': 'cmd',
|
||||||
|
'func': 'echo 1'}
|
||||||
|
assert conn == [{'child_input': 'cmd',
|
||||||
|
'parent_input': 'ip',
|
||||||
|
'parent': 'N',
|
||||||
|
'events': None}]
|
||||||
|
|
||||||
|
|
||||||
def test_parse_connection_disable_events():
|
def test_parse_connection_disable_events():
|
||||||
correct_connection = {'child_input': 'ip',
|
correct_connection = {'child_input': 'ip',
|
||||||
'parent': 'node1',
|
'parent': 'node1',
|
||||||
@ -205,7 +221,7 @@ def test_parse_list_of_connected_dicts():
|
|||||||
inputs = {'list': [
|
inputs = {'list': [
|
||||||
{'key': 'emitter1::key'},
|
{'key': 'emitter1::key'},
|
||||||
{'key': 'emitter2::key'}]}
|
{'key': 'emitter2::key'}]}
|
||||||
connections, assignments = cr.parse_inputs(inputs)
|
connections, assignments, _ = cr.parse_inputs(inputs)
|
||||||
assert assignments == {}
|
assert assignments == {}
|
||||||
assert connections == [
|
assert connections == [
|
||||||
{'child_input': 'list:key', 'parent_input': 'key',
|
{'child_input': 'list:key', 'parent_input': 'key',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user