示例#1
0
    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)
示例#2
0
def load_vistrail(locator, is_abstraction=False):
    from core.vistrail.vistrail import Vistrail

    abstraction_files = []
    thumbnail_files = []
    mashups = []
    vistrail = None
    if locator is None:
        vistrail = Vistrail()
    else:
        res = locator.load()
        if type(res) == type(SaveBundle(None)):
            vistrail = res.vistrail
            abstraction_files.extend(res.abstractions)
            thumbnail_files.extend(res.thumbnails)
            mashups.extend(res.mashups)
        else:
            vistrail = res
    vistrail.is_abstraction = is_abstraction
    return (vistrail, abstraction_files, thumbnail_files, mashups)
示例#3
0
    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)
示例#4
0
    def __init__(self, parent=None):
        """ QQueryTab(parent: QWidget) -> QQueryTab
        Create an empty vistrail controller for this query tab
        
        """
        QPipelineTab.__init__(self, parent)
        self.pipelineView.setBackgroundBrush(
            CurrentTheme.QUERY_BACKGROUND_BRUSH)

        self.moduleMethods.vWidget.formType = QFunctionQueryForm

        controller = QueryVistrailController(auto_save=False)
        controller.set_vistrail(Vistrail(), None)
        self.setController(controller)
        controller.change_selected_version(0)
        self.connect(controller, QtCore.SIGNAL('vistrailChanged()'),
                     self.vistrailChanged)
示例#5
0
    def build_widget(self):
        layout = QtGui.QVBoxLayout()
        layout.setMargin(0)
        layout.setSpacing(0)

        self.query_controller = QueryController(self)
        self.vt_controller = VistrailController(auto_save=False)
        self.p_controller = VistrailController(Vistrail(), auto_save=False)
        
        self.connect(self.p_controller,
                     QtCore.SIGNAL('vistrailChanged()'),
                     self.vistrailChanged)

        self.query_box = QQueryBox()
        self.query_box.set_controller(self.query_controller)
        layout.addWidget(self.query_box)

        self.stacked_widget = QtGui.QStackedWidget()
        self.pipeline_view = QQueryPipelineView()
        self.p_controller.current_pipeline_view = self.pipeline_view.scene()
        self.pipeline_view.set_controller(self.p_controller)
        self.pipeline_view.set_query_controller(self.query_controller)
        QQueryView.VISUAL_SEARCH_VIEW = \
            self.stacked_widget.addWidget(self.pipeline_view)
        self.global_result_view = QQueryResultGlobalView()
        QQueryView.GLOBAL_RESULT_VIEW = \
            self.stacked_widget.addWidget(self.global_result_view)
        self.version_result_view = QQueryResultVersionView()
        self.connect(self.version_result_view.scene(), 
                     QtCore.SIGNAL('versionSelected(int,bool,bool,bool,bool)'),
                     self.result_version_selected)
        # self.version_result_view.set_controller(self.vt_controller)
        QQueryView.VERSION_RESULT_VIEW = \
            self.stacked_widget.addWidget(self.version_result_view)
        self.workflow_result_view = QQueryResultWorkflowView()
        # self.workflow_result_view.set_controller(self.vt_controller)
        QQueryView.WORKFLOW_RESULT_VIEW = \
            self.stacked_widget.addWidget(self.workflow_result_view)
        self.stacked_widget.setCurrentWidget(self.pipeline_view)
        layout.addWidget(self.stacked_widget)

        self.setLayout(layout)
        self.current_display = QQueryView.VISUAL_SEARCH_VIEW
        self.current_result_view = QQueryView.VERSION_RESULT_VIEW
 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)
示例#7
0
    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()
示例#8
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 = 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
    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
示例#10
0
 def get_vistrail(self):
     if self._vistrail is None:
         self._vistrail = Vistrail()
     return self._vistrail
def read_vistrail(vt_fname):
    import db.services.io
    from core.vistrail.vistrail import Vistrail
    vistrail = db.services.io.open_vistrail_from_xml(vt_fname)
    Vistrail.convert(vistrail)
    return vistrail
示例#12
0
def read_vistrail(vt_fname):
    import db.services.io
    from core.vistrail.vistrail import Vistrail
    vistrail = db.services.io.open_vistrail_from_xml(vt_fname)
    Vistrail.convert(vistrail)
    return vistrail