Expand complicated format + list comprehension into its own function

This commit is contained in:
Davide Depau 2018-01-09 10:59:08 +01:00
parent b4503a183c
commit 03762a5cc5
No known key found for this signature in database
GPG Key ID: C7D999B6A55EFE86

View File

@ -54,11 +54,24 @@ def _get_input_args(input_node):
return args return args
def _format_input_stream_name(stream_name_map, edge):
prefix = stream_name_map[edge.upstream_node, edge.upstream_label]
if not edge.upstream_selector:
suffix = ""
else:
suffix = ":{}".format(edge.upstream_selector)
return "[{}{}]".format(prefix, suffix)
def _format_output_stream_name(stream_name_map, edge):
return "[{}]".format(stream_name_map[edge.upstream_node, edge.upstream_label])
def _get_filter_spec(node, outgoing_edge_map, stream_name_map): def _get_filter_spec(node, outgoing_edge_map, stream_name_map):
incoming_edges = node.incoming_edges incoming_edges = node.incoming_edges
outgoing_edges = get_outgoing_edges(node, outgoing_edge_map) outgoing_edges = get_outgoing_edges(node, outgoing_edge_map)
inputs = ["[{}{}]".format(stream_name_map[edge.upstream_node, edge.upstream_label], "" if not edge.upstream_selector else ":{}".format(edge.upstream_selector)) for edge in incoming_edges] inputs = [_format_input_stream_name(stream_name_map, edge) for edge in incoming_edges]
outputs = ["[{}]".format(stream_name_map[edge.upstream_node, edge.upstream_label]) for edge in outgoing_edges] outputs = [_format_output_stream_name(stream_name_map, edge) for edge in outgoing_edges]
filter_spec = '{}{}{}'.format(''.join(inputs), node._get_filter(outgoing_edges), ''.join(outputs)) filter_spec = '{}{}{}'.format(''.join(inputs), node._get_filter(outgoing_edges), ''.join(outputs))
return filter_spec return filter_spec
@ -99,7 +112,7 @@ def _get_output_args(node, stream_name_map):
for edge in node.incoming_edges: for edge in node.incoming_edges:
# edge = node.incoming_edges[0] # edge = node.incoming_edges[0]
stream_name = "[{}{}]".format(stream_name_map[edge.upstream_node, edge.upstream_label], "" if not edge.upstream_selector else ":{}".format(edge.upstream_selector)) stream_name = _format_input_stream_name(stream_name_map, edge)
if stream_name != '[0]' or len(node.incoming_edges) > 1: if stream_name != '[0]' or len(node.incoming_edges) > 1:
args += ['-map', stream_name] args += ['-map', stream_name]