def materializeWorkflow(vistrail, version): # construct path up through tree and perform each action if vistrail.db_has_action_with_id(version): workflow = DBWorkflow() # for action in getActionChain(vistrail, version): # oldPerformAction(action, workflow) performActions(getActionChain(vistrail, version), workflow) workflow.db_id = version workflow.db_vistrailId = vistrail.db_id return workflow elif version == 0: return DBWorkflow() else: raise VistrailsDBException("invalid workflow version %s" % version)
def getWorkflowDiff(vistrail, v1, v2, heuristic_match=True): (sharedOps, vOnlyOps) = \ getVersionDifferences(vistrail, [v1, v2]) sharedWorkflow = DBWorkflow() performAdds(sharedOps, sharedWorkflow) # FIXME better to do additional ops (and do deletes) or do this? v1Workflow = DBWorkflow() v1Ops = vOnlyOps[0][2] performAdds(v1Ops, v1Workflow) v2Workflow = DBWorkflow() v2Ops = vOnlyOps[1][2] performAdds(v2Ops, v2Workflow) # FIXME connections do not check their ports sharedModuleIds = [] sharedConnectionIds = [] sharedFunctionIds = {} for op in sharedOps: if op.what == 'module' or op.what == 'abstractionRef': sharedModuleIds.append(getNewObjId(op)) elif op.what == 'connection': sharedConnectionIds.append(getNewObjId(op)) elif op.what == 'function': sharedFunctionIds[getNewObjId(op)] = op.db_parentObjId vOnlyModules = [] vOnlyConnections = [] paramChgModules = {} for (vAdds, vDeletes, _) in vOnlyOps: moduleDeleteIds = [] connectionDeleteIds = [] for op in vDeletes: if op.what == 'module' or op.what == 'abstractionRef': moduleDeleteIds.append(getOldObjId(op)) if getOldObjId(op) in sharedModuleIds: sharedModuleIds.remove(getOldObjId(op)) if paramChgModules.has_key(getOldObjId(op)): del paramChgModules[getOldObjId(op)] elif op.what == 'function' and op.db_parentObjType == 'module' \ and op.db_parentObjId in sharedModuleIds: # have a function change paramChgModules[op.db_parentObjId] = None sharedModuleIds.remove(op.db_parentObjId) elif op.what == 'parameter' and op.db_parentObjType == 'function' \ and sharedFunctionIds.has_key(op.db_parentObjId): # have a parameter change moduleId = sharedFunctionIds[op.db_parentObjId] if moduleId in sharedModuleIds: paramChgModules[moduleId] = None sharedModuleIds.remove(moduleId) elif op.what == 'connection': connectionDeleteIds.append(getOldObjId(op)) if getOldObjId(op) in sharedConnectionIds: sharedConnectionIds.remove(getOldObjId(op)) moduleAddIds = [] connectionAddIds = [] for op in vAdds: if op.what == 'module' or op.what == 'abstractionRef': moduleAddIds.append(getNewObjId(op)) elif (op.what == 'function' and (op.db_parentObjType == 'module' or op.db_parentObjType == 'abstractionRef') and op.db_parentObjId in sharedModuleIds): # have a function change paramChgModules[op.db_parentObjId] = None sharedModuleIds.remove(op.db_parentObjId) elif op.what == 'parameter' and op.db_parentObjType == 'function' \ and sharedFunctionIds.has_key(op.db_parentObjId): # have a parameter change moduleId = sharedFunctionIds[op.db_parentObjId] if moduleId in sharedModuleIds: paramChgModules[moduleId] = None sharedModuleIds.remove(moduleId) elif op.what == 'connection': connectionAddIds.append(getOldObjId(op)) vOnlyModules.append((moduleAddIds, moduleDeleteIds)) vOnlyConnections.append((connectionAddIds, connectionDeleteIds)) sharedModulePairs = [(id, id) for id in sharedModuleIds] v1Only = vOnlyModules[0][0] v2Only = vOnlyModules[1][0] for id in vOnlyModules[1][1]: if id not in vOnlyModules[0][1]: v1Only.append(id) for id in vOnlyModules[0][1]: if id not in vOnlyModules[1][1]: v2Only.append(id) sharedConnectionPairs = [(id, id) for id in sharedConnectionIds] c1Only = vOnlyConnections[0][0] c2Only = vOnlyConnections[1][0] for id in vOnlyConnections[1][1]: if id not in vOnlyConnections[0][1]: c1Only.append(id) for id in vOnlyConnections[0][1]: if id not in vOnlyConnections[1][1]: c2Only.append(id) paramChgModulePairs = [(id, id) for id in paramChgModules.keys()] # add heuristic matches if heuristic_match: # match modules for (m1_id, m2_id) in paramChgModulePairs[:]: m1 = v1Workflow.db_get_module(m1_id) m2 = v2Workflow.db_get_module(m2_id) if heuristicModuleMatch(m1, m2) == 1: paramChgModulePairs.remove((m1_id, m2_id)) sharedModulePairs.append((m1_id, m2_id)) for m1_id in v1Only[:]: m1 = v1Workflow.db_get_module(m1_id) match = None for m2_id in v2Only: m2 = v2Workflow.db_get_module(m2_id) isMatch = heuristicModuleMatch(m1, m2) if isMatch == 1: match = (m1_id, m2_id) break elif isMatch == 0: match = (m1_id, m2_id) if match is not None: if isMatch == 1: v1Only.remove(match[0]) v2Only.remove(match[1]) sharedModulePairs.append(match) else: v1Only.remove(match[0]) v2Only.remove(match[1]) paramChgModulePairs.append(match) # match connections for c1_id in c1Only[:]: c1 = v1Workflow.db_get_connection(c1_id) match = None for c2_id in c2Only: c2 = v2Workflow.db_get_connection(c2_id) isMatch = heuristicConnectionMatch(c1, c2) if isMatch == 1: match = (c1_id, c2_id) break elif isMatch == 0: match = (c1_id, c2_id) if match is not None: # don't have port changes yet c1Only.remove(match[0]) c2Only.remove(match[1]) sharedConnectionPairs.append(match) paramChanges = [] # print sharedModulePairs # print paramChgModulePairs for (m1_id, m2_id) in paramChgModulePairs: m1 = v1Workflow.db_get_module(m1_id) m2 = v2Workflow.db_get_module(m2_id) paramChanges.append(((m1_id, m2_id), getParamChanges(m1, m2, heuristic_match))) return (v1Workflow, v2Workflow, sharedModulePairs, v1Only, v2Only, paramChanges, sharedConnectionPairs, c1Only, c2Only)