def make_port_from_module(module, port_type): for function in module.functions: if function.name == 'name': port_name = function.params[0].strValue if function.name == 'spec': port_spec = function.params[0].strValue port = Port(id=-1, name=port_name, type=port_type) portSpecs = port_spec[1:-1].split(',') signature = [] for s in portSpecs: spec = s.split(':', 2) signature.append(registry.get_descriptor_by_name(*spec).module) port.spec = core.modules.module_registry.PortSpec(signature) return port
def add_port_to_registry(self, port_spec): module = \ registry.get_descriptor_by_name(self.package, self.name, self.namespace).module if self.registry is None: self.registry = ModuleRegistry() self.registry.add_hierarchy(registry, self) if port_spec.type == 'input': endpoint = PortEndPoint.Destination else: endpoint = PortEndPoint.Source portSpecs = port_spec.spec[1:-1].split(',') signature = [registry.get_descriptor_from_name_only(spec).module for spec in portSpecs] port = Port() port.name = port_spec.name port.spec = core.modules.module_registry.PortSpec(signature) self.registry.add_port(module, endpoint, port)
def delete_port_from_registry(self, id): if not id in self.port_specs: raise VistrailsInternalError("id missing in port_specs") portSpec = self.port_specs[id] portSpecs = portSpec.spec[1:-1].split(',') signature = [registry.get_descriptor_from_name_only(spec).module for spec in portSpecs] port = Port(signature) port.name = portSpec.name port.spec = core.modules.module_registry.PortSpec(signature) module = \ registry.get_descriptor_by_name(self.package, self.name, self.namespace).module assert isinstance(self.registry, ModuleRegistry) if portSpec.type == 'input': self.registry.delete_input_port(module, port.name) else: self.registry.delete_output_port(module, port.name)
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