def Duplicate(port_in, **kw): # pylint: disable=C0103 """ Creates a message duplicator and connects its secondary output port to the given input port. """ ctx = Context.top() template = DuplicatorTemplate(destination=port_in) parser = ComponentParser() operations = list(parser.divert(template.apply())) process = parser.get_component() if 'alias' in kw: operations.append(AddTokenOp(AliasToken(process, kw['alias']))) if 'label' in kw: operations.append(AddTokenOp(LabelToken(process, kw['label']))) if 'description' in kw: operations.append(AddTokenOp(DescriptionToken(process, kw['description']))) if 'partition' in kw: operations.append(AddTokenOp(PartitionToken(process, kw['partition']))) ctx.tokens.extend(operations) return process
def Chain(name, *procs, **kw): # pylint: disable=C0103 """ Forms a chain of the given components by connecting the default input port to the default output port of its predecessor. """ ctx = Context.top() template = ChainTemplate(chain=procs) parser = ComponentParser() operations = list(parser.divert(template.apply())) process = parser.get_component() operations.append(AddTokenOp(LabelToken(process, name))) operations.append(AddTokenOp(AliasToken(process, name))) if 'description' in kw: operations.append(AddTokenOp(DescriptionToken(process, kw['description']))) if 'partition' in kw: operations.append(AddTokenOp(PartitionToken(process, kw['partition']))) ctx.tokens.extend(operations) return process