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
def translateDeleteAnnotationAction(_action, id_scope): operations = [] for _annotation in _action.db_datas: operation = DBDelete(id=_action.db_time, what='annotation', objectId=_annotation.db_key) operations.append(operation) return createAction(_action, operations, id_scope)
def translateDeleteConnectionAction(_action, id_scope): operations = [] for _connection in _action.db_datas: operation = DBDelete(id=_action.db_time, what='connection', objectId=_connection.db_connectionId) operations.append(operation) return createAction(_action, operations, id_scope)
def translateDeleteModuleAction(_action, id_scope): operations = [] for _module in _action.db_datas: operation = DBDelete(id=_action.db_time, what='module', objectId=_module.db_moduleId) operations.append(operation) return createAction(_action, operations, id_scope)
def translateDeleteFunctionAction(_action, id_scope): operations = [] for _function in _action.db_datas: operation = DBDelete(id=_action.db_time, what='function', objectId=_function.db_functionId, parentObjId=_function.db_moduleId, parentObjType='module') operations.append(operation) return createAction(_action, operations, id_scope)
def translateDeleteModulePortAction(_action, id_scope): operations = [] for _portSpec in _action.db_datas: operation = DBDelete(id=_action.db_time, what='portSpec', objectId=(_portSpec.db_portName, _portSpec.db_portType), parentObjId=_portSpec.db_moduleId, parentObjType='module') operations.append(operation) return createAction(_action, operations, id_scope)
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