Esempio n. 1
0
def create_action_from_ops(ops, simplify=False):
    if len(ops) > 0:
        from core.vistrail.action import Action
        action = db.services.action.create_action_from_ops(ops, simplify)
        Action.convert(action)
        return action
    return None
Esempio n. 2
0
def create_action(op_list):
    if len(op_list) > 0:
        from core.vistrail.action import Action
        action = db.services.action.create_action(op_list)
        Action.convert(action)
        return action
    return None
Esempio n. 3
0
 def convert(_abstraction):
     if _abstraction.__class__ == Abstraction:
         return
     _abstraction.__class__ = Abstraction
     for _action in _abstraction.action_list:
         Action.convert(_action)
     for _tag in _abstraction.tag_list:
         Tag.convert(_tag)
Esempio n. 4
0
 def add_action(self, action, parent):
     Action.convert(action)
     if action.id < 0:
         action.id = self.idScope.getNewId(action.vtType)
     action.prevId = parent
     for op in action.operations:
         if op.id < 0:
             op.id = self.idScope.getNewId('operation')
     self.add_version(action)                
Esempio n. 5
0
    def create_action(self, id_scope=None):
        from core.vistrail.action import Action
        from core.vistrail.module import Module
        from core.vistrail.module_function import ModuleFunction
        from core.vistrail.module_param import ModuleParam
        from core.vistrail.operation import AddOp
        from db.domain import IdScope
        from datetime import datetime

        if id_scope is None:
            id_scope = IdScope()
        param = ModuleParam(id=id_scope.getNewId(ModuleParam.vtType),
                            type='Integer',
                            val='1')
        function = ModuleFunction(id=id_scope.getNewId(ModuleFunction.vtType),
                                  name='value',
                                  parameters=[param])
        m = Module(id=id_scope.getNewId(Module.vtType),
                   name='Float',
                   package='edu.utah.sci.vistrails.basic',
                   functions=[function])

        add_op = AddOp(id=id_scope.getNewId('operation'),
                       what='module',
                       objectId=m.id,
                       data=m)
        action = Action(id=id_scope.getNewId(Action.vtType),
                        prevId=0,
                        date=datetime(2007, 11, 18),
                        operations=[add_op])
        return action
Esempio n. 6
0
def create_action(action_list):
    """create_action(action_list: list) -> Action
    where action_list is a list of tuples
     (
      type, 
      object, 
      parent_type=None,
      parent_id=None,
      new_obj=None
     )
    and the method returns a *single* action that accomplishes all 
    of the operations.

    Examples: create_action([('add', module1), ('delete', connection2)]
              create_action([('add', param1, 'function', function1),
                             ('change', old_func, new_func, 'module', m1)])
    Note that create_action([('add', module)]) adds a module and *all* of its
    children.
    """
    action = db.services.action.create_action(action_list)
    Action.convert(action)
    return action
Esempio n. 7
0
    def positionPipelines(self, sheetPrefix, sheetCount, rowCount, colCount,
                          pipelines):
        """ positionPipelines(sheetPrefix: str, sheetCount: int, rowCount: int,
                              colCount: int, pipelines: list of Pipeline)
                              -> list of Pipelines
        Apply the virtual cell location to a list of pipelines in a
        parameter exploration given that pipelines has multiple chunk
        of sheetCount x rowCount x colCount cells
        
        """
        (vRCount, vCCount, cells) = self.getConfiguration()
        modifiedPipelines = []
        for pId in xrange(len(pipelines)):
            pipeline = copy.copy(pipelines[pId])
            col = pId % colCount
            row = (pId / colCount) % rowCount
            sheet = (pId / (colCount*rowCount)) % sheetCount
            
            decodedCells = self.decodeConfiguration(pipeline, cells)

            for (mId, vRow, vCol) in decodedCells:
                # Walk through all connection and remove all
                # CellLocation connected to this spreadsheet cell
                #  delConn = DeleteConnectionAction()
                action_list = []
                for (cId,c) in self.pipeline.connections.iteritems():
                    if (c.destinationId==mId and 
                        pipeline.modules[c.sourceId].name=="CellLocation"):
                        action_list.append(('delete', c))
                        # delConn.addId(cId)
                # delConn.perform(pipeline)
                action = db.services.action.create_action(action_list)
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)
                
                # Add a sheet reference with a specific name
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                sheetNameParam = ModuleParam(id=param_id,
                                             pos=0,
                                             name="",
                                             val="%s %d" % (sheetPrefix, sheet),
                                             type="String",
                                             alias="",
                                             )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                sheetNameFunction = ModuleFunction(id=function_id,
                                                   pos=0,
                                                   name="SheetName",
                                                   parameters=[sheetNameParam],
                                                   )
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                minRowParam = ModuleParam(id=param_id,
                                          pos=0,
                                          name="",
                                          val=str(rowCount*vRCount),
                                          type="Integer",
                                          alias="",
                                          )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                minRowFunction = ModuleFunction(id=function_id,
                                                pos=1,
                                                name="MinRowCount",
                                                parameters=[minRowParam],
                                                )
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                minColParam = ModuleParam(id=param_id,
                                          pos=0,
                                          name="",
                                          val=str(colCount*vCCount),
                                          type="Integer",
                                          alias="",
                                          )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                minColFunction = ModuleFunction(id=function_id,
                                                pos=2,
                                                name="MinColumnCount",
                                                parameters=[minColParam],
                                                )
                module_id = -pipeline.tmp_id.getNewId(module.Module.vtType)
                sheetReference = module.Module(id=module_id,
                                               name="SheetReference",
                                               package="edu.utah.sci.vistrails.spreadsheet",
                                               functions=[sheetNameFunction,
                                                          minRowFunction,
                                                          minColFunction])
                action = db.services.action.create_action([('add', 
                                                           sheetReference)])
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)

#                 sheetReference.id = pipeline.fresh_module_id()
#                 sheetReference.name = "SheetReference"
#                 addModule = AddModuleAction()
#                 addModule.module = sheetReference
#                 addModule.perform(pipeline)
#
#                 addParam = ChangeParameterAction()
#                 addParam.addParameter(sheetReference.id, 0, 0,
#                                       "SheetName", "",
#                                       '%s %d' % (sheetPrefix, sheet),
#                                       "String", "" )
#                 addParam.addParameter(sheetReference.id, 1, 0,
#                                       "MinRowCount", "",
#                                       str(rowCount*vRCount), "Integer", "" )
#                 addParam.addParameter(sheetReference.id, 2, 0,
#                                       "MinColumnCount", "",
#                                       str(colCount*vCCount), "Integer", "" )
#                 addParam.perform(pipeline)

                # Add a cell location module with a specific row and column
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                rowParam = ModuleParam(id=param_id,
                                       pos=0,
                                       name="",
                                       val=str(row*vRCount+vRow+1),
                                       type="Integer",
                                       alias="",
                                       )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                rowFunction = ModuleFunction(id=function_id,
                                             pos=0,
                                             name="Row",
                                             parameters=[rowParam],
                                             )
                param_id = -pipeline.tmp_id.getNewId(ModuleParam.vtType)
                colParam = ModuleParam(id=param_id,
                                       pos=0,
                                       name="",
                                       val=str(col*vCCount+vCol+1),
                                       type="Integer",
                                       alias="",
                                       )
                function_id = -pipeline.tmp_id.getNewId(ModuleFunction.vtType)
                colFunction = ModuleFunction(id=function_id,
                                             pos=1,
                                             name="Column",
                                             parameters=[colParam],
                                             )
                module_id = -pipeline.tmp_id.getNewId(module.Module.vtType)
                cellLocation = module.Module(id=module_id,
                                             name="CellLocation",
                                             package="edu.utah.sci.vistrails.spreadsheet",
                                             functions=[rowFunction,
                                                        colFunction])
                action = db.services.action.create_action([('add', 
                                                           cellLocation)])
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)
                
#                 cellLocation.id = pipeline.fresh_module_id()
#                 cellLocation.name = "CellLocation"
#                 addModule = AddModuleAction()
#                 addModule.module = cellLocation
#                 addModule.perform(pipeline)
#                
#                 addParam = ChangeParameterAction()                
#                 addParam.addParameter(cellLocation.id, 0, 0,
#                                       "Row", "", str(row*vRCount+vRow+1),
#                                       "Integer", "" )
#                 addParam.addParameter(cellLocation.id, 1, 0,
#                                       "Column", "", str(col*vCCount+vCol+1),
#                                       "Integer", "" )
#                 addParam.perform(pipeline)
                
                # Then connect the SheetReference to the CellLocation
                port_id = -pipeline.tmp_id.getNewId(Port.vtType)
                source = Port(id=port_id,
                              type='source',
                              moduleId=sheetReference.id,
                              moduleName=sheetReference.name)
                source.name = "self"
                source.spec = copy.copy(registry.get_output_port_spec(sheetReference,
                                                                      "self"))
                port_id = -pipeline.tmp_id.getNewId(Port.vtType)
                destination = Port(id=port_id,
                                   type='destination',
                                   moduleId=cellLocation.id,
                                   moduleName=cellLocation.name)
                destination.name = "SheetReference"
                destination.spec = copy.copy(registry.get_input_port_spec(cellLocation,
                                                                          "SheetReference"))
                c_id = -pipeline.tmp_id.getNewId(connection.Connection.vtType)
                conn = connection.Connection(id=c_id,
                                             ports=[source, destination])
                action = db.services.action.create_action([('add', 
                                                           conn)])
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)
                              
#                 conn = connection.Connection()
#                 conn.id = pipeline.fresh_connection_id()
#                 conn.source.moduleId = sheetReference.id
#                 conn.source.moduleName = sheetReference.name
#                 conn.source.name = "self"
#                 conn.source.spec = registry.getOutputPortSpec(
#                     sheetReference, "self")
#                 conn.connectionId = conn.id
#                 conn.destination.moduleId = cellLocation.id
#                 conn.destination.moduleName = cellLocation.name
#                 conn.destination.name = "SheetReference"
#                 conn.destination.spec = registry.getInputPortSpec(
#                     cellLocation, "SheetReference")
#                 addConnection = AddConnectionAction()
#                 addConnection.connection = conn
#                 addConnection.perform(pipeline)
                
                # Then connect the CellLocation to the spreadsheet cell
                port_id = -pipeline.tmp_id.getNewId(Port.vtType)
                source = Port(id=port_id,
                              type='source',
                              moduleId=cellLocation.id,
                              moduleName=cellLocation.name)
                source.name = "self"
                source.spec = registry.get_output_port_spec(cellLocation, "self")
                port_id = -pipeline.tmp_id.getNewId(Port.vtType)
                cell_module = pipeline.get_module_by_id(mId)
                destination = Port(id=port_id,
                                   type='destination',
                                   moduleId=mId,
                                   moduleName=pipeline.modules[mId].name)
                destination.name = "Location"
                destination.spec = registry.get_input_port_spec(cell_module,
                                                                "Location")
                c_id = -pipeline.tmp_id.getNewId(connection.Connection.vtType)
                conn = connection.Connection(id=c_id,
                                             ports=[source, destination])
                action = db.services.action.create_action([('add', 
                                                           conn)])
                # FIXME: this should go to dbservice
                Action.convert(action)
                pipeline.perform_action(action)

#                 conn = connection.Connection()
#                 conn.id = pipeline.fresh_connection_id()
#                 conn.source.moduleId = cellLocation.id
#                 conn.source.moduleName = cellLocation.name
#                 conn.source.name = "self"
#                 conn.source.spec = registry.getOutputPortSpec(
#                     cellLocation, "self")
#                 conn.connectionId = conn.id
#                 conn.destination.moduleId = mId
#                 conn.destination.moduleName = pipeline.modules[mId].name
#                 conn.destination.name = "Location"
#                 conn.destination.spec = registry.getInputPortSpec(
#                     cellLocation, "Location")
#                 addConnection = AddConnectionAction()
#                 addConnection.connection = conn
#                 addConnection.perform(pipeline)

            modifiedPipelines.append(pipeline)

        return modifiedPipelines
Esempio n. 8
0
def create_action_from_ops(op_list):
    from core.vistrail.action import Action
    action = db.services.action.create_action_from_ops(op_list)
    Action.convert(action)
    return action
Esempio n. 9
0
def getPathAsAction(vt, v1, v2, do_copy=False):
    a = db.services.vistrail.getPathAsAction(vt, v1, v2, do_copy)
    Action.convert(a)
    return a
Esempio n. 10
0
def getPathAsAction(vt, v1, v2):
    a = db.services.vistrail.getPathAsAction(vt, v1, v2)
    Action.convert(a)
    return a