Пример #1
0
    def create_action(self, id_scope=IdScope()):
        from vistrails.core.mashup.component import Component
        from vistrails.core.mashup.alias import Alias
        from vistrails.core.mashup.mashup import Mashup
        c1 = Component(id=id_scope.getNewId('mashup_component'),
                       vttype='parameter',
                       param_id=15L,
                       parent_vttype='function',
                       parent_id=3L,
                       mid=4L,
                       type='String',
                       value='test',
                       p_pos=0,
                       pos=1,
                       strvaluelist='test1,test2',
                       widget="text")
        a1 = Alias(id=id_scope.getNewId('mashup_alias'),
                   name='alias1',
                   component=c1)

        m = Mashup(id=id_scope.getNewId('mashup'),
                   name='mashup1',
                   vtid='empty.vt',
                   version=15L,
                   alias_list=[a1])
        action = Action(id=id_scope.getNewId('mashup_action'),
                        prevId=0L,
                        date=datetime(2007, 11, 18),
                        mashup=m)
        return action
Пример #2
0
    def validateForPipeline(self, pipeline):
        """validateForPipeline(pipeline) -> None
        This will make sure that the parameters in the alias list are present
        in the pipeline. If they were removed, the aliases pointing to it will 
        be removed. This changes the mashup in place """
        to_remove = []
        for alias in self.alias_list:
            try:
                param = pipeline.db_get_object(alias.component.vttype,
                                               alias.component.vtid)
            except Exception:
                to_remove.append(alias)
        for a in to_remove:
            self.alias_list.remove(a)
        pos = 0
        mashup_aliases = []
        for a in self.alias_list:
            mashup_aliases.append(a.name)
            a.component.pos = pos
            pos += 1

        for a, info in pipeline.aliases.iteritems():
            if a not in mashup_aliases:
                parameter = pipeline.db_get_object(info[0], info[1])
                cid = self.id_scope.getNewId('component')
                aid = self.id_scope.getNewId('alias')
                component = Component(cid, parameter.vtType, parameter.real_id,
                                      info[2], info[3], info[4],
                                      parameter.type, parameter.strValue,
                                      parameter.pos, pos, "")
                newalias = Alias(aid, a, component)
                self.alias_list.append(newalias)
                pos += 1
Пример #3
0
 def create_mashup(self, id_scope=IdScope()):
     c1 = Component(id=id_scope.getNewId('mashup_component'),
                       vttype='parameter', param_id=15L, 
                       parent_vttype='function', parent_id=3L, mid=4L,
                       type='String', value='test', p_pos=0, pos=1, 
                       strvaluelist='test1,test2', widget="text")
     a1 = Alias(id=id_scope.getNewId('mashup_alias'), name='alias1', component=c1)
     
     m = Mashup(id=id_scope.getNewId('mashup'), name='mashup1', vtid='empty.vt', 
                version=15L, alias_list=[a1])
     return m
Пример #4
0
    def updateAliasFromParam(self, param):
        add_alias = True
        new_aliases = []
        pos = 0
        for alias in self.currentMashup.alias_list:
            if alias.component.vtid != param.id:
                calias = alias.do_copy(new_ids=True,
                                       id_scope=self.mshptrail.id_scope,
                                       id_remap={})
                calias.component.pos = pos
                new_aliases.append(calias)
                pos += 1
            else:
                #print "found alias: ", alias
                add_alias = False
                if param.alias != '':
                    new_alias = alias.do_copy(new_ids=True,
                                              id_scope=self.mshptrail.id_scope,
                                              id_remap={})
                    new_alias.name = param.alias
                    new_aliases.append(new_alias)
                    pos += 1
        if add_alias:
            parameter = self.vtPipeline.db_get_object(param.dbtype, param.id)
            cid = self.id_scope.getNewId('mashup_component')
            aid = self.id_scope.getNewId('mashup_alias')
            component = Component(cid, parameter.vtType, parameter.real_id,
                                  param.parent_dbtype, param.parent_id,
                                  param.mId, parameter.type,
                                  parameter.strValue, parameter.pos, pos, "")
            alias = Alias(aid, param.alias, component)
            new_aliases.append(alias)
            self.vtPipeline.add_alias(param.alias, param.type, param.id,
                                      param.parent_dbtype, param.parent_id,
                                      param.mId)
        else:
            self.vtPipeline.change_alias(param.alias, param.type, param.id,
                                         param.parent_dbtype, param.parent_id,
                                         param.mId)

        return self.createMashupVersion(new_aliases, quiet=False)
Пример #5
0
    def loadAliasesFromPipeline(self, pipeline, id_scope):
        """loadAliasesFromPipelines(pipeline: Pipeline) -> None 
        This will replace current aliases with the ones present in Pipeline
        
        """

        if pipeline:
            self.alias_list = []
            if len(pipeline.aliases) > 0:
                pos = 0
                for aname, info in pipeline.aliases.iteritems():
                    parameter = pipeline.db_get_object(info[0], info[1])
                    cid = id_scope.getNewId('component')
                    aid = id_scope.getNewId('alias')
                    component = Component(cid, parameter.vtType,
                                          parameter.real_id, info[2], info[3],
                                          info[4], parameter.type,
                                          parameter.strValue, parameter.pos,
                                          pos, "")
                    alias = Alias(aid, aname, component)
                    self.alias_list.append(alias)
                    pos += 1
Пример #6
0
 def convert(_alias):
     _alias.__class__ = Alias
     Component.convert(_alias.component)
Пример #7
0
 def convert(_alias):
     _alias.__class__ = Alias
     Component.convert(_alias.component)
Пример #8
0
    def updateAliasesFromPipeline(self, pipeline):
        """updateAliasesFromPipeline(self, pipeline) -> long
        This will generate a new mashup by updating the aliases of the current 
        mashup according to the aliases in a pipeline. This assumes that the 
        mashup's current aliases are different from pipeline aliases by at most 
        one change (eg., an alias rename, an alias addition, an alias removal)
        
        """
        pip_aliases = pipeline.aliases.keys()
        mashup_aliases = [a.name for a in self.currentMashup.alias_list]
        new_aliases = []
        if len(pip_aliases) == len(mashup_aliases):
            #an alias probably changed its name or its value
            old_a = None
            new_a = None
            for a in self.currentMashup.alias_list:
                if a.name not in pip_aliases:
                    old_a = a.do_copy(new_ids=True,
                                      id_scope=self.mshptrail.id_scope,
                                      id_remap={})
                    new_aliases.append(old_a)
                else:
                    new_aliases.append(a)
            for a in pip_aliases:
                if a not in mashup_aliases:
                    new_a = (a, pipeline.aliases[a])
            if old_a is not None and new_a is not None:
                (a, info) = new_a
                parameter = pipeline.db_get_object(info[0], info[1])
                old_a.name = a
                old_a.component.vttype = parameter.vtType
                old_a.component.vtid = parameter.real_id
                old_a.component.vtparent_type = info[2]
                old_a.component.vt_parent_id = info[3]
                old_a.component.mid = info[4]
                old_a.component.type = parameter.type
                old_a.component.val = parameter.strValue
                old_a.component.vtpos = parameter.pos

        elif len(pip_aliases) < len(mashup_aliases):
            # an alias was removed
            pos = 0
            for a in self.currentMashup.alias_list:
                if a.name in pip_aliases:
                    alias = a.do_copy(new_ids=True,
                                      id_scope=self.mshptrail.id_scope,
                                      id_remap={})
                    alias.component.pos = pos
                    new_aliases.append(alias)
                    pos += 1
        else:
            #an alias was added
            pos = len(mashup_aliases)
            new_aliases = [a for a in self.currentMashup.alias_list]
            for a in pip_aliases:
                if a not in mashup_aliases:
                    info = pipeline.aliases[a]
                    parameter = pipeline.db_get_object(info[0], info[1])
                    cid = self.id_scope.getNewId('mashup_component')
                    aid = self.id_scope.getNewId('mashup_alias')
                    component = Component(cid, parameter.vtType,
                                          parameter.real_id, info[2], info[3],
                                          info[4], parameter.type,
                                          parameter.strValue, parameter.pos,
                                          pos, "")
                    alias = Alias(aid, a, component)
                    new_aliases.append(alias)
                    pos += 1

        return self.createMashupVersion(new_aliases, quiet=False)