def open_workflow(self, locator, version=None): self.close_first_vistrail_if_necessary() if self.single_document_mode and self.currentView(): self.closeVistrail() vistrail = Vistrail() try: if locator is not None: workflow = locator.load(Pipeline) action_list = [] for module in workflow.module_list: action_list.append(('add', module)) for connection in workflow.connection_list: action_list.append(('add', connection)) action = core.db.action.create_action(action_list) vistrail.add_action(action, 0L) vistrail.update_id_scope() vistrail.addTag("Imported workflow", action.id) # FIXME might need different locator? except ModuleRegistryException, e: msg = ('Cannot find module "%s" in package "%s". ' 'Make sure package is ' 'enabled in the Preferences dialog.' % \ (e._name, e._identifier)) debug.critical(msg)
def generate_vtl(locator,version,pipeline,execute=False,forceDB=False, showSpreadsheetOnly=False,embedWorkflow=False): """generate_vtl(locator:DBLocator or XMLLocator, version: str, pipeline:Pipeline, execute:boolean, forceDB:boolean, showspreadsheetOnly:boolean, embedWorkflow: boolean) -> str It generates the contents of a .vtl file with the information given. """ node = ElementTree.Element('vtlink') if isinstance(locator, DBLocator): node.set('host', str(locator.host)) node.set('port', str(locator.port)) node.set('database', str(locator.db)) node.set('vtid', str(locator.obj_id)) elif locator is not None: node.set('filename', str(locator.name)) node.set('version', str(version)) node.set('execute', str(execute)) node.set('forceDB', str(forceDB)) node.set('showSpreadsheetOnly', str(showSpreadsheetOnly)) if embedWorkflow == True: vistrail = Vistrail() action_list = [] for module in pipeline.module_list: action_list.append(('add', module)) for connection in pipeline.connection_list: action_list.append(('add', connection)) action = core.db.action.create_action(action_list) vistrail.add_action(action, 0L) vistrail.addTag("Imported workflow", action.id) if not forceDB: node.set('version', str(action.id)) if not vistrail.db_version: vistrail.db_version = currentVersion pipxmlstr = io.serialize(vistrail) vtcontent = base64.b64encode(pipxmlstr) node.set('vtcontent',vtcontent) return ElementTree.tostring(node)
def processWorkFlow(self, xmlFile): global _outputFilePath # there should probably be a call in the api for this block of code vistrail = Vistrail() locator = FileLocator(xmlFile) workflow = locator.load(Pipeline) action_list = [] for module in workflow.module_list: if module.name == 'FileSink': _outputFilePath = _tmpDir + '/cp_tmp_' + uuid.uuid4().hex + '.png' for i in xrange(module.getNumFunctions()): if 'outputPath' == module.functions[i].name: module.functions[i].params[0].strValue = _outputFilePath; action_list.append(('add', module)) for connection in workflow.connection_list: action_list.append(('add', connection)) action = core.db.action.create_action(action_list) vistrail.add_action(action, 0L) vistrail.update_id_scope() vistrail.addTag("Imported workflow", action.id) vt = get_api() # there should probably be a call in the api for this next line vt._controller.set_vistrail(vistrail, locator) vt.select_version(action.id) # Assuming that this call is synchronou vt.execute() # Close and exit vt.close_vistrail()
def exportMashup(filename, vtcontroller, mashuptrail, mashupversion, etype): """exportMashup(filename: str, vtcontroller: VistrailController, mashuptrail: Mashuptrail, type: int) -> bool where etype is 0: include full tree 1: include only workflow and mashup identified by version 2: as a link, it will point to a local file. """ result = False if vtcontroller is not None and mashuptrail is not None: locator = vtcontroller.locator version = mashuptrail.vtVersion node = ElementTree.Element("vtlink") if isinstance(locator, DBLocator): node.set("host", str(locator.host)) node.set("port", str(locator.port)) node.set("database", str(locator.db)) node.set("vtid", str(locator.obj_id)) else: node.set("filename", str(locator.name)) node.set("version", str(version)) node.set("execute", "True") node.set("forceDB", "False") node.set("showSpreadsheetOnly", "True") node.set("mashuptrail", str(mashuptrail.id)) node.set("mashupVersion", str(mashupversion)) if etype in [0, 1]: if etype == 1: # minimal pip = vtcontroller.vistrail.getPipeline(version) vistrail = Vistrail() id_remap = {} action = core.db.action.create_paste_action(pip, vistrail.idScope, id_remap) vistrail.add_action(action, 0L, 0) tag = vtcontroller.vistrail.get_tag(version) if tag is None: tag = "Imported workflow" vistrail.addTag(tag, action.id) node.set("version", str(action.id)) id_scope = IdScope(1L) newmashuptrail = Mashuptrail(MashupsManager.getNewMashuptrailId(), action.id, id_scope) maction = mashuptrail.actionMap[mashupversion] mtag = mashuptrail.getTagForActionId(mashupversion) newmashup = copy.copy(maction.mashup) newmashup.remapPipelineObjects(id_remap) currVersion = newmashuptrail.addVersion( newmashuptrail.getLatestVersion(), newmashup, maction.user, maction.date ) newmashuptrail.currentVersion = currVersion newmashuptrail.changeTag(currVersion, mtag, maction.user, maction.date) newvtcontroller = BaseVistrailController() newvtcontroller.set_vistrail(vistrail, None) MashupsManager.addMashuptrailtoVistrailController(newvtcontroller, newmashuptrail) node.set("mashuptrail", str(newmashuptrail.id)) node.set("mashupVersion", str(newmashuptrail.currentVersion)) else: vistrail = vtcontroller.vistrail newvtcontroller = MashupsManager.copyBaseVistrailController(vtcontroller) # create temporary file (fd, name) = tempfile.mkstemp(prefix="vt_tmp", suffix=".vt") os.close(fd) fileLocator = FileLocator(name) newvtcontroller.write_vistrail(fileLocator) contents = open(name).read() vtcontent = base64.b64encode(contents) os.unlink(name) # if not vistrail.db_version: # vistrail.db_version = currentVersion node.set("vtcontent", vtcontent) xmlstring = ElementTree.tostring(node) file_ = open(filename, "w") file_.write(xmlstring) file_.close() result = True return result