Example #1
0
class VistrailsCoreApplication(VistrailsApplicationInterface):
    def __init__(self):
        VistrailsApplicationInterface.__init__(self)
        self._controller = None
        self._vistrail = None

    def init(self, optionsDict=None):
        VistrailsApplicationInterface.init(self, optionsDict)
        self.vistrailsStartup.init()

    def is_running_gui(self):
        return False

    def get_vistrail(self):
        if self._vistrail is None:
            self._vistrail = Vistrail()
        return self._vistrail

    def get_controller(self):
        if self._controller is None:
            v = self.get_vistrail()
            self._controller = VistrailController(v)
            self._controller.set_vistrail(v, None)
            self._controller.change_selected_version(0)
        return self._controller
Example #2
0
 def get_controller(self):
     if self._controller is None:
         v = self.get_vistrail()
         self._controller = VistrailController(v)
         self._controller.set_vistrail(v, None)
         self._controller.change_selected_version(0)
     return self._controller
Example #3
0
class VistrailsCoreApplication(VistrailsApplicationInterface):
    def __init__(self):
        VistrailsApplicationInterface.__init__(self)
        self._controller = None
        self._vistrail = None

    def init(self, optionsDict=None):
        VistrailsApplicationInterface.init(self, optionsDict)
        self.vistrailsStartup.init()

    def is_running_gui(self):
        return False

    def get_vistrail(self):
        if self._vistrail is None:
            self._vistrail = Vistrail()
        return self._vistrail

    def get_controller(self):
        if self._controller is None:
            v = self.get_vistrail()
            self._controller = VistrailController(v)
            self._controller.set_vistrail(v, None)
            self._controller.change_selected_version(0)
        return self._controller
 def copyBaseVistrailController(vt_controller):
     newvt_controller = BaseVistrailController()
     current_log = vt_controller.log
     vistrail = vt_controller.vistrail
     newvt_controller.log = current_log
     newvt_controller.set_vistrail(vistrail, None)
     for m in vt_controller._mashups:
         newvt_controller._mashups.append(copy.copy(m))
     return newvt_controller
Example #5
0
 def copyBaseVistrailController(vt_controller):
     newvt_controller = BaseVistrailController()
     current_log = vt_controller.log
     vistrail = vt_controller.vistrail
     newvt_controller.log = current_log
     newvt_controller.set_vistrail(vistrail, None)
     for m in vt_controller._mashups:
         newvt_controller._mashups.append(copy.copy(m))
     return newvt_controller
Example #6
0
 def get_controller(self):
     if self._controller is None:
         v = self.get_vistrail()
         self._controller = VistrailController(v)
         self._controller.set_vistrail(v, None)
         self._controller.change_selected_version(0)
     return self._controller
Example #7
0
 def addParameterChangesFromAliasesAction(self, pipeline, controller, vistrail, parent_version, aliases):
     param_changes = []
     newid = parent_version
     print "addParameterChangesFromAliasesAction()"
     print "Aliases: %s " % str( aliases )
     print "Pipeline Aliases: %s " % str( pipeline.aliases )
     aliasList = aliases.iteritems()
     for k,value in aliasList:
         alias = pipeline.aliases.get(k,None) # alias = (type, oId, parentType, parentId, mId)
         if alias:
             module = pipeline.modules[alias[4]]
             function = module.function_idx[alias[3]]
             old_param = function.parameter_idx[alias[1]]
             #print alias, module, function, old_param
             if old_param.strValue != value:
                 new_param = VistrailController.update_parameter(controller, 
                                                                 old_param, 
                                                                 value)
                 if new_param is not None:
                     op = ('change', old_param, new_param, 
                           function.vtType, function.real_id)
                     param_changes.append(op)
                     print "Added parameter change for alias=%s, value=%s" % ( k, value  )
                 else:
                     debug.warning("CDAT Package: Change parameter %s in widget %s was not generated"%(k, self.name))
         else:
             debug.warning( "CDAT Package: Alias %s does not exist in pipeline" % (k) )
     if len(param_changes) > 0:
         action = core.db.action.create_action(param_changes)
         vistrail.add_action(action, parent_version, controller.current_session)
         controller.set_changed(True)
         controller.recompute_terse_graph()
         controller.invalidate_version_tree()
         newid = action.id
     return newid
Example #8
0
 def previewChanges(self, aliases):
     print "previewChanges", aliases
     # we will just execute the pipeline with the given alias dictionary
     controller = VistrailController()
     controller.set_vistrail(self.plot_vistrail, self.locator)
     version = self.plot_vistrail.get_version_number(
         self.workflow_tag
     ) if self.workflow_tag else controller.get_latest_version_in_graph()
     controller.change_selected_version(version)
     (results, _) = controller.execute_current_workflow(aliases)
Example #9
0
    def execute(self):
        """ execute() -> None
        Execute the selected pipeline with the edited aliases

        """
        aliases = {}
        for r in xrange(self.aliasTable.rowCount()):
            name = str(self.aliasTable.item(r, 0).text())
            value = str(self.aliasTable.item(r, 1).text())
            aliases[name] = value

        versionNumber = self.versions[self.pipelineList.currentIndex().row()][0]
        pipeline = self.vistrail.getPipelineVersionNumber(versionNumber)
        controller = VistrailController(self.vistrail)
        controller.execute_workflow_list([(self.vistrail.locator,
                                           versionNumber,
                                           pipeline,
                                           DummyView(),
                                           aliases,
                                           None)])
Example #10
0
 def applyChanges(self, aliases):
     #        print "applyChanges"
     self.writePipelineToCurrentVistrail(aliases)
     pipeline = self.current_controller.vistrail.getPipeline(
         self.current_parent_version)
     #print "Controller changed ", self.current_controller.changed
     controller = VistrailController()
     controller.set_vistrail(self.current_controller.vistrail,
                             self.current_controller.locator)
     controller.change_selected_version(self.current_parent_version)
     (results, _) = controller.execute_current_workflow()
Example #11
0
 def previewChanges(self, aliases):
     print "previewChanges", aliases
     # we will just execute the pipeline with the given alias dictionary
     controller = VistrailController()
     controller.set_vistrail(self.plot_vistrail, self.locator)
     version = self.plot_vistrail.get_version_number(self.workflow_tag) if self.workflow_tag else controller.get_latest_version_in_graph()
     controller.change_selected_version(version)
     (results, _) = controller.execute_current_workflow(aliases)
Example #12
0
def load_workflow_as_function(vt_filename, workflow):
    """load_workflow_as_function(vt_filename: str, 
                                 workflow: str or int) -> function 
    vt_filename is the path to a vistrail and workflow can be a workflow 
    version or a workflow tag
    
    """
    from core.vistrail.controller import VistrailController
    from core.db.locator import FileLocator
    from core.db.io import load_vistrail

    def getfunction(controller, doc, **kwargs):
        def makefunction(*args, **kwargs):
            return controller.execute_current_workflow(custom_aliases=kwargs,
                    reason='API load_workflow_as_function call') 
        makefunction.__doc__ = doc
        return makefunction    
    locator = FileLocator(vt_filename) 
    (v, abstractions , thumbnails, mashups)  = load_vistrail(locator)
    controller = VistrailController()
    controller.set_vistrail(v, locator, abstractions, thumbnails, mashups)
    if type(workflow) == type("str"):
        version = v.get_version_number(workflow)
    elif type(workflow) in [ type(1), long]:
        version = workflow
    controller.change_selected_version(version)
    notes = v.get_notes(version)
    pipeline = controller.current_pipeline
    docstring = "parameters of the function: \n  ("
    kw_aliases = {}
    for (a, info) in pipeline.aliases.iteritems():
        parameter = pipeline.db_get_object(info[0],info[1])
        kw_aliases[a] = parameter.strValue
        docstring += "%s=%s,\n   "%(a,parameter.strValue)
    docstring = docstring[:-5] + ")\n"
    if notes != None:
        docstring += str(notes)
    return getfunction(controller, docstring, **kw_aliases)
Example #13
0
    def applyChanges(self, aliases):
#        print "applyChanges"
        self.writePipelineToCurrentVistrail(aliases)
        pipeline = self.current_controller.vistrail.getPipeline(self.current_parent_version)
        #print "Controller changed ", self.current_controller.changed
        controller = VistrailController()
        controller.set_vistrail(self.current_controller.vistrail,
                                self.current_controller.locator)
        controller.change_selected_version(self.current_parent_version)
        (results, _) = controller.execute_current_workflow()
Example #14
0
 def addParameterChangesFromAliasesAction(self, pipeline, controller,
                                          vistrail, parent_version,
                                          aliases):
     param_changes = []
     newid = parent_version
     print "addParameterChangesFromAliasesAction()"
     print "Aliases: %s " % str(aliases)
     print "Pipeline Aliases: %s " % str(pipeline.aliases)
     aliasList = aliases.iteritems()
     for k, value in aliasList:
         alias = pipeline.aliases.get(
             k, None)  # alias = (type, oId, parentType, parentId, mId)
         if alias:
             module = pipeline.modules[alias[4]]
             function = module.function_idx[alias[3]]
             old_param = function.parameter_idx[alias[1]]
             #print alias, module, function, old_param
             if old_param.strValue != value:
                 new_param = VistrailController.update_parameter(
                     controller, old_param, value)
                 if new_param is not None:
                     op = ('change', old_param, new_param, function.vtType,
                           function.real_id)
                     param_changes.append(op)
                     print "Added parameter change for alias=%s, value=%s" % (
                         k, value)
                 else:
                     debug.warning(
                         "CDAT Package: Change parameter %s in widget %s was not generated"
                         % (k, self.name))
         else:
             debug.warning(
                 "CDAT Package: Alias %s does not exist in pipeline" % (k))
     if len(param_changes) > 0:
         action = core.db.action.create_action(param_changes)
         vistrail.add_action(action, parent_version,
                             controller.current_session)
         controller.set_changed(True)
         controller.recompute_terse_graph()
         controller.invalidate_version_tree()
         newid = action.id
     return newid
Example #15
0
def load_workflow_as_function(vt_filename, workflow):
    """load_workflow_as_function(vt_filename: str, 
                                 workflow: str or int) -> function 
    vt_filename is the path to a vistrail and workflow can be a workflow 
    version or a workflow tag
    
    """
    from core.vistrail.controller import VistrailController
    from core.db.locator import FileLocator
    from core.db.io import load_vistrail

    def getfunction(controller, doc, **kwargs):
        def makefunction(*args, **kwargs):
            return controller.execute_current_workflow(
                custom_aliases=kwargs,
                reason='API load_workflow_as_function call')

        makefunction.__doc__ = doc
        return makefunction

    locator = FileLocator(vt_filename)
    (v, abstractions, thumbnails, mashups) = load_vistrail(locator)
    controller = VistrailController()
    controller.set_vistrail(v, locator, abstractions, thumbnails, mashups)
    if type(workflow) == type("str"):
        version = v.get_version_number(workflow)
    elif type(workflow) in [type(1), long]:
        version = workflow
    controller.change_selected_version(version)
    notes = v.get_notes(version)
    pipeline = controller.current_pipeline
    docstring = "parameters of the function: \n  ("
    kw_aliases = {}
    for (a, info) in pipeline.aliases.iteritems():
        parameter = pipeline.db_get_object(info[0], info[1])
        kw_aliases[a] = parameter.strValue
        docstring += "%s=%s,\n   " % (a, parameter.strValue)
    docstring = docstring[:-5] + ")\n"
    if notes != None:
        docstring += str(notes)
    return getfunction(controller, docstring, **kw_aliases)
Example #16
0
 def test_cache(self):
     from core.db.locator import XMLFileLocator
     from core.vistrail.controller import VistrailController
     from core.db.io import load_vistrail
     
     """Test if basic caching is working."""
     locator = XMLFileLocator(core.system.vistrails_root_directory() +
                         '/tests/resources/dummy.xml')
     (v, abstractions, thumbnails, mashups) = load_vistrail(locator)
     
     # the controller will take care of upgrades
     controller = VistrailController()
     controller.set_vistrail(v, locator, abstractions, thumbnails, mashups)
     p1 = v.getPipeline('int chain')
     n = v.get_version_number('int chain')
     controller.change_selected_version(n)
     controller.flush_delayed_actions()
     p1 = controller.current_pipeline
     
     view = DummyView()
     interpreter = core.interpreter.cached.CachedInterpreter.get()
     result = interpreter.execute(p1, 
                                  locator=v,
                                  current_version=n,
                                  view=view,
                                  )
     # to force fresh params
     p2 = v.getPipeline('int chain')
     controller.change_selected_version(n)
     controller.flush_delayed_actions()
     p2 = controller.current_pipeline
     result = interpreter.execute(p2, 
                                  locator=v,
                                  current_version=n,
                                  view=view,
                                  )
     assert len(result.modules_added) == 1
    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 push_vistrail_to_repository(self, branching=False):
        """ uploads current VisTrail to web repository """

        self._repository_status['details'] = "Pushing to repository..."
        self._push_button.setEnabled(False)
        self._branch_button.setEnabled(False)
        self.update_push_information()
        try:
            # create temp file
            self.directory = tempfile.mkdtemp(prefix='vt_tmp')
            (fd, filename) = tempfile.mkstemp(suffix='.vt', prefix='vt_tmp',
                                              dir=self.directory)
            os.close(fd)

            # writing tmp vt and switching back to orginal vt
            locator = ZIPFileLocator(filename)
            controller = api.get_current_controller()
            tmp_controller = VistrailController()
            tmp_controller.set_vistrail(controller.vistrail.do_copy(), locator)
            tmp_controller.changed = True
            tmp_controller.write_vistrail(locator)

            # check if this vt is from the repository
            if controller.vistrail.get_annotation('repository_vt_id'):
                repository_vt_id = controller.vistrail.get_annotation('repository_vt_id').value
            else:
                repository_vt_id = -1

            # upload vistrail temp file to repository
            register_openers(cookiejar=self.dialog.cookiejar)
            project = self.serverCombo.itemData(self.serverCombo.currentIndex()).toList()[0].toString()
            if project == "Default": project = ""

            params = {'vistrail_file': open(filename, 'rb'),
                      'action': 'upload',
                      'name': controller.locator.short_name,
                      'repository_vt_id': repository_vt_id if not branching else -1,
                      'is_runnable': not bool(len(self.unsupported_packages)+ \
                                              len(self.local_data_modules)),
                      'vt_id': 0,
                      'branched_from': "" if not branching else repository_vt_id,
                      'project': project,
                      'everyone_can_view': self.perm_view.checkState(),
                      'everyone_can_edit': self.perm_edit.checkState(),
                      'everyone_can_download': self.perm_download.checkState()
                     }

            upload_url = "%s/vistrails/remote_upload/" % \
                    self.config.webRepositoryURL

            datagen, headers = multipart_encode(params)
            request = urllib2.Request(upload_url, datagen, headers)
            result = urllib2.urlopen(request)
            updated_response = result.read()

            os.unlink(filename)

            if updated_response[:6] == "upload":
                # No update, just upload
                if result.code != 200:
                    self._repository_status['details'] = \
                            "Push to repository failed"
                else:
                    repository_vt_id = int(updated_response[8:])
                    controller.vistrail.set_annotation('repository_vt_id',
                                                       repository_vt_id)
                    controller.vistrail.set_annotation('repository_creator',
                                                       self.dialog.loginUser.text())
                    # ensure that the annotations get saved
                    controller.set_changed(True)
                    self._repository_status['details'] = \
                            "Push to repository was successful"
            else:
                # update, load updated vistrail
                if result.code != 200:
                    self._repository_status['details'] = "Update Failed"
                else:
                    debug.log("getting version from web")
                    # request file to download
                    download_url = "%s/vistrails/download/%s/" % \
                            (self.config.webRepositoryURL, updated_response)

                    request = urllib2.Request(download_url)
                    result = urllib2.urlopen(request)
                    updated_file = result.read()

                    # create temp file of updated vistrail
                    self.directory = tempfile.mkdtemp(prefix='vt_tmp')
                    (fd, updated_filename) = tempfile.mkstemp(suffix='.vtl',
                                                              prefix='vtl_tmp',
                                                              dir=self.directory)
                    os.close(fd)
                    updated_vt = open(updated_filename, 'w')
                    updated_vt.write(updated_file)
                    updated_vt.close()

                    # switch vistrails to updated one
                    controller = api.get_current_controller()

                    updated_locator = FileLocator(updated_filename)

                    (up_vistrail, abstractions, thumbnails, mashups) = \
                            load_vistrail(updated_locator)

                    controller.set_vistrail(up_vistrail,
                                            controller.vistrail.locator,
                                            abstractions, thumbnails, mashups)

                    # update version tree drawing
                    controller.recompute_terse_graph()
                    controller.invalidate_version_tree()

                    os.remove(updated_filename)
                    os.remove(updated_filename[:-1])
                    os.rmdir(self.directory)

                    self._repository_status['details'] = \
                            "Update to repository was successful"

        except Exception, e:
            debug.critical(str(e))
            self._repository_status['details'] = "An error occurred"
Example #19
0
 def loadVistrailFromFile(self, filename):
     locator = FileLocator(filename)
     (v, abstractions , thumbnails)  = load_vistrail(locator)
     controller = VistrailController()
     controller.set_vistrail(v, locator, abstractions, thumbnails)
     return (v, controller)
Example #20
0
    def load(self, loadworkflow=True):
        config = ConfigParser.ConfigParser()
        if config.read(self.config_file):
            if config.has_section('global'):
                if config.has_option('global', 'cellnum'):
                    self.cellnum = config.getint('global', 'cellnum')
                if config.has_option('global', 'filenum'):
                    self.filenum = config.getint('global', 'filenum')
                if config.has_option('global', 'varnum'):
                    self.varnum = config.getint('global', 'varnum')
                    print "   ------ Loaded plot %s, varnum = %d ------ " % ( self.name, self.varnum )
                if config.has_option('global', 'workflow_tag'):
                    self.workflow_tag = config.get('global', 'workflow_tag')
#                else:
#                    debug.warning("CDAT Package: file %s does not contain a required option 'workflow_tag'. Widget will not be loaded."%self.config_file)
#                    self.loaded = False
#                    return
                if config.has_option('global', 'filetypes'):
                    types = config.get('global', 'filetypes')
                    tlist = [t.strip() for t in types.split(";")]
                    for t in tlist:
                        kv = t.split(":")
                        self.filetypes[kv[0].strip()] = [v.strip() 
                                                         for v in kv[1].split(",")]
                if config.has_option('global', 'qt_filter'):
                    self.qt_filter = config.get('global', 'qt_filter')
                if config.has_option('global', 'dependencies'):
                    deps = config.get('global', 'dependencies')
                    self.dependencies = [d.strip() for d in deps.split(",")]
            
                if config.has_option('global', 'serialized_config_alias'):
                    self.serializedConfigAlias = config.get('global', 'serialized_config_alias')

                    for y in range(self.filenum):
                        self.files.append( 'Filename' + str(y+1) )
                            
                    for v in range(self.varnum):
                        self.vars.append( 'VariableName' + str(v+1) )
                        self.axes.append( 'Axes' + str(v+1) )

                    for x in range(self.cellnum):
                        section_name = 'cell' + str(x+1)
                        if config.has_section(section_name):
                            cellType = config.get(section_name, 'celltype')
                            if config.has_option(section_name, 'address_alias'):
                                self.cells.append( Cell( cellType, None, None,
                                                     config.get(section_name, 'address_alias') ) )
                            else:
                                self.cells.append(Cell( cellType,"Row"+str(x+1), "Column"+str(x+1) ) )                                                              
                else:
                    
                    for y in range(self.filenum):
                        option_name = 'filename_alias' + str(y+1)
                        if config.has_option('global', option_name):
                            self.files.append(config.get('global', option_name))
                            
                    for v in range(self.varnum):
                        option_name = 'varname_alias' + str(v+1)
                        if config.has_option('global', option_name):
                            self.vars.append(config.get('global', option_name))
                        axes_name = 'axes_alias' + str(v+1)
                        if config.has_option('global', axes_name):
                            self.axes.append(config.get('global', axes_name))
                        
                    for x in range(self.cellnum):
                        section_name = 'cell' + str(x+1)
                        if (config.has_section(section_name) and
                            config.has_option(section_name, 'celltype') and
                            config.has_option(section_name, 'row_alias') and
                            config.has_option(section_name, 'col_alias')):
                            self.cells.append(Cell(config.get(section_name, 'celltype'),
                                                   config.get(section_name, 'row_alias'),
                                                   config.get(section_name, 'col_alias')))
                
                if loadworkflow:
                    #load workflow in vistrail
                    #only if dependencies are enabled
                    manager = get_package_manager()
                    self.unsatisfied_deps = []
                    for dep in self.dependencies:
                        if not manager.has_package(dep):
                            self.unsatisfied_deps.append(dep)
                    if len(self.unsatisfied_deps) == 0:
                        try:
                            (self.plot_vistrail, abstractions , thumbnails, mashups) = load_vistrail(self.locator)
                            controller = VistrailController()
                            controller.set_vistrail(self.plot_vistrail, self.locator, 
                                                    abstractions, thumbnails,
                                                    mashups) 
    
                            self.workflow_version = self.plot_vistrail.get_version_number(self.workflow_tag) if self.workflow_tag else controller.get_latest_version_in_graph()
                            print " Loaded %s version: %s" % (  self.name, str( self.workflow_version ) )
                            controller.change_selected_version(self.workflow_version)
                            self.workflow = controller.current_pipeline
                            self.loaded = True
                        except Exception, err:
                            debug.warning( "Error loading workflow %s: %s" % ( self.name, err ) )
                            self.loaded = False
                    else:
                        debug.warning("UV-CDAT: %s widget could not be loaded \
    because it depends on packages that are not loaded:"%self.name)
                        debug.warning("  %s"%", ".join(self.unsatisfied_deps))
                        self.loaded = False
            else:
                debug.warning("UV-CDAT: file %s does not contain a 'global'\
 section. Widget will not be loaded."%self.config_file)
                self.loaded = False
Example #21
0
 def loadVistrailFromFile(self, filename):
     locator = FileLocator(filename)
     (v, abstractions, thumbnails) = load_vistrail(locator)
     controller = VistrailController()
     controller.set_vistrail(v, locator, abstractions, thumbnails)
     return (v, controller)
Example #22
0
def run_and_get_results(w_list,
                        parameters='',
                        workflow_info=None,
                        update_vistrail=True,
                        extra_info=None,
                        reason='Console Mode Execution'):
    """run_and_get_results(w_list: list of (locator, version), parameters: str,
                           workflow_info:str, update_vistrail: boolean,
                           extra_info:dict)
    Run all workflows in w_list, and returns an interpreter result object.
    version can be a tag name or a version id.
    
    """
    elements = parameters.split("$&$")
    aliases = {}
    result = []
    for locator, workflow in w_list:
        (v, abstractions, thumbnails, mashups) = load_vistrail(locator)
        controller = VistrailController(auto_save=update_vistrail)
        controller.set_vistrail(v, locator, abstractions, thumbnails, mashups)
        if type(workflow) == type("str"):
            version = v.get_version_number(workflow)
        elif type(workflow) in [type(1), long]:
            version = workflow
        elif workflow is None:
            version = controller.get_latest_version_in_graph()
        else:
            msg = "Invalid version tag or number: %s" % workflow
            raise VistrailsInternalError(msg)
        controller.change_selected_version(version)

        for e in elements:
            pos = e.find("=")
            if pos != -1:
                key = e[:pos].strip()
                value = e[pos + 1:].strip()

                if controller.current_pipeline.has_alias(key):
                    aliases[key] = value

        if workflow_info is not None and controller.current_pipeline is not None:
            if is_running_gui():
                from gui.pipeline_view import QPipelineView
                pipeline_view = QPipelineView()
                pipeline_view.scene().setupScene(controller.current_pipeline)
                base_fname = "%s_%s_pipeline.pdf" % (locator.short_name,
                                                     version)
                filename = os.path.join(workflow_info, base_fname)
                pipeline_view.scene().saveToPDF(filename)
                del pipeline_view
            else:
                debug.critical("Cannot save pipeline figure when not "
                               "running in gui mode")
            base_fname = "%s_%s_pipeline.xml" % (locator.short_name, version)
            filename = os.path.join(workflow_info, base_fname)
            core.db.io.save_workflow(controller.current_pipeline, filename)
        if not update_vistrail:
            conf = get_vistrails_configuration()
            if conf.has('thumbs'):
                conf.thumbs.autoSave = False

        (results, _) = \
            controller.execute_current_workflow(custom_aliases=aliases,
                                                extra_info=extra_info,
                                                reason=reason)
        new_version = controller.current_version
        if new_version != version:
            debug.warning("Version '%s' (%s) was upgraded. The actual "
                          "version executed was %s" % \
                              (workflow, version, new_version))
        run = results[0]
        run.workflow_info = (locator.name, new_version)
        run.pipeline = controller.current_pipeline

        if update_vistrail:
            controller.write_vistrail(locator)
        result.append(run)
    return result
def run_and_get_results(w_list, parameters='', workflow_info=None, 
                        update_vistrail=True, extra_info=None, 
                        reason='Console Mode Execution'):
    """run_and_get_results(w_list: list of (locator, version), parameters: str,
                           workflow_info:str, update_vistrail: boolean,
                           extra_info:dict)
    Run all workflows in w_list, and returns an interpreter result object.
    version can be a tag name or a version id.
    
    """
    elements = parameters.split("$&$")
    aliases = {}
    result = []
    for locator, workflow in w_list:
        (v, abstractions , thumbnails, mashups)  = load_vistrail(locator)
        controller = VistrailController(auto_save=update_vistrail)
        controller.set_vistrail(v, locator, abstractions, thumbnails, mashups)
        if type(workflow) == type("str"):
            version = v.get_version_number(workflow)
        elif type(workflow) in [ type(1), long]:
            version = workflow
        elif workflow is None:
            version = controller.get_latest_version_in_graph()
        else:
            msg = "Invalid version tag or number: %s" % workflow
            raise VistrailsInternalError(msg)
        controller.change_selected_version(version)
        
        for e in elements:
            pos = e.find("=")
            if pos != -1:
                key = e[:pos].strip()
                value = e[pos+1:].strip()
            
                if controller.current_pipeline.has_alias(key):
                    aliases[key] = value
                    
        if workflow_info is not None and controller.current_pipeline is not None:
            if is_running_gui():
                from gui.pipeline_view import QPipelineView
                pipeline_view = QPipelineView()
                pipeline_view.scene().setupScene(controller.current_pipeline)
                base_fname = "%s_%s_pipeline.pdf" % (locator.short_name, version)
                filename = os.path.join(workflow_info, base_fname)
                pipeline_view.scene().saveToPDF(filename)
                del pipeline_view
            else:
                debug.critical("Cannot save pipeline figure when not "
                               "running in gui mode")
            base_fname = "%s_%s_pipeline.xml" % (locator.short_name, version)
            filename = os.path.join(workflow_info, base_fname)
            core.db.io.save_workflow(controller.current_pipeline, filename)
        if not update_vistrail:
            conf = get_vistrails_configuration()
            if conf.has('thumbs'):
                conf.thumbs.autoSave = False
        
        (results, _) = \
            controller.execute_current_workflow(custom_aliases=aliases,
                                                extra_info=extra_info,
                                                reason=reason)
        new_version = controller.current_version
        if new_version != version:
            debug.warning("Version '%s' (%s) was upgraded. The actual "
                          "version executed was %s" % \
                              (workflow, version, new_version))
        run = results[0]
        run.workflow_info = (locator.name, new_version)
        run.pipeline = controller.current_pipeline

        if update_vistrail:
            controller.write_vistrail(locator)
        result.append(run)
    return result
Example #24
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
Example #25
0
    def push_vistrail_to_repository(self, branching=False):
        """ uploads current VisTrail to web repository """

        self._repository_status['details'] = "Pushing to repository..."
        self._push_button.setEnabled(False)
        self._branch_button.setEnabled(False)
        self.update_push_information()
        try:
            # create temp file
            self.directory = tempfile.mkdtemp(prefix='vt_tmp')
            (fd, filename) = tempfile.mkstemp(suffix='.vt',
                                              prefix='vt_tmp',
                                              dir=self.directory)
            os.close(fd)

            # writing tmp vt and switching back to orginal vt
            locator = ZIPFileLocator(filename)
            controller = api.get_current_controller()
            tmp_controller = VistrailController()
            tmp_controller.set_vistrail(controller.vistrail.do_copy(), locator)
            tmp_controller.changed = True
            tmp_controller.write_vistrail(locator)

            # check if this vt is from the repository
            if controller.vistrail.get_annotation('repository_vt_id'):
                repository_vt_id = controller.vistrail.get_annotation(
                    'repository_vt_id').value
            else:
                repository_vt_id = -1

            # upload vistrail temp file to repository
            register_openers(cookiejar=self.dialog.cookiejar)
            project = self.serverCombo.itemData(
                self.serverCombo.currentIndex()).toList()[0].toString()
            if project == "Default": project = ""

            params = {'vistrail_file': open(filename, 'rb'),
                      'action': 'upload',
                      'name': controller.locator.short_name,
                      'repository_vt_id': repository_vt_id if not branching else -1,
                      'is_runnable': not bool(len(self.unsupported_packages)+ \
                                              len(self.local_data_modules)),
                      'vt_id': 0,
                      'branched_from': "" if not branching else repository_vt_id,
                      'project': project,
                      'everyone_can_view': self.perm_view.checkState(),
                      'everyone_can_edit': self.perm_edit.checkState(),
                      'everyone_can_download': self.perm_download.checkState()
                     }

            upload_url = "%s/vistrails/remote_upload/" % \
                    self.config.webRepositoryURL

            datagen, headers = multipart_encode(params)
            request = urllib2.Request(upload_url, datagen, headers)
            result = urllib2.urlopen(request)
            updated_response = result.read()

            os.unlink(filename)

            if updated_response[:6] == "upload":
                # No update, just upload
                if result.code != 200:
                    self._repository_status['details'] = \
                            "Push to repository failed"
                else:
                    repository_vt_id = int(updated_response[8:])
                    controller.vistrail.set_annotation('repository_vt_id',
                                                       repository_vt_id)
                    controller.vistrail.set_annotation(
                        'repository_creator', self.dialog.loginUser.text())
                    # ensure that the annotations get saved
                    controller.set_changed(True)
                    self._repository_status['details'] = \
                            "Push to repository was successful"
            else:
                # update, load updated vistrail
                if result.code != 200:
                    self._repository_status['details'] = "Update Failed"
                else:
                    debug.log("getting version from web")
                    # request file to download
                    download_url = "%s/vistrails/download/%s/" % \
                            (self.config.webRepositoryURL, updated_response)

                    request = urllib2.Request(download_url)
                    result = urllib2.urlopen(request)
                    updated_file = result.read()

                    # create temp file of updated vistrail
                    self.directory = tempfile.mkdtemp(prefix='vt_tmp')
                    (fd,
                     updated_filename) = tempfile.mkstemp(suffix='.vtl',
                                                          prefix='vtl_tmp',
                                                          dir=self.directory)
                    os.close(fd)
                    updated_vt = open(updated_filename, 'w')
                    updated_vt.write(updated_file)
                    updated_vt.close()

                    # switch vistrails to updated one
                    controller = api.get_current_controller()

                    updated_locator = FileLocator(updated_filename)

                    (up_vistrail, abstractions, thumbnails, mashups) = \
                            load_vistrail(updated_locator)

                    controller.set_vistrail(up_vistrail,
                                            controller.vistrail.locator,
                                            abstractions, thumbnails, mashups)

                    # update version tree drawing
                    controller.recompute_terse_graph()
                    controller.invalidate_version_tree()

                    os.remove(updated_filename)
                    os.remove(updated_filename[:-1])
                    os.rmdir(self.directory)

                    self._repository_status['details'] = \
                            "Update to repository was successful"

        except Exception, e:
            debug.critical(str(e))
            self._repository_status['details'] = "An error occurred"