diff options
author | Sebastian Koslowski <sebastian.koslowski@gmail.com> | 2016-05-03 17:13:08 +0200 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2017-06-29 09:16:49 -0700 |
commit | 7f7fa2f91467fdb2b11312be8562e7b51fdeb199 (patch) | |
tree | 24268bac15b9920d2a15ddbb45eaf3b9b03718a1 /grc/core/generator/FlowGraphProxy.py | |
parent | 44cae388881821942e691a4d69a923bbd8d347db (diff) |
grc: added yaml/mako support
Includes basic converter from XML/Cheetah to YAML/Mako based block format.
Diffstat (limited to 'grc/core/generator/FlowGraphProxy.py')
-rw-r--r-- | grc/core/generator/FlowGraphProxy.py | 54 |
1 files changed, 43 insertions, 11 deletions
diff --git a/grc/core/generator/FlowGraphProxy.py b/grc/core/generator/FlowGraphProxy.py index 23ccf95c4b..f438fa0d39 100644 --- a/grc/core/generator/FlowGraphProxy.py +++ b/grc/core/generator/FlowGraphProxy.py @@ -66,14 +66,15 @@ class FlowGraphProxy(object): # TODO: move this in a refactored Generator self.get_pad_sinks() if direction in ('source', 'out') else [] ports = [] for pad in pads: + type_param = pad.params['type'] master = { - 'label': str(pad.get_param('label').get_evaluated()), - 'type': str(pad.get_param('type').get_evaluated()), - 'vlen': str(pad.get_param('vlen').get_value()), - 'size': pad.get_param('type').opt_value('size'), - 'optional': bool(pad.get_param('optional').get_evaluated()), + 'label': str(pad.params['label'].get_evaluated()), + 'type': str(pad.params['type'].get_evaluated()), + 'vlen': str(pad.params['vlen'].get_value()), + 'size': type_param.options.attributes[type_param.get_value()]['size'], + 'optional': bool(pad.params['optional'].get_evaluated()), } - num_ports = pad.get_param('num_streams').get_evaluated() + num_ports = pad.params['num_streams'].get_evaluated() if num_ports > 1: for i in range(num_ports): clone = master.copy() @@ -91,7 +92,7 @@ class FlowGraphProxy(object): # TODO: move this in a refactored Generator a list of pad source blocks in this flow graph """ pads = [b for b in self.get_enabled_blocks() if b.key == 'pad_source'] - return sorted(pads, lambda x, y: cmp(x.get_id(), y.get_id())) + return sorted(pads, key=lambda x: x.name) def get_pad_sinks(self): """ @@ -101,7 +102,7 @@ class FlowGraphProxy(object): # TODO: move this in a refactored Generator a list of pad sink blocks in this flow graph """ pads = [b for b in self.get_enabled_blocks() if b.key == 'pad_sink'] - return sorted(pads, lambda x, y: cmp(x.get_id(), y.get_id())) + return sorted(pads, key=lambda x: x.name) def get_pad_port_global_key(self, port): """ @@ -116,15 +117,46 @@ class FlowGraphProxy(object): # TODO: move this in a refactored Generator for pad in pads: # using the block param 'type' instead of the port domain here # to emphasize that hier block generation is domain agnostic - is_message_pad = pad.get_param('type').get_evaluated() == "message" + is_message_pad = pad.params['type'].get_evaluated() == "message" if port.parent == pad: if is_message_pad: - key = pad.get_param('label').get_value() + key = pad.params['label'].get_value() else: key = str(key_offset + int(port.key)) return key else: # assuming we have either only sources or sinks if not is_message_pad: - key_offset += len(pad.get_ports()) + key_offset += len(pad.sinks) + len(pad.sources) return -1 + + +def get_hier_block_io(flow_graph, direction, domain=None): + """ + Get a list of io ports for this flow graph. + + Returns a list of dicts with: type, label, vlen, size, optional + """ + pads = flow_graph.get_pad_sources() if direction in ('sink', 'in') else \ + flow_graph.get_pad_sinks() if direction in ('source', 'out') else [] + ports = [] + for pad in pads: + type_param = pad.params['type'] + master = { + 'label': str(pad.params['label'].get_evaluated()), + 'type': str(pad.params['type'].get_evaluated()), + 'vlen': str(pad.params['vlen'].get_value()), + 'size': type_param.options.attributes[type_param.get_value()]['size'], + 'optional': bool(pad.params['optional'].get_evaluated()), + } + num_ports = pad.params['num_streams'].get_evaluated() + if num_ports > 1: + for i in range(num_ports): + clone = master.copy() + clone['label'] += str(i) + ports.append(clone) + else: + ports.append(master) + if domain is not None: + ports = [p for p in ports if p.domain == domain] + return ports |