Exemplo n.º 1
0
    def _get_linked_attributes(self):
        # for parameters which still do not have attributes, we can try
        # using links: if a linked parameter in a sub-process has
        # attributes, then we can get them here.
        attributes = self.capsul_attributes
        schema = 'link'  # FIXME
        param_attributes = attributes.get_parameters_attributes()
        forbidden_attributes = set(['generated_by_parameter',
                                    'generated_by_process'])
        done_parameters = set(
            [p for p, al in six.iteritems(param_attributes)
              if len([a for a in al if a not in forbidden_attributes])
              != 0])
        traits_types = {str: traits.Str, unicode: traits.Str, int: traits.Int,
                        float: traits.Float, list: traits.List}
        name = self.process.name
        for pname, trait in six.iteritems(self.process.user_traits()):
            if pname in done_parameters:
                continue
            plug = self.process.pipeline_node.plugs.get(pname)
            if plug is None:
                continue
            if trait.output:
                links = plug.links_from
            else:
                links = plug.links_to
            for link in links:
                node = link[2]
                if hasattr(node, 'process'):
                    process = node.process
                else:
                    process = node
                completion_engine \
                    = ProcessCompletionEngine.get_completion_engine(
                        process, '.'.join([name, link[0]]))
                sub_attributes = completion_engine.get_attribute_values()
                sub_p_attribs = sub_attributes.get_parameters_attributes()
                if link[1] in sub_p_attribs:
                    s_p_attributes = sub_p_attribs[link[1]]
                    if len(s_p_attributes) != 0 \
                            and len([x for x in s_p_attributes.keys()
                                    if x not in forbidden_attributes]) != 0:
                        ea = EditableAttributes()
                        for attribute, value in six.iteritems(
                                s_p_attributes):
                            if attribute not in forbidden_attributes:
                                ttype = traits_types.get(type(value))
                                if ttype is not None:
                                    trait = ttype()
                                else:
                                    trait = value
                                ea.add_trait(attribute, ttype)
                                setattr(ea, attribute, value)

                        attributes.set_parameter_attributes(
                            pname, schema, ea, {})

                    break
 def editable_attributes(attributes, fom):
     ea = EditableAttributes()
     for attribute in attributes:
         if attribute.startswith('fom_'):
             continue  # skip FOM internals
         default_value = fom.attribute_definitions[attribute].get(
             'default_value', '')
         ea.add_trait(attribute, Str(default_value))
     return ea
Exemplo n.º 3
0
 def editable_attributes(attributes, fom):
     ea = EditableAttributes()
     for attribute in attributes:
         if attribute.startswith('fom_'):
             continue # skip FOM internals
         default_value = fom.attribute_definitions[attribute].get(
             'default_value', '')
         ea.add_trait(attribute, Str(default_value))
     return ea
Exemplo n.º 4
0
    def get_attribute_values(self):
        if self.trait('capsul_attributes') is not None \
                and hasattr(self, 'capsul_attributes'):
            return self.capsul_attributes

        self.add_trait('capsul_attributes', ControllerTrait(Controller()))
        capsul_attributes = ProcessAttributes(self.process, {})
        self.capsul_attributes = capsul_attributes
        outputs = self.process._outputs
        schema = 'switch'  # FIXME
        name = getattr(self.process, 'context_name', self.name)
        pipeline_name = '.'.join(name.split('.')[:-1])
        if pipeline_name == '':
            pipeline_name = []
        else:
            pipeline_name = [pipeline_name]
        forbidden_attributes = set(
            ['generated_by_parameter', 'generated_by_process'])
        traits_types = {
            str: traits.Str,
            unicode: traits.Str,
            int: traits.Int,
            float: traits.Float,
            list: traits.List
        }
        for out_name in outputs:
            in_name = '_switch_'.join((self.process.switch, out_name))
            found = False
            for output, name in ((False, in_name), (True, out_name)):
                plug = self.process.plugs.get(name)
                if plug is None:
                    continue
                if output:
                    links = plug.links_to
                else:
                    links = plug.links_from
                for link in links:
                    node = link[2]
                    if isinstance(node, Switch):
                        # FIXME: just for now
                        continue
                    if link[0] == '':
                        # link to the parent pipeline: don't call it to avoid
                        # an infinite loop.
                        # Either it will provide attributes by its own, either
                        # we must not take them into account, so skip it.
                        continue
                    if hasattr(node, 'process'):
                        process = node.process
                    else:
                        process = node
                    proc_name = '.'.join(pipeline_name + [link[0]])
                    completion_engine \
                        = ProcessCompletionEngine.get_completion_engine(
                            process, name=proc_name)
                    attributes = completion_engine.get_attribute_values()
                    try:
                        param_attributes \
                            = attributes.get_parameters_attributes()[link[1]]
                    except:
                        continue

                    if len(param_attributes) != 0 \
                            and len([x for x in param_attributes.keys()
                                     if x not in forbidden_attributes]) != 0:
                        ea = EditableAttributes()
                        for attribute, value in six.iteritems(
                                param_attributes):
                            if attribute not in forbidden_attributes:
                                ttype = traits_types.get(type(value))
                                if ttype is not None:
                                    trait = ttype()
                                else:
                                    trait = value
                                ea.add_trait(attribute, ttype)
                                setattr(ea, attribute, value)

                        capsul_attributes.set_parameter_attributes(
                            name, schema, ea, {})
                        found = True
                        break
                if found:
                    break
            if found:
                # propagate from input/output to other side
                ea = EditableAttributes()
                for attribute, value in six.iteritems(param_attributes):
                    ttype = traits_types.get(type(value))
                    if ttype is not None:
                        trait = ttype()
                    else:
                        trait = value
                    ea.add_trait(attribute, ttype)
                    setattr(ea, attribute, value)
                if output:
                    capsul_attributes.set_parameter_attributes(
                        in_name, schema, ea, {})
                else:
                    capsul_attributes.set_parameter_attributes(
                        out_name, schema, ea, {})

        self.install_switch_observer()
        return capsul_attributes
Exemplo n.º 5
0
    def get_attribute_values(self):
        if self.process.name == 'select_renormalization_commissures':
            debug = True
        else: debug = False
        if self.trait('capsul_attributes') is not None \
                and hasattr(self, 'capsul_attributes'):
            return self.capsul_attributes

        self.add_trait('capsul_attributes', ControllerTrait(Controller()))
        capsul_attributes = ProcessAttributes(self.process, {})
        self.capsul_attributes = capsul_attributes
        outputs = self.process._outputs
        schema = 'switch'  # FIXME
        name = getattr(self.process, 'context_name', self.name)
        pipeline_name = '.'.join(name.split('.')[:-1])
        if pipeline_name == '':
            pipeline_name = []
        else:
            pipeline_name = [pipeline_name]
        forbidden_attributes = set(['generated_by_parameter',
                                    'generated_by_process'])
        traits_types = {str: traits.Str, unicode: traits.Str, int: traits.Int,
                        float: traits.Float, list: traits.List}
        for out_name in outputs:
            in_name = '_switch_'.join((self.process.switch, out_name))
            found = False
            for output, name in ((False, in_name), (True, out_name)):
                plug = self.process.plugs.get(name)
                if plug is None:
                    continue
                if output:
                    links = plug.links_to
                else:
                    links = plug.links_from
                for link in links:
                    node = link[2]
                    if isinstance(node, Switch):
                        # FIXME: just for now
                        continue
                    if link[0] == '':
                        # link to the parent pipeline: don't call it to avoid
                        # an infinite loop.
                        # Either it will provide attributes by its own, either
                        # we must not take them into account, so skip it.
                        continue
                    if hasattr(node, 'process'):
                        process = node.process
                    else:
                        process = node
                    proc_name = '.'.join(pipeline_name + [link[0]])
                    completion_engine \
                        = ProcessCompletionEngine.get_completion_engine(
                            process, name=proc_name)
                    attributes = completion_engine.get_attribute_values()
                    try:
                        param_attributes \
                            = attributes.get_parameters_attributes()[link[1]]
                    except:
                        continue

                    if len(param_attributes) != 0 \
                            and len([x for x in param_attributes.keys()
                                     if x not in forbidden_attributes]) != 0:
                        ea = EditableAttributes()
                        for attribute, value in six.iteritems(
                                param_attributes):
                            if attribute not in forbidden_attributes:
                                ttype = traits_types.get(type(value))
                                if ttype is not None:
                                    trait = ttype()
                                else:
                                    trait = value
                                ea.add_trait(attribute, ttype)
                                setattr(ea, attribute, value)

                        capsul_attributes.set_parameter_attributes(
                            name, schema, ea, {})
                        found = True
                        break
                if found:
                    break
            if found:
                # propagate from input/output to other side
                ea = EditableAttributes()
                for attribute, value in six.iteritems(
                        param_attributes):
                    ttype = traits_types.get(type(value))
                    if ttype is not None:
                        trait = ttype()
                    else:
                        trait = value
                    ea.add_trait(attribute, ttype)
                    setattr(ea, attribute, value)
                if output:
                    capsul_attributes.set_parameter_attributes(
                        in_name, schema, ea, {})
                else:
                    capsul_attributes.set_parameter_attributes(
                        out_name, schema, ea, {})

        self.install_switch_observer()
        return capsul_attributes