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 = vistrails.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(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)
             try:
                 fileLocator = FileLocator(name)
                 newvtcontroller.write_vistrail(fileLocator)
                 contents = open(name).read()
                 vtcontent = base64.b64encode(contents)
             finally:
                 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
예제 #2
0
    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 = vistrails.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(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)
                try:
                    fileLocator = FileLocator(name)
                    newvtcontroller.write_vistrail(fileLocator)
                    contents = open(name).read()
                    vtcontent = base64.b64encode(contents)
                finally:
                    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