Exemple #1
0
def createOperation(actionType,
                    objId,
                    objType,
                    parentId,
                    parentType,
                    object=None):
    if actionType == 'add':
        operation = DBAdd(what=objType,
                          objectId=objId,
                          parentObjId=parentId,
                          parentObjType=parentType,
                          data=object)

    elif actionType == 'change':
        operation = DBChange(what=objType,
                             oldObjId=objId,
                             parentObjId=parentId,
                             parentObjType=parentType,
                             data=object)
    elif actionType == 'delete':
        operation = DBDelete(what=objType,
                             objectId=objId,
                             parentObjId=parentId,
                             parentObjType=parentType)
    else:
        msg = "Cannot find actionType='%s'" % actionType
        raise Exception(msg)

    return operation
Exemple #2
0
def translateVistrail(_vistrail):
    # FIXME should this be a deepcopy?
    vistrail = DBVistrail()

    for _action in _vistrail.db_actions.itervalues():
        ops = []
        for op in _action.db_operations:
            if op.vtType == 'add':
                data = convert_data(op.db_data)
                ops.append(
                    DBAdd(id=op.db_id,
                          what=op.db_what,
                          objectId=op.db_objectId,
                          parentObjId=op.db_parentObjId,
                          parentObjType=op.db_parentObjType,
                          data=data))
            elif op.vtType == 'change':
                data = convert_data(op.db_data)
                ops.append(
                    DBChange(id=op.db_id,
                             what=op.db_what,
                             oldObjId=op.db_oldObjId,
                             newObjId=op.db_newObjId,
                             parentObjId=op.db_parentObjId,
                             parentObjType=op.db_parentObjType,
                             data=data))
            elif op.vtType == 'delete':
                ops.append(
                    DBDelete(id=op.db_id,
                             what=op.db_what,
                             objectId=op.db_objectId,
                             parentObjId=op.db_parentObjId,
                             parentObjType=op.db_parentObjType))
        action = DBAction(id=_action.db_id,
                          prevId=_action.db_prevId,
                          date=_action.db_date,
                          user=_action.db_user,
                          operations=ops)
        vistrail.db_add_action(action)

    for _tag in _vistrail.db_tags.itervalues():
        tag = DBTag(id=_tag.db_time, name=_tag.db_name)
        vistrail.db_add_tag(tag)

    vistrail.db_version = '0.6.0'
    return vistrail
Exemple #3
0
def translateAddModulePortAction(_action, id_scope):
    operations = []
    for _portSpec in _action.db_datas:
        # ids need to be checked
        portSpec = DBPortSpec(id=_portSpec.db_moduleId,
                              name=_portSpec.db_portName,
                              type=_portSpec.db_portType,
                              spec=_portSpec.db_portSpec)
        operation = DBAdd(id=_action.db_time,
                          what='portSpec',
                          objectId=(_portSpec.db_portName,
                                    _portSpec.db_portType),
                          parentObjId=_portSpec.db_moduleId,
                          parentObjType='module',
                          data=portSpec)
        operations.append(operation)

    return createAction(_action, operations, id_scope)
Exemple #4
0
def translateAddModuleAction(_action, id_scope):
    operations = []
    for _module in _action.db_datas:
        # note that we're just blindly setting all cache tags to 1 since
        # v0.3.1 didn't really switch this
        module = DBModule(id=_module.db_id,
                          name=_module.db_name,
                          cache=1,
                          location=DBLocation(id=_module.db_id,
                                              x=_module.db_x,
                                              y=_module.db_y))
        module.db_location.relative = False
        operation = DBAdd(id=_action.db_time,
                          what='module',
                          objectId=_module.db_id,
                          data=module)
        operations.append(operation)

    return createAction(_action, operations, id_scope)
Exemple #5
0
def translateAddConnectionAction(_action, id_scope):
    operations = []
    for _connection in _action.db_datas:
        source = DBPort(id=_connection.db_id,
                        type='source',
                        moduleId=_connection.db_sourceId,
                        moduleName=_connection.db_sourceModule,
                        sig=_connection.db_sourcePort)
        destination = DBPort(id=_connection.db_id,
                             type='destination',
                             moduleId=_connection.db_destinationId,
                             moduleName=_connection.db_destinationModule,
                             sig=_connection.db_destinationPort)
        connection = DBConnection(id=_connection.db_id,
                                  ports=[source, destination])
        operation = DBAdd(id=_action.db_time,
                          what='connection',
                          objectId=_connection.db_id,
                          data=connection)
        operations.append(operation)

    return createAction(_action, operations, id_scope)
Exemple #6
0
def convertChangeToAdd(operation):
    return DBAdd(what=operation.db_what,
                 objectId=operation.db_newObjId,
                 parentObjId=operation.db_parentObjId,
                 parentObjType=operation.db_parentObjType,
                 data=operation.db_data)